akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007; 
int main() {
  int n,m;
  cin>>n>>m;
  long long cnt_n;
  long long cnt_m;
  long long kotae=2;
  long long sa=abs(n-m);
  if(sa==1)kotae--;
  else if(sa>1){
    cout<<0<<endl;
    return 0;
  }
  for(long long i=n;i>=2;i--){
    kotae*=i;
    kotae%=MOD;
  }
  kotae%=MOD;
  for(long long i=m;i>=2;i--){
    kotae*=i;
    kotae%=MOD;
  }
  kotae%=MOD;
  cout<<kotae<<endl;
}
  

    


Measured memory_bytes: 3536
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if A == B:
    print('YES')
    sys.exit()

if A > B:
    if W - V >= 0:
        print('NO')
    else:
        length = abs(B-A)
        s = abs(W-V)
        if length/s <= T:
            print('YES')
        else:
            print('NO')
else:
    if W - V >= 0:
        print('NO')
    else:
        length = abs(B-A)
        s = abs(W-V)
        if length/s <= T:
            print('YES')
        else:
            print('NO')

Measured memory_bytes: 61696
#include <bits/stdc++.h>

using namespace std;

int main() {
    long long n;
    cin >> n;
    vector <long long> a(n), b(n);
    for (long long i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    long long answer = 0;
    for (long long i = n - 1; i > -1; i--) {
        a[i] += answer;
        long long z = (a[i] + b[i] - 1) / b[i] * b[i];
        answer += z - a[i];
    }
    cout << answer << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int main()
{
	string s;
	cin >> s;

	int n = s.size()-2;
	if (n == 1) {
		if (s[0] == s[2])
			cout << "Second" << endl;
		else
			cout << "First" << endl;
	}
	else if(n % 2 == 0){
		if (s[0] != s[s.size() - 1])
			cout << "Second" << endl;
		else
			cout << "First" << endl;

	}
	else {
		if (s[0] != s[s.size() - 1])
			cout << "First" << endl;
		else
			cout << "Second" << endl;
	}
 	
	return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
S = input()

A = []
c = N
while c > 0:
    d = M
    while d > 0:
        if c - d >= 0 and S[c - d] == "0":
            break
        d -= 1
    else:
        print(-1)
        quit()

    c -= d
    A.append(d)

print(*reversed(A))

Measured memory_bytes: 6384
// ABC164B - Battle

#include <bits/stdc++.h>
using namespace std;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (1) {
		C -= B;
		if (C <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		A -= D;
		if (A <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#define inf 1000000001
using namespace std;

int main()
{
  int N,map[17][17],dp[(1<<17)];
  while(1){
    cin>>N;
    if(N==0)break;
    for(int i=0;i<N;i++){
      for(int j=0;j<N+1;j++){
	cin>>map[i][j];
      }
    }
    memset(dp,inf,sizeof(dp));
    dp[0]=0;
    for(int i=0;i<(1<<N);i++){
      for(int j=0;j<N;j++){
	if(((i>>j)&1)==0){
	  int m=map[j][0];
	  for(int k=0;k<N;k++){
	    if(((i>>k)&1)==1){
	      m=min(m,map[j][k+1]);
	    }
	  }
	  dp[(i|(1<<j))]=min(dp[(i|(1<<j))],dp[i]+m);
	}
      }
    }
    cout<<dp[(1<<N)-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;

int main() {

  int H, N;
  cin >> H >> N;

  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a_;
    cin >> a_;
    sum += a_;
  }

  if (H <= sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
 
ll height[100005], dp[100005], n, k;
 
int main()
{
	Fastest
	
	cin >> n >> k;
	
	for(ll i = 1; i <= n; i++){
		cin >> height[i];
	}
	dp[1]=0;
	dp[2]=abs(height[1]-height[2]);
	ll minimum;
	for(int i=3;i<=n;i++){
		minimum = INT_MAX;
		for(ll j=1;j<=k;j++){
			if(i-j > 0)
				minimum=min(dp[i-j]+abs(height[i]-height[i-j]),minimum);
		}
		dp[i]=minimum;
	}
	cout << dp[n] << endl;		
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  if (s.at(0) == 'o') count++;
  if (s.at(1) == 'o') count++;
  if (s.at(2) == 'o') count++;
  
  cout << 700 + 100 * count << endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
bool d1[5]={0,1,1,0,0};
bool d2[5]={0,1,0,1,0};
bool f[100001];
int n;
string s;
void prin(){
	rep(i,n){
		if(f[i]){
			cout<<'S';
		}
		else{
			cout<<'W';
		}
	}
	return;
}
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>s;
	rep(i,4){
		memset(f,0,sizeof(f));
		f[1]=d1[i];
		f[2]=d2[i];
		for(int j=3;j<=n;j++){
			if((s[j-2]=='o'&&f[j-1])||(s[j-2]=='x'&&!f[j-1])){
				f[j]=f[j-2];
			}
			else{
				f[j]=!f[j-2];
			}
		}
		if((s[0]=='o'&&f[1])||(s[0]=='x'&&!f[1])){
			if(f[2]==f[n]){
				if((s[n-1]=='o'&&f[n])||(s[n-1]=='x'&&!f[n])){
					if(f[1]==f[n-1]){
						prin();
						return 0;
					}
				}
				else{
					if(f[1]!=f[n-1]){
						prin();
						return 0;
					}
				}
			}
		}
		else{
			if(f[2]!=f[n]){
				if((s[n-1]=='o'&&f[n])||(s[n-1]=='x'&&!f[n])){
					if(f[1]==f[n-1]){
						prin();
						return 0;
					}
				}
				else{
					if(f[1]!=f[n-1]){
						prin();
						return 0;
					}
				}
			}
		}
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    long long n;
    cin >> n;
    string s;
    cin >> s;
    
    long long count = 0;
    for(char i = '0'; i <= '9'; i++){
        if(s.find(i) == string::npos){
            continue;
        }
        string s1 = s.substr(s.find(i)+1);
        for(char j = '0'; j <= '9'; j++){
            if(s1.find(j) == string::npos){
                continue;
            }
            string s2 = s1.substr(s1.find(j)+1);
            for(char k = '0'; k <= '9'; k++){
                if(s2.find(k) == string::npos){
                    continue;
                }
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(){
	int n; cin>>n;
	ll a[210000]={0};
	for(int i=0;i<n;i++) cin>>a[i];

	ll x=0,y=0;
	for(int i=0;i<n-1;i++){
		x += a[i];
	}
	y += a[n-1];

	//cout<<x<<" "<<y<<endl;

	if(n==2) cout<< abs(x - y) <<endl;

	else{
		ll mins=abs(x - y), d=0;
		for(int i=n-2;i>=1;i--){
			x -= a[i];
			y += a[i];
			d = abs(x - y);
			mins = min(mins, d);

			//cout<<x<<" "<<y<<endl<<endl;
		}

		cout<< mins <<endl;
	}

	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>

int main()
{
    long long int a;
    scanf("%lld",&a);
    int i = 0;
    char str[100];
    
    while(a > 0)
	{
        int check = a % 26;
        
        if (check == 0)
		{
            str[i++] = 'z';
            a = (a/26) - 1;
        }
		else
		{
            str[i++] = (check - 1) + 'a';
            a /= 26;
        }
    }
    str[i] = '\0';
    
	int j;
    for(j = i - 1; j >= 0; j--)
	{
        printf("%c", str[j]);
    }
    
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int A, B;
    int cost;
    cin >> A >> B;
    if (A >= 13) {
        cost = B;
    } else if (A >= 6) {
        cost = B / 2;
    } else {
        cost = 0;
    }

    cout << cost << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll long long

int main() {
	//入力
	string s,t;
	cin >> s >> t;

	//処理
	int ans = 1001;
	rep(i, s.size()-t.size() + 1) {
		int cnt = 0;
		rep(j, t.size()) {
			if (s[i+j] != t[j]) {
				++cnt;
			}
		}
		ans = min(ans, cnt);
	}

	//出力
	cout << ans << endl;
}

Measured memory_bytes: 3628
# coding: utf-8
import sys
from bisect import bisect_left, bisect_right
import itertools
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# AとBは全探索、その後二分探索
X, Y, Z, K = lr()
A = lr(); A.sort()
B = lr(); B.sort()
C = lr(); C.sort()
D = []
for a, b in itertools.product(A, B):
    D.append(a+b)
D.sort()
if len(D) > K:
    D = D[-K:]

def check(x):
    length = len(D)
    count = 0
    for y in C:
        i = bisect_left(D, x-y)
        count += length - i
    return count >= K

ok = 0; ng = 10 ** 11
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

# ok以上の値
answer = []
for y in C:
    index = bisect_left(D, ok-y)
    for i in range(index, len(D)):
        heappush(answer, -(D[i]+y))

for i in range(K):
    print(-heappop(answer))

# 02

Measured memory_bytes: 133352
n=int(input())
s=list(input())

max=0
count=0

for i in range(1,len(s)):
    str1=set(list(s[0:i]))
    str2=set(list(s[i:n]))
    for c in str1:
        if c in str2:
            count+=1
            if max<=count:
                max=count
    count=0

print(max)


Measured memory_bytes: 3060
// AtCoder Beginner Contest 164 - Problem A: Sheep and Wolves (https://atcoder.jp/contests/abc164/tasks/abc164_a)
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int S, W;
    cin >> S >> W;

    cout << (W >= S ? "unsafe" : "safe") << '\n';

    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  int hr,ans;
  hr=b/a;
  if(hr>=c){
  ans=c;
  }
  else {
    ans=hr;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    cin >> N;

    int a[N];
    int sum = 0;
    for(int i = 0;i < N;i++)
    {
        cin >> a[i];
        sum += a[i] - 1;
    }
    
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> hs(n);
    for(int i=0; i<n; i++) cin >> hs.at(i);
    vector<int> node(n, 0);
    node.at(1) = abs(hs.at(0) - hs.at(1));
    for(int i=2; i<n; i++)
    {
        node.at(i) = min(node.at(i-1) + abs(hs.at(i) - hs.at(i-1)), node.at(i-2) + abs(hs.at(i) - hs.at(i-2)));
    }
    cout << node.back() << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define HashMap std::unordered_map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm ( A x, B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int x, y, X, Y;

    signed call_of_Cthulhu( signed datum ) {

        read x >> y >> X >> Y;
        echo X-(Y-y) _ Y+(X-x) _  x-(Y-y) _ y+(X-x) fin;

        return 0;
    }
}
signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

long long n,a[30],br;
string s[55];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n;
    for(int i=0;i<n;i++)
        cin>>s[i];

    for(int i=0;i<30;i++)
        a[i]=3000;

    for(int q=0;q<26;q++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<s[i].size();j++)
            {
                if(s[i][j]=='a'+q)
                    br++;
            }
            if(br<a[q])
                a[q]=br;
            br=0;
        }
        char b=('a'+q);
        for(int i=0;i<a[q];i++)
            cout<<b;
        br=0;
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
plan = []
for i in range(N):
    p = list(map(int, input().split()))
    plan.append(p)
x = 0
y = 0
t = 0
for p in plan:
    margin = p[0]-t
    if (abs(p[1] - x) + abs(p[2] - y)) > margin:
        print("No")
        exit()
    if (abs(p[1] - x) + abs(p[2] - y)) % 2 != margin % 2:
        print("No")
        exit()
    t = p[0]
    x = p[1]
    y = p[2]

print("Yes")


Measured memory_bytes: 27380
#include<cstdio>
#include<algorithm>
using namespace std;
int a[6];
int main()
{
	for(int i = 1;i <= 3;i++) scanf("%d",&a[i]);
	swap(a[1], a[2]);
	swap(a[1], a[3]);
	for(int i = 1;i <= 3;i++) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 1024

static char s[N][N + 64];
static int n;

static
nextint()
{
  char s[32];
  fgets(s, sizeof(s), stdin);
  return atoi(s);
}

static void
preproc(s)
char *s;
{
  if (s[0] != '.') return ;
  for (; s[1] == '.'; ++s) {
    s[0] = ' ';
  }
  s[0] = '+';
}

main()
{
  int i, j;
  
  for (;;) {
    n = nextint();
    if (n == 0) break ;

    memset(s, 0, sizeof(s));
    for (i = 0; i < n; ++i) {
      fgets(s[i], sizeof(s[i]), stdin);
      preproc(s[i]);
    }
    
    for (i = 0; i < n; ++i) {
      char *p = strchr(s[i], '+');
      if (p == NULL) continue ;
      for (j = i + 1; j < n; ++j) {
        if (s[j][p - s[i]] == ' ') continue ;
        if (s[j][p - s[i]] == '+') {
          for (--j; j != i; --j) {
            s[j][p - s[i]] = '|';
          }
        }
        break ;
      }
    }
    
    for (i = 0; i < n; ++i) {
      fputs(s[i], stdout);
    }
  }

  return 0;
}

Measured memory_bytes: 1600
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e6 + 10;
int arr[MAX_N], bad[MAX_N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
        bad[arr[i]] ++;
    }
    int cnt = 0;
    for(int i = 0; i < n; i ++) {
        bool flag = true;
        if(bad[arr[i]] > 1) {continue;}
        if(arr[i] != 1 && bad[1]) {continue;}
        for(int j = 2; j * j <= arr[i]; j ++) {
            if(arr[i] % j != 0) {continue;}
            if(bad[j] || bad[arr[i] / j]) {
                flag = false;
                break;
            }
        }
        if(flag) {
            cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 8228
#include <bits/stdc++.h>
using namespace std;

long long n, m;
vector<vector<int>> g;
vector<int> dist;

long long solve();

int main() {
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[--a].push_back(--b);
    g[b].push_back(a);
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, bipartite = 0, nonbipartite = 0, cnt = n;
  dist.assign(n, 0);
  for (int i = 0; i < n; ++i)
    if (dist[i] == 0) {
      if (g[i].size() == 0)
        res += 2 * (cnt--) - 1;
      else {
        queue<int> qu;
        qu.push(i);
        dist[i] = 1;
        while (qu.size()) {
          int now = qu.front();
          qu.pop();
          int cos = dist[now] / 2 + ((dist[now] & 1) << 1);
          for (auto to : g[now])
            if (dist[to] != (dist[to] | cos)) {
              dist[to] |= cos;
              qu.push(to);
            }
        }
        if (dist[i] == 3)
          ++nonbipartite;
        else
          ++bipartite;
      }
    }
  res += (nonbipartite + bipartite) * (nonbipartite + bipartite) +
         bipartite * bipartite;
  return res;
}

Measured memory_bytes: 10436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vll;
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp make_pair
const int mod=(ll)1e9+7;
#define all(x) x.begin(),x.end()
#define s(x) ((ll)x.size())
#define tc ll t; cin>>t; while(t--)
#define FOR(i,j,n) for(ll i=j;i<n;i++)
#define ig cin.ignore()
#define fast_cin ios_base::sync_with_stdio(false)
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
ll inv(ll x) {return power(x,mod-2);}
/*---------------------------------------------------------//
const int MAXM = 1e7+3010;   ll fact[MAXM];
void factorial(){ fact[0]=1;FOR(i,1,MAXM) fact[i]=(fact[i-1]*i)%mod;}
ll nCr(ll n,ll r){return ((fact[n])*(((inv(fact[r]))*(inv(fact[n-r])))%mod))%mod;}

// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
//-------------------------------------------------------------------/*/

int main(){
    ll a,b,c,cnt=0;   cin >> a >> b >> c;

    if(a%2) cnt++;
    if(b%2) cnt++;    if(c%2) cnt++;

    if(cnt){
        cout << 0 << "\n";
        return 0;
    }
    ll flag=0;
    while(!cnt){
        ll x= a,y=b,z=c;

        a = y/2 + z/2;
        b = x/2 + z/2 ;
        c = x/2 + y/2 ;

        if(a%2) cnt++;
        if(b%2) cnt++;    if(c%2) cnt++;

        flag++; // cout << flag << "\n";
        if(cnt){
            cout << flag << "\n";
            return 0;
        }
        //cout << a << " " << b << " " << c << "\n";
        if((a==b && b==c) || flag==(ll)1e12 ){
            cout << -1 << "\n";
            break;
        }
    }














}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

vi adj[MX];
int Ans[MX];
bool visited[MX];
queue<int> q;
int dis[MX];

void bfs(int node){

    visited[node] = true;
    dis[node] = 0;
    q.push(node);

    while(!q.empty()){

        int s = q.front(); q.pop();

        for(auto u : adj[s]){

            if(visited[u]) continue;
            visited[u] = true;

            Ans[u] = s;

            dis[u] = dis[s] + 1;
            q.push(u);
        }
    }
}

int main(){

    setIO();

    int n, m;
    cin >> n >> m;

    while(m--){

        int a, b;
        cin >> a >> b;

        adj[a].pb(b), adj[b].pb(a);
    }

    bfs(1);

    for(int i = 1; i <= n; i++){

        if(!visited[i]){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes\n";

    for(int i = 2; i <= n; i++) cout << Ans[i] << "\n";
}


Measured memory_bytes: 13352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    ll N; cin >> N;
    ll A[N],B[N];
    ll sum = 0;
    ll num = 0;
    ll minus_sum = 0;
    vector<ll> S_plus(0);
    for(ll i = 0; i < N; i++) cin >> A[i];
    for(ll i = 0; i < N; i++) cin >> B[i];
    for(ll i = 0; i < N; i++){
        sum += (A[i]-B[i]);
        if(B[i] > A[i]){
            minus_sum += (B[i] - A[i]);
            num++;
        }
        else S_plus.push_back(A[i] - B[i]);
    }

    if(sum < 0)
    {
        cout << -1 << endl;
        return 0;
    }

    sort(S_plus.begin(),S_plus.end());
    reverse(S_plus.begin(),S_plus.end());
    for(ll i = 0; i < S_plus.size(); i++){
        if(minus_sum > 0){
            minus_sum -= S_plus[i];
            num++;
        } else break;
    }
    cout << num << endl;
}


Measured memory_bytes: 2808
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin >> N;
    vector<tuple<string,int,int>> R(N);
    REP(i,N) {
        int a,b;
        string s;
        cin >> s >> a ;
        get<0>(R[i]) = s;
        get<1>(R[i]) = -a;
        get<2>(R[i]) = i + 1;
    }
    sort(ALL(R));
    REP(i,N) cout<<get<2>(R[i])<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> enter(n), s(n);
  for(int i=0; i<n; i++){
    cin >> enter.at(i);
    s.at(i) = enter.at(i);
  }
  
  sort(s.begin(), s.end());
  
  for(int i = 0; i < n; i++){
    int ans;
    if(enter.at(i) != s.at(n-1)) ans = s.at(n-1);
    else ans = s.at(n-2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  string s; cin >> s;
  s += "----";
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(s.substr(i, 3) == "ABC"){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<climits>

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;


const double pi=2*acos(0.0);

int main() {
    fast;
    cin.tie(0);
    lld n;
    cin >> n;
    long double ans=2*pi*n;
    cout<<ans<<endl;
}

Measured memory_bytes: 3796
#include <iostream>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    int n;
    
    for(n = M / N; n >= 1; --n){
        if(M % n == 0){
            cout << n << endl;
            return 0;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 200005;

long long a[N],b[N];
long long c[N],d[N];

bool f[35];

int main()
{
	int n;
	
	scanf("%d",&n);
	
	for (int i = 0;i < n;i++)
	{
		scanf("%lld",&a[i]);
	}
	
	for (int i = 0;i < n;i++)
	{
		scanf("%lld",&b[i]);
	}
	
	for (int i = 0;i <= 30;i++)
	{
		long long t = ((long long)1 << i);
		
		for (int j = 0;j < n;j++)
		{
			c[j] = a[j] % (2 * t);
			d[j] = b[j] % (2 * t);
		}
		
		sort(d,d+n);
		
		for (int j = 0;j < n;j++)
		{
			long long y = 2 * t - c[j];
			long long x = t - c[j];
			
			int p1 = lower_bound(d,d+n,x) - d;
			int p2 = lower_bound(d,d+n,y) - d;
			
			if ((p2 - p1) % 2) f[i] = !f[i];
			
			y = 4 * t - c[j];
			x = 3 * t - c[j];
			
			p1 = lower_bound(d,d+n,x) - d;
			p2 = lower_bound(d,d+n,y) - d;
			
			if ((p2 - p1) % 2) f[i] = !f[i];
		}
	}
	
	int ans = 0;
	
	for (int i = 0;i <= 30;i++)
	{
		if (f[i]) ans |= ((long long)1 << i);
	}
	
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 6400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
int main(){
    mod_build();
    int a,b;
    cin>>a>>b;
    ll ans = a+ 1;
    REP(i,1,a+1){
        ans += comb(b-1,i) * (a-i+1) %mod;
    }
    rep(i,b+1)rep(j,b+1){
        if(i==0)ans += comb(b-1,j)*comb(j-1,i) %mod * comb(a-i-j+1,2) %mod;
        else ans += comb(b-1,j)*comb(j-1,i) %mod * comb(a-i-j+2,2) %mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 2560
/*input
y
1
2 1 x
*/

#include <bits/stdc++.h> 

using namespace std; 

vector<char> v(1e6+10);

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	int p = 3e5+10, q = p;
	for(int i = 0; i < s.length(); i++) {
		v[i+p+1] = s[i];
		q = i+p+1;
	}
	q++;
	int Q;
	cin >> Q;
	bool f = false;
	while(Q--) {
		int t;
		cin >> t;
		if(t == 1) {
			swap(p, q);
			f = !f;
		}
		else {
			int l;
			char ch;
			cin >> l >> ch;
			if(l == 1) {
				v[p] = ch;
				if(f) p++;
				else p--;
			}
			else {
				v[q] = ch;
				if(f) q--;
				else q++;
			}
		}
	}
	if(f) {
		for(int i = p-1; i > q; i--) cout << v[i];
	}
	else {
		for(int i = p+1; i < q; i++) cout << v[i];
	}

	return 0;
}


Measured memory_bytes: 1872
process_num, quantum = STDIN.gets().split(' ').map {|item| item.to_i}
input = STDIN.read().split("\n")
queue = []
input.each do |line|
  queue.push(line.split(" "))
end
time=0

until queue.empty?
  current_job = queue.shift
  rest = current_job[1].to_i - quantum
  if rest > 0
    time += quantum
    queue.push([current_job[0],rest])
  else
    time += quantum + rest
    puts "#{current_job[0]} #{time}"
  end
end

Measured memory_bytes: 21112
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if ( a < b ) { swap(a, b); }
  if ( (a-b)%2 == 0 ) {
    cout << b + (a-b)/2 << endl; 
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 3640
from collections import deque
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False

def main():
    s = input()
    Yes(s[0]=='7'or s[1]=='7'or s[2]=='7')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9244
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	vector<vector<char>> c(120);
	int H, W;
	cin >> H >> W;
	int sumh = 0;
	int sumw = 0;
	int sumhh[200] = {};
	int sumww[200] = {};
	for (int i = 0; i < H; i++) {
		int k = 0;
		for (int j = 0; j < W; j++) {
			char a;
			cin >> a;
			c[i].push_back(a);
			if (a == '.') {
				k++;
			}
		}
		if (k == W) {
			sumh++;
			sumhh[i] = 1;
		}
	}
	for (int i = 0; i < W; i++) {
		int k = 0;
		for (int j = 0; j < H; j++) {
			char a = c[j][i];
			if (a == '.') {
				k++;
			}
		}
		if (k == H ) {
			sumw++;
			sumww[i] = 1;

		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (!(sumhh[i] == 1 || sumww[j] == 1)) {
				cout << c[i][j];
			}
		}
		if (!(sumhh[i] == 1)){
			cout << "\n";
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

main(){
  long N;
  cin >> N;
  long A[N],B[N];
  for(long ii=0;ii<N;ii++){
    cin >> A[ii] >> B[ii];
  }
  pair<long,long>C[N];
  for(long ii=0;ii<N;ii++){
    C[ii].first=A[ii]+B[ii];
    C[ii].second=ii;
  }
  sort(C,C+N);
  long a=0,b=0;
  for(long ii=N-1;ii>=0;ii--){
    if(ii%2==(N-1)%2){//高橋くん
      a+=A[C[ii].second];
    }
    else{//青木さん
      b+=B[C[ii].second];
    }
  }
  cout << a-b << endl;
}


Measured memory_bytes: 3328
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = -A[i]
heapq.heapify(A)
for i in range(M):
    minv = - heapq.heappop(A)
    heapq.heappush(A, (minv//2)*(-1))
print(-sum(A))

Measured memory_bytes: 72300
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	x := readInt()
	y := readInt()
	z := readInt()
	k := readInt()
	a := make([]int64, x)
	b := make([]int64, y)
	c := make([]int64, z)

	for i := range a {
		a[i] = readInt64()
	}
	for i := range b {
		b[i] = readInt64()
	}
	for i := range c {
		c[i] = readInt64()
	}

	d := make([]int64, x*y)
	i := 0
	for _, v := range a {
		for _, w := range b {
			d[i] = v + w
			i++
		}
	}
	sort.Sort(sortTarget0Slice(d))
	if k < len(d) {
		d = d[:k]
	}
	e := make([]int64, len(d)*len(c))
	i = 0
	for _, v := range c {
		for _, w := range d {
			e[i] = v + w
			i++
		}
	}
	sort.Sort(sortTarget0Slice(e))
	for i := 0; i < k; i++ {
		println(e[i])
	}
}

// -----------------------------------------------------------------------------
type sortTarget0Slice []int64

func (s sortTarget0Slice) Len() int {
	return len(s)
}

func (s sortTarget0Slice) Less(i, j int) bool {
	return s[i] > s[j]
}

func (s sortTarget0Slice) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}


Measured memory_bytes: 33024
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

template<int mod>
struct Ring_mod {
    int val;
    Ring_mod(): val(0) {}
    Ring_mod(long long x)
    {
        if (x < 0) x += mod;
        if (x >= mod) x -= mod;
        if (x >= mod) x %= mod;
        val = x;
    }
    explicit operator int() { return val; }
    Ring_mod operator+(const Ring_mod& b) { return Ring_mod(val + b.val); }
    Ring_mod operator-(const Ring_mod& b) { return Ring_mod(val - b.val); }
    void operator+=(const Ring_mod& b) { val = Ring_mod(val + b.val).val; }
    void operator-=(const Ring_mod& b) { val = Ring_mod(val - b.val).val; }
    Ring_mod operator*(const Ring_mod& b) { return Ring_mod((long long) val * b.val); }
};

const int MOD = 1e9 + 7;
typedef Ring_mod<MOD> int_mod;

template<typename T>
struct Matrix {
    Matrix(int r, int c) : _r(r), _c(c), a(r * c) {}
    T* operator[](int row) { return row * _c + a.data(); }
    int _r, _c;
    vector<T> a;
};

int main()
{
    string a;
    int d;
    cin >> a >> d;
    int n = a.size();

    Matrix<int_mod> f(n + 1, d);
    f[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int u = 0; u < d; ++u)
            for (int k = 0; k < 10; ++k) {
                int v = (u + k) % d;
                f[i + 1][v] += f[i][u];
            }

    int p = 0;
    int_mod res = 0;
    for (int i = 0; i < n; ++i) {
        int x = a[i] - '0';
        for (int j = 0; j < x; ++j) {
            int v = (p + j) % d;
            if (v == 0) v = d;
            res += f[n - i - 1][d - v];
        }
        p += x;
    }
    if (p % d == 0)
        res += 1;
    res -= 1;   // don't count zero
    cout << (int) res;
    return 0;
}


Measured memory_bytes: 7232
#include <stdio.h>
#include <stdlib.h>

#define MMAX 1000000

typedef unsigned int u32;
typedef unsigned char u8;

static u32 map[MMAX];

u32 f(u32 n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3*n + 1;
  }
}

u32 max(u32 a, u32 b) {
  return (a < b) ? b : a;
}

int main() {
  u32 s;
  scanf("%u", &s);
  for (u32 i = 1; ;) {
    map[s] = i++;
    s = f(s);
    if (map[s] != 0) {
      printf("%u\n", max(map[s], i));
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	
	// 浮動小数点での出力
	float answer = (N - floor(N / 2)) / (float)N;
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    char s;
    int ss;
    cin >> s;
    string a = "ACGT";
    for(int i = 0;i<4;i++){
        if(s == a[i]){
            ss = i;
            break;
        }
    }
    cout << a[3-ss] << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
public class Simple {
    public static void Main() { new Simple().Solve(); }
    int N;
    long[] T;
    void Solve() {
        //input
        N = int.Parse(Console.ReadLine());
        T = new long[N];
        for (int i = 0; i < N; ++i)
            T[i] = long.Parse(Console.ReadLine());

        long ans = T.Aggregate((v, n) => LCM(v, n));

        //res
        Console.WriteLine(ans);
    }
    void Swap(ref long a,ref long b) {
        long tmp = b;
        b = a;
        a = tmp;
    }
    long GCD(long a,long b) {
        if (a < b)
            Swap(ref a, ref b);
        return b == 0 ? a : GCD(b, a % b);
    }
    long LCM(long a,long b) {
        return a * (b / GCD(a, b));
    }
}

Measured memory_bytes: 13268
def f():
    max_c = 0
    c = 0
    for h in range(n):
        for w in range(n):
            if grid[h][w] == 1:
                    c += 1
            else:
                if  max_c < c:
                    max_c = c
                c = 0
        else:
            if  max_c < c:
                max_c = c
            c = 0
    
    for w in range(n):
        for h in range(n):
            if grid[h][w] == 1:
                c += 1
            else:
                if  max_c < c:
                    max_c = c
                c = 0
        else:
            if  max_c < c:
                max_c = c
            c = 0
    
    for p in range(n):
        for a in range(n-p):
            if grid[p+a][0+a] == 1:
                c += 1
            else:
                if  max_c < c:
                    max_c = c
                c = 0
        else:
            if  max_c < c:
                max_c = c
            c = 0
        
    for p in range(1,n):
        for a in range(n-p):
            if grid[0+a][p+a] == 1:
                c += 1
            else:
                if  max_c < c:
                    max_c = c
                c = 0
        else:
            if  max_c < c:
                max_c = c
            c = 0
                
    for p in range(n):
        for a in range(n-p):
            if grid[p+a][n-1-a] == 1:
                c += 1
            else:
                if  max_c < c:
                    max_c = c
                c = 0
        else:
            if  max_c < c:
                max_c = c
            c = 0
            
    for p in range(n, -1, -1):
        for a in range(p):
            if grid[0+a][p-1-a] == 1:
                c += 1
            else:
                if  max_c < c:
                    max_c = c
                c = 0
        else:
            if  max_c < c:
                max_c = c
            c = 0
                
    print max_c
        
while True:
    n = input()
    if n == 0: break
    grid = [map(int, raw_input()) for i in range(n)]
    f()

Measured memory_bytes: 5104
_n = int(input())
_lengths = list(map(int, input().split(" ")))
_lengths.sort()

_pre = 0
_index = -1
_sticks = []
for _length in _lengths:
  if _pre != _length:
    _sticks.append([_length, 1])
    _index += 1
    _pre = _length
  else:
    _sticks[_index][1] +=1

_counter = 0
if len(_sticks) >= 3:
  for _i in range(len(_sticks)):
    for _j in range(_i+1, len(_sticks)):
      for _k in range(_j+1, len(_sticks)):
        if _sticks[_i][0] + _sticks[_j][0] > _sticks[_k][0]:
          _counter += _sticks[_i][1] * _sticks[_j][1] * _sticks[_k][1] 
print(_counter)

Measured memory_bytes: 9228
//In The Name of Beauty
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e5 + 8;
ll const INF  = 1e12 + 8;
ll const delta = 1000000007;
ll cnt[30];
int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 1;
    for(ll i = 0;i < s.size();i++)cnt[s[i] - 'a']++;
    for(ll i = 0;i < 30;i++)ans = (ans * (cnt[i] + 1)) % delta;
    ans += delta;
    ans--;
    ans %= delta;
    cout << ans;
    return 0;
}
//Written by M_H_H_7


Measured memory_bytes: 512
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def size(self, x):
        return -self.parents[self.find(x)]

def cmb_1(n, r):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

cmb_list = [0] * (10 ** 5 + 1)
for i in range(10 ** 5 + 1):
    cmb_list[i] = cmb_1(i, 2)

N, M = getNM()
query = [getNM() for i in range(M)]

U = UnionFind(N)
now = cmb_list[N]
ans = [now]

for i in range(M - 1, 0, -1):
    a, b = query[i]
    size_a = 0
    size_b = 0
    if not U.same(a - 1, b - 1):
        size_a = U.size(a - 1)
        size_b = U.size(b - 1)

        U.union(a - 1, b - 1)
        size_after = U.size(a - 1)

        now -= (cmb_list[size_after] - cmb_list[size_a] - cmb_list[size_b])
    else:
        U.union(a - 1, b - 1)
    ans.append(now)

for i in range(M - 1, -1, -1):
    print(ans[i])

Measured memory_bytes: 123016
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 100100;
const int mod = 1000000007;

int n;
int a[N], b[N], x[N], y[N], z[N];

void test() {
	scanf("%d", &n);
	FORI(i,n) scanf("%d", &a[i]);
	FORI(i,n) scanf("%d", &b[i]);
	FORI(i,n) {
		x[i] = y[i] = -1;
		z[i] = mod;
	}
	FORI(i,n) {
		if (a[i] > a[i-1]) x[i] = a[i];
		else z[i] = a[i];
	}
	for (int i=n; i>=1; i--) {
		if (b[i] > b[i+1]) y[i] = b[i];
		else z[i] = min(z[i], b[i]);
	}
	FORI(i,n) if (x[i] != -1 && y[i] != -1 && x[i] != y[i]) {
		printf("0\n");
		return;
	}
	int res = 1;
	FORI(i,n) {
		if (x[i] != -1 && z[i] < x[i]) {
			printf("0\n");
			return;
		}
		if (y[i] != -1 && z[i] < y[i]) {
			printf("0\n");
			return;
		}
		if (x[i] == -1 && y[i] == -1) res = 1LL * res * z[i] % mod;
	}
	printf("%d\n", res);
}

int main() {
	test();
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int sum(int n){
    int res=0;
    while(n>0){
        res+=n%10;
        n/=10;
    }
    return res;
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
signed main() {
    int x,y;cin>>x>>y;
    cout<<x+y-gcd(x,y)+1<<endl;
}



Measured memory_bytes: 3112