ACM 第三天

A - Arpa’s hard exam and Mehrdad’s naive cheat

CodeForces - 742A

There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.

Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.

Mehrdad has become quite confused and wants you to help him. Please help, although it‘s a naive cheat.

Input

The single line of input contains one integer n (0  ≤  n  ≤  109).

Output

Print single integer — the last digit of 1378n.

Examples

Input

1

Output

8

Input

2

Output

4

Note

In the first example, last digit of 13781 = 1378 is 8.

In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n==0)
        printf("1\n");
    else if(n%4==1)
    {
        printf("8\n");
    }
    else if(n%4==2)
    {
        printf("4\n");
    }
    else if(n%4==3)
    {
        printf("2\n");
    }
    else
    {
        printf("6\n");
    }
    return 0;
}

E - Vladik and flights

CodeForces - 743A

Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.

Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik‘s house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik‘s house and the place of the olympiad are located near the same airport.

To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.

Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.

Print the minimum cost Vladik has to pay to get to the olympiad.

Input

The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) —
the number of airports, the id of the airport from which Vladik starts
his route and the id of the airport which he has to reach.

The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

Output

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

Examples

Input

4 1 41010

Output

1

Input

5 5 210110

Output

0

Note

In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It‘s impossible to get to the olympiad for free, so the answer is equal to 1.

In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,a,b;
 5     char s[100010];
 6     scanf("%d %d %d",&n,&a,&b);
 7     scanf("%s",s);
 8         if(s[a-1]==s[b-1])
 9             printf("0\n");
10         else
11             printf("1\n");
12     return 0;
13 }

F - Chloe and the sequence

CodeForces - 743B

Chloe, the same as Vladik, is a competitive programmer. She didn‘t have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.

Let‘s consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n - 1) steps. On each step we take the sequence we‘ve got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven‘t used before. For example, we get the sequence [1, 2, 1] after the first step, the sequence [1, 2, 1, 3, 1, 2, 1] after the second step.

The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i. e. after (n - 1) steps.

Please help Chloe to solve the problem!

Input

The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n - 1).

Output

Print single integer — the integer at the k-th position in the obtained sequence.

Examples

Input

3 2

Output

2

Input

4 8

Output

4

Note

In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.

In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.

1 #include<bits/stdc++.h>
2 using namespace std;
3 long long n,k;
4 int main()
5 {
6     scanf("%lld%lld",&n,&k);
7     cout<<log2(k&(-k))+1<<endl;
8 }

G - Vladik and fractions

CodeForces - 743C

Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .

Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can‘t check Vladik‘s answer if the numbers are large, he asks you to print numbers not exceeding 109.

If there is no such answer, print -1.

Input

The single line contains single integer n (1 ≤ n ≤ 104).

Output

If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1.

If there are multiple answers, print any of them.

Examples

Input

3

Output

2 7 42

Input

7

Output

7 8 56
1 #include<stdio.h>
2 int main()
3 {
4     int n;
5     scanf("%d",&n);
6     if(n==1)printf("-1\n");
7     else printf("%d %d %d\n",n,n+1,n*(n+1));
8     return 0;
9 }

原文地址:https://www.cnblogs.com/weixq351/p/9367439.html

时间: 2024-10-20 19:18:05

ACM 第三天的相关文章

ACM第三次比赛UVA11877 The Coco-Cola Store

Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop, you’ll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how many full bottles of coco-cola can you drink? Inp

ACM第三次比赛 Big Chocolate

Problem G Big Chocolate Mohammad has recently visited Switzerland . As he loves his friends very much, he decided to buy some chocolate for them, but as this fine chocolate is very expensive(You know Mohammad is a little BIT stingy!), he could only a

acm专题三1006

Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:<br><br>有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?<br><img src=../data/images/2084-1.jpg><br>已经告诉你了,这是个DP的题目,你能AC吗? Input 输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1

(转)女生应该找一个玩ACM的男生

1.强烈的事业心 将来,他也一定会有自己热爱的事业.而且,男人最性感的时刻之一,就是他专心致志做事的时候.所以,找一个机会在他全神贯注玩ACM的时候,从侧面好好观察他,你就会发现我说的话没错. 2.永不放弃的精神 在比赛刚开始,神牛队就飘崎岖.玩ACM的男生不会退缩,而是毅然决定一个人继续AC下去,靠着自己对胜利的渴望,拿下一个气球.两个气球.三个气 球……N个气球!即使WA了10+次也始终如一的战斗到最后一刻.如果没有不服输的精神,早就放弃了.所以,想要在玩ACM的男性里找一个容易服输的人很

ACM心情总结

已经快要12点了,然而还有5000字概率论论文没有动.在论文里,我本来是想要总结一下ACM竞赛中出现过的概率论题目,然而当敲打第一段前言的时候,我就迟疑了. 我问自己,ACM竞赛到底有什么现实意义. 如果是我们学校的ACM队教练,可能会这么说: 那是因为参加了ACM有就业保障啊,你看我们集训队,大四的时候大家一起吃个饭,一问出路如何,最差也是个阿里巴巴. 如果是游刃有余的高手,可能会这么说: 因为ACM竞赛可以提高敏捷开发的能力,同时作为国际赛事,可以直接在保研这一项加裸分. 但是我无法控制自己

中国计算机学会CCF推荐国际学术会议期刊

中国计算机学会推荐国际学术期刊 (计算机系统与高性能计算) 一.A类 序号 刊物简称 刊物全称 出版社 网址 1 TOCS ACM Transactions on Computer Systems ACM http://tocs.acm.org/ 2 TOC IEEE Transactions on Computers IEEE http://www.computer.org/portal/web/tc 3 TPDS IEEE Transactions on Parallel and Distr

CCF推荐国际学术期刊

中国计算机学会推荐国际学术期刊 (计算机系统与高性能计算) 一.A类 序号 刊物简称 刊物全称 出版社 网址 1 TOCS ACM Transactions on Computer Systems ACM http://tocs.acm.org/ 2 TOC IEEE Transactions on Computers IEEE http://www.computer.org/portal/web/tc 3 TPDS IEEE Transactions on Parallel and Distr

OUC&amp;&amp;我的ACM之路(三)

OUC && 我的ACM之路(三) 时间匆匆,转眼间,省赛我都已经参加过三届了.前面两篇日志:OUC && 我的ACM之路(一)  OUC && 我的ACM之路(二)首先吐槽一下这次省赛题目实在太简单了,也许HIT认为我们就这个水平吧.SD加油,早日冲出final.  rank在这里 其实我也没啥好总结的,只是感概,时间过得匆匆,很多话,前面两篇里面已经说了.最后说一下,实际比赛的时候,ABG三个数学题目,ouc_abc写的,Orz,要当时的状态,我应该是推

acm练习(三)

acm练习(三) //画图 #include<iostream>using namespace std;int main(){ int n; cin>>n; for(int s=0;s<n;s++) { for(int s1=0;s1<n;s1++) { cout<<"*"; } cout<<endl; }} 已通过 //三个数排序 #include<iostream>using namespace std;int