akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
       if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
    int f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline ll readll() {
    ll f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void fl(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
          dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define MAXN 500010
ll n,k,a[MAXN],maxv=0;
bool check(ll x){
    ll res=0;
    for(int i=1;i<=n;i++)res+=(a[i]-1)/x;
    if(res>k)return false;
    else return true;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        maxv=max(maxv,a[i]);
    }
    ll l=1,r=maxv,mid;
    while(l<=r){
        mid=(l+r)>>1;
        if(check(mid)){
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<l<<endl;
    return 0;
}
/* stuff to remember
    * int overflow, array bounds
    * special cases (n=1? n=0?)
    * do something instead of nothing and stay organized
    * USE STATIC ARRAYS
    * DEFINING ARRAYS BEFORE main()
    * DO NOT DEFINE ARRAYS IN main()
    * USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 5112
#include <stdio.h>
int main(void) {
	int N;
	int a[9] = {0}, i, j = 0, t, sum = 0;
	scanf("%d", &N);
	t = N;
	for (i = 0; 1; i++) {
		if (t < 10) {
			a[i] = t;
			break;
		}
		a[i] = t % 10;
		t /= 10;

	}
	for (i = 0; i < 9; i++) {
		sum += a[i];
	}
	if ((N % sum) == 0) {
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int g[100][100];

int solve(vi& vec)
{
    int res = 0;
    rep(i,len(vec)){
        int cri = INF;
        rep(j,len(vec)){
            if(j != i){
                cmn(cri,g[vec[i]][vec[j]]);
            }
        }
        res += cri;
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        g[a-1][b-1] = g[b-1][a-1] = c;
    }
    int ans = 0;
    srep(i,2,min(n+1,15)){
        vi vec;
        rep(j,n){
            int cnt = 0;
            rep(k,n){
                if(g[j][k] > 0){
                    cnt++;
                }
            }
            if(cnt >= i-1){
                vec.pb(j);
            }
        }
        if(len(vec) >= i){
            vector<bool> v(len(vec),false);
            fill(v.end() - i, v.end(), true);
            do{
                vi ch;
                rep(j,len(v)){
                    if(v[j]){
                        ch.pb(vec[j]);
                    }
                }
                cmx(ans,solve(ch));
            }while(next_permutation(all(v)));
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3264
#include<stdio.h>
#define M 1000

int main(void){
  int i;
  int n,m;
  int trout[M],dice[M];
  int cur_p;

  for(;;){
    scanf("%d%d",&n,&m);
    if(n==0 && m==0)
      break;

    cur_p=0;

    for(i=0;i<n;i++)
      scanf("%d",&trout[i]);
    for(i=0;i<m;i++)
      scanf("%d",&dice[i]);

    for(i=0;i<m;i++){
      cur_p+=dice[i];
      if(cur_p>=n-1)
        break;
      cur_p+=trout[cur_p];
      if(cur_p>=n-1)
        break;
    }
    printf("%d\n",i+1);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<PII> v(n);
    REP(i, n) cin >> v[i].first >> v[i].second;
    sort(ALL(v));
    dump(v);

    ll ret = 0;
    vector<ll> cnt(n);
    REP(i, n) {
        ll val = max(0LL, v[i].second-a*cnt[i]);
        ll num = (val+a-1) / a;
        dump(i, val, num);
        ret += num;
        // v[i].first + 2D 以下のやつに+num
        ll idx = upper_bound(ALL(v), PII(v[i].first+2*d, INF)) - v.begin();
        dump(idx);
        if(idx<n) cnt[idx] -= num;
        if(i+1<n) cnt[i+1] += cnt[i] + num;
        dump(cnt[i+1]);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, mod = 1e9+7;

int n, c[N], ans = 1;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int T; scanf("%d",&T);
		c[T]++;
	}
	for(int i=1-n%2;i<n;i+=2) {
		if(c[i] != 2-(i==0)) {puts("0"); return 0;}
		ans = ans * c[i] % mod;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import lru_cache

N = int(readline())

@lru_cache(None)
def F(N):
    if N < 10:
        return N
    q,r = divmod(N,10)
    x = F(q) + r
    y = F(q-1) + 9
    return max(x,y)

answer = F(N)
print(answer)

Measured memory_bytes: 3572
import math
S = int(input())

MOD = int(1e9+7)

def factorial():
    # return a list of [factorial(0) ... factorial(2000)]
    f = [1,]
    for i in range(1, 2000):
        f.append((f[-1]*i) % MOD)
    return f


def modInverse(b,m): 
    g = math.gcd(b, m)  
    if (g != 1): 
        # print("Inverse doesn't exist")  
        return -1
    else:  
        # If b and m are relatively prime,  
        # then modulo inverse is b^(m-2) mode m  
        return pow(b, m - 2, m) 

  
# Function to compute a/b under modulo m  
def modDivide(a,b,m): 
    a = a % m 
    inv = modInverse(b,m) 
    if(inv == -1): 
        return None
    else: 
        return (inv*a) % m


def comb(n, m, f):
    a = modDivide(f[n], f[m], MOD)
    b = modDivide(a, f[n-m], MOD)
    return b

f = factorial()

Max_length = S // 3

if S < 3:
    print(0)

else:
    N = 1 # if length == 1
    for L in range(2, Max_length+1):
        # S - 3 * L objects into  L bins
        # C(S - 3L + L - 1, L-1)
        N = ( N + comb(S-2*L-1, L-1, f) ) % MOD

    print(N)
    

Measured memory_bytes: 9220
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long x = sc.nextLong();
        long[] list = new long[n + 1];

        for (int i = 0; i < n; i++) {
            list[i] = sc.nextLong();
        }
        list[n] = x;
        Arrays.sort(list);
        Set<Long> gaps = new TreeSet<>();

        for (int i = 0; i < n; i++) {
            long gap = list[i + 1] - list[i];
            if (gap == 1) {
                System.out.println(gap);
                return;
            }
            gaps.add(list[i + 1] - list[i]);
        }

        Long[] gapsArray = gaps.toArray(new Long[0]);

        long ans = gapsArray[0];

        parent : for (int i = 0; i < gapsArray.length - 1 ; i++) {
            for (int j = i + 1; j < gapsArray.length; j++) {
                long gcd = gcd(gapsArray[j], gapsArray[i]);
                if (gcd < ans) {
                    ans = gcd;
                }
                if (ans == 1) {
                    break parent;
                }
            }
        }

        System.out.println(ans);

    }

    //最大公約数gcd
    public static long gcd (long a, long b) {
        long temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}

Measured memory_bytes: 49732
#include <stdio.h>
#include <math.h>
#define MAXLENGTH 100
typedef unsigned long long int Ull;

int main(void){
    char s[MAXLENGTH + 1];
    Ull k;
    scanf("%s %lld", s, &k);

    int i;
    for(i = 0; i < k; i++){
        if(s[i] != '1'){
            printf("%c\n", s[i]);
            goto END;
        }
    }

    printf("1\n");
END:
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;



int main()
{
  long x, y;
  // string s;
  // cin  >> x >> y;
  int v[3][3];

  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> v[i][j];
    }
  }


  int a[3];
  int b[3];

  a[0] = 0;

  // 𝑏𝑖 = 𝑐1,𝑖 − 𝑎1
  b[0] = v[0][0] - a[0];
  b[1] = v[0][1] - a[0];
  b[2] = v[0][2] - a[0];

  // a[1] = v[1][0] - v[0][0] + a[0];
  // a[2] = v[2][0] - v[0][0] + a[0];
  // 𝑎𝑖 = 𝑐𝑖,1 − 𝑏1
  a[1] = v[1][0] -b[0];
  a[2] = v[2][0] -b[0];






  bool isSameGroup = true;

  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (v[i][j] != a[i] + b[j]) {
        isSameGroup = false;
      }
    }
  }


  cout << (isSameGroup ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int H,N,A[100000],i,k,wa;
  scanf("%d%d",&H,&N);
  for(i=0;i<N;i++)
  {
    scanf("%d",&A[i]);
  }
  wa=0;
  for(k=0;k<N;k++)
  {
    wa=wa+A[k];
    if(H<=wa)
    {
      printf("Yes");
      exit(0);
    }
  }
  printf("No");
}
     

Measured memory_bytes: 512
# coding: utf-8
import sys
from itertools import permutations,combinations
sys.setrecursionlimit(10 ** 7)

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

# 全探索
INF = 10 ** 5
answer = INF
N = ir()
if N == 1:
    print(0); exit()
A = lr()
B = lr()
for pattern in combinations(range(N), (N+1)//2):
    pattern = set(pattern)
    red = []
    blue = []
    for i in range(N):
        if i in pattern:
            red.append((B[i], i) if i&1 else (A[i], i))
        else:
            blue.append((A[i], i) if i&1 else (B[i], i))
    red.sort()
    blue.sort()
    result = []
    
    for i in range(N//2):
        if red[i][0] > blue[i][0]:
            break
        if i + 1 < len(red) and red[i+1][0] < blue[i][0]:
            break
        result.append(red[i][1])
        result.append(blue[i][1])
    else:
        if N&1 and blue[-1][0] > red[-1][0]:
            continue
        if N&1:
            result.append(red[-1][1])
        temp = 0
        used = set()
        for i in range(N):
            for x in used:
                if result[i] < x:
                    temp += 1
            used.add(result[i])            
        if temp < answer:
            answer = temp

print(answer if answer != INF else -1)
# 12

Measured memory_bytes: 53596
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int N;
void dfs(string s, char mx)
{
    if (s.length() == N)
    {
        printf("%s\n", s.c_str());
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
        }
    }
}
int main()
{
    cin >> N;
    dfs("", 'a');

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int count=0;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
    if(h.at(i)>=k){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> bridge(M);
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        bridge.at(i).first = a;
        bridge.at(i).second = b;
    }
    sort(bridge.begin(), bridge.end());
    
    priority_queue<int, vector<int>, greater<int>> pque;
    
    int res = 0;
    int cnt = 0;
    for(int i = 0; i < N+1; i++){
        while(true){
            if(cnt < M && bridge.at(cnt).first == i){
                pque.push(bridge.at(cnt).second-1);
                cnt++;
            }else{
                break;
            }
        }
        if(pque.empty())continue;
        int limit = pque.top();
        if(i == limit){
            res++;
            while(!pque.empty()){
                pque.pop();
            }
        }
    }
    cout << res << endl;
    
    
}


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

const int NUM = 1000000007;

int main(){
  int N;
  cin>>N;
  long ans=1;
  for(int i=1;i<=N;i++){
    ans=(ans*i)%NUM;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

#define DIV 998244353

int main(){
    int N;
    cin >> N;
    int D[N];

    int m = 0;
    for(int i=0; i<N; i++){
        cin >> D[i];
        if(D[i] == 0 && i != 0){
            cout << 0 << endl;
            return 0;
        }
        m = max(m, D[i]);
    }

    if(D[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    int a[m + 1];
    for(int i=0; i<=m; i++){
        a[i] = 0;
    }

    

    for(int i=1; i<N; i++){
        a[D[i]]++;
    }



    long ans = 1;
    for(int i=1; i < m; i++){
        for(int j = 0; j< a[i+1]; j++){
            ans *= a[i];
            ans %= DIV;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int count = 0;
		while(true){
			count++;
			
			int w = sc.nextInt();
			if(w==0) break;
			int n = sc.nextInt();
			
			int[] a = new int[n];
			int[] b = new int[n];
			for(int i=0;i<n;i++){
				String[] s = sc.next().split(",");
				a[i] = Integer.valueOf(s[0]);
				b[i] = Integer.valueOf(s[1]);
			}
			
			int[][] dp = new int[n+1][w+1];
			int[][] wgt = new int[n+1][w+1];
			
			for(int i=n-1;i>=0;i--){
				for(int j=0;j<=w;j++){
					if(j>=b[i] && dp[i+1][j]<dp[i+1][j-b[i]]+a[i]){
						dp[i][j] = dp[i+1][j-b[i]] + a[i];
						wgt[i][j] = wgt[i+1][j-b[i]] + b[i];
					}else{
						dp[i][j] = dp[i+1][j];
						wgt[i][j] = wgt[i+1][j];
					}
				}
			}
			
			System.out.println("Case " + count + ":");
			System.out.println(dp[0][w]);
			System.out.println(wgt[0][w]);
		}	
	}	
}

Measured memory_bytes: 32868
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	cout << (1900 * M + 100 * (N - M))*(1 << M) << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
cnt = 0
(1..N).step(2) do |n|
  n_dup = Marshal.load(Marshal.dump(n))
  sum = 2
  div = 2
  count = 0
  while n_dup != 1
    if n_dup % div == 0
      count += 1
      n_dup /= div
    else
      sum *= (count + 1)
      count = 0
      div += 1
    end
  end
  cnt += 1 if sum == 8
end
puts cnt

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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  cout << (A - 1) * (B - 1) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	string S;
	cin >> S;
	int a[4]={};
	REP(i,S.length()){
		if(S[i]=='N') a[0]=1;
		if(S[i]=='W') a[1]=2;
		if(S[i]=='S') a[2]=-1;
		if(S[i]=='E') a[3]=-2;
	}
	REP(i,3) a[i+1]+=a[i];
	if(a[3]==0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break    
    else:    
        if m+f<30 or m==-1 or f==-1:
            print("F")
        if m+f>=80 and m!=-1 and f!=-1:
            print("A")
        if 65<=m+f<80 and m!=-1 and f!=-1:
            print("B")
        if 50<=m+f<65 and m!=-1 and f!=-1:
            print("C")
        if 30<=m+f<50 and m!=-1 and f!=-1:
            if r>=50:
                print("C")
            else:
                print("D")
        


Measured memory_bytes: 5592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		System.out.println(getGCD(x, y));
		sc.close();
	}

	public static int getGCD(int a, int b) { // ユークリッドの互除法
		if(a < b) {
			int t = a;
			a = b;
			b = t;
		}
		int c = a % b;
		if(c == 0) {
			return b;
		}else {
			return getGCD(b, c);
		}
	}
}



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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 6e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}


int bit[maxn][30];


void update(int idx, int l, int val)
{
  idx += 2;
  while(idx < maxn)
  {
    bit[idx][l] += val;
    idx += idx & (-idx);
  }
}

vector<int> query(int idx)
{
  idx += 2;
  vector<int>cnt(27, 0);
  while(idx)
  {
    for(int i = 0 ; i < 26; i++)
      cnt[i] += bit[idx][i];
    idx -= idx & (-idx);
  }
  return cnt;
}


int queryRange(int x, int y)
{
  auto cntY = query(y);
  auto cntX = query(x - 1);
  int ans = 0;
  for(int i = 0 ; i < 26; i++)
  {
    // cout << i << " --> " << cntY[i] << " " << cntX[i] << endl;
    cntY[i] -= cntX[i];
    if(cntY[i] > 0)
      ans++;
  }
  return ans;
}

int main()
{
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for(int i = 0; i < n; i++)
  {
    update(i + 1, s[i] - 'a', 1);
  }
  int q;
  cin >> q;
  while(q--)
  {
    int op;
    cin >> op;
    if(op == 1)
    {
      int i;
      char c;
      cin >> i >> c;
      update(i, s[i-1] - 'a', -1);
      update(i, c - 'a', 1);
      s[i-1] = c;
    }
    else
    {
      int l,r;
      cin >> l >> r;
      cout << (queryRange(l, r)) << endl;
    }
  }

  return 0;
}

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

int main() 
{ 
 int buy,oturi,kozeni,a,b,c,d,e,f; 
 while(1){
  cin>>buy;
  if(buy==0)
   break;
  else{
   oturi=1000-buy;
   a=oturi/500;
   if(a)b=(oturi-500)/100;
     else b=oturi/100;
   c=oturi%100/50;
   if(c)d=(oturi%100-50)/10;
     else d=oturi%100/10;
   e=oturi%10/5;
   if(e)f=oturi%10-5;
      else f=oturi%10;   

   kozeni=a+b+c+d+e+f;
   cout<<kozeni<<"\n";
  }
 }
 return 0; 
} 

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#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++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m; cin >> n >> m;
    vector<int> ac(n);
    vector<int> wcnt(n);
    int p; string s;
    rep(i,m){
        cin >> p >> s;
        if (s == "AC") ac[p-1] = 1;
        if (s == "WA"){
            if (ac[p-1] == 1) continue;
            else wcnt[p-1]++;
        }
    }
    int cntac = 0, cntwa = 0;
    rep(i,n){
        if (ac[i] == 1) cntac++;
    }
    rep(i,n){
        if (ac[i] == 0) continue;
        else cntwa += wcnt[i];
    }
    cout << cntac << " " << cntwa << endl;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    import sys
    dp = [0.0] * 100001
    dp[1] = 1.0
    for i in xrange(2, 100001):
        p = 1.0
        w = 0.5
        for j in xrange(1,i):
            if p < 1e-13:
                break
            dp[i] += (p*(1-w))*(j+dp[max(0,i-j-1)])
            p *= w
            w *= 0.5
        dp[i] += i*p
    while True:
        N = int(raw_input())
        if N == 0:
            sys.exit()
        print "%.8f" % dp[N]

Measured memory_bytes: 9276
a = [[int(i) for i in input().split()] for _ in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

ans = "No"
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      a[i][j] = "x"
      
if (a[0][0]==a[1][1]==a[2][2]=="x") or (a[2][0]==a[1][1]==a[0][2]=="x"):
  print("Yes")
  exit()
  
if (a[0][0]==a[1][0]==a[2][0]=="x")or(a[0][1]==a[1][1]==a[2][1]=="x")or(a[0][2]==a[1][2]==a[2][2]=="x"):
  print("Yes")
  exit()
  
if (a[0][0]==a[0][1]==a[0][2]=="x")or(a[1][0]==a[1][1]==a[1][2]=="x")or(a[2][0]==a[2][1]==a[2][2]=="x"):
  print("Yes")
  exit()
  
  
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
#define int long long
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int Inv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	void math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=Inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int n,m,a[100100];

signed main()
{
	n=read();m=read();
	int sum=0;
	rep(i,1,n) {a[i]=read();sum+=a[i];}
	int cnt=0;
	rep(i,1,n)
	{
		if (a[i]*4*m>=sum) cnt++;
	}
	//cout << cnt << endl;
	if (cnt>=m) puts("Yes");
	else puts("No");
	return 0;
}
	



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define readvec(vec) for(auto& e: vec){cin >> e;}
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int >    vecint;
typedef vector<ll >      vecll;
typedef vector<double >   vecd;
typedef vector<string > vecstr;
typedef vector<char >  vecchar;
typedef vector<bool >  vecbool;
typedef vector<vector<bool> >  vec2bool;
typedef vector<vector<int> >    vec2int;
typedef vector<vector<double> >   vec2d;
////////////////////////////////////////////////
void init(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
template<typename T>
T gcd(T a, T b){
  if(b == 0){
    return a;
  }
  if(a < b)return gcd(b, a);
  return gcd(b, a%b);
}
template<typename T>
T lcm(T a, T b){
  return (a/gcd(a,b))*b;
}
////////////////////////////////////////////////
int main()
{
  ll N, M; cin >> N >> M;
  string s, t; cin >> s >> t;
  ll g = gcd(N, M);
  ll l = lcm(N, M);
  ll n, m;
  n = N/g;  m = M/g;
  bool ok = true;
  REP(i,g){
    if(s[i*n] != t[i*m]){
      ok = false;
    }
  }
  cout << (ok?l:-1) << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  string s;
  bool even,odd;
  even=true;
  odd=true;
  cin >> s;
  
  for(ii=0;ii<s.size();ii++){
    if(ii % 2 == 1){
      if(s[ii] == 'R'){
        even = false;
      }

    }
    else{
      if(s[ii] == 'L'){
        odd = false;
      }
    }
  }
  if(even && odd){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
 int a,b,c,d;
 cin>>a>>b>>c;
 if(a>b && a>c){
 d=a;
 }
 else if(b>a && b>c){
 d=b;
 }
 else if(c>a && c>b){
 d=c;
 }
 else if(a==b && b==c){
 d=a;
 }
 cout<<a+b+c-d;
}

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct BIT{
    ll N;
    vector<ll> bit;
    BIT(ll N) : bit(N+1),N(N){};

    ll sum(ll i){
        ll s = 0;
        while(i>0){
           s += bit[i];
           i -= i& -i;
        }
        return s;
    }

    void add(ll i,ll x){
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

//反転数を求める
ll inverse_number(vector<ll> z){
    ll n = z.size();
    ll inv_num = 0;

    BIT b(n);
    for(ll i = 0; i <= n; i++){
        b.bit[i] = 0;
    }

    for(ll i = 0; i < n; i++){
        inv_num += i - b.sum(z[i]);
        b.add(z[i],1);
    }

    return inv_num;
}

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

	ll n = s.length();
	vector<vector<ll> > al_pos(26);  //initial position

	for(ll i = 0; i < n; i++){
		al_pos[s[i]-'a'].push_back(i);
	}

	ll odd_al = -1;
	for(ll i = 0; i < 26; i++){
		if(al_pos[i].size() % 2 != 0){
			if(odd_al >= 0){
				cout << -1 << endl;
				return 0;
			}else{
				odd_al = i;
			}
		}
	}

	if((odd_al>=0 && n%2==0) || (odd_al<0 && n%2!=0)){
		cout << -1 << endl;
		return 0;
	}

	ll al_now[26] = {0};

	string front,back,center;
	for(ll i = 0; i < n; i++){
		if(n%2!=0 && al_now[s[i]-'a'] == al_pos[odd_al].size()/2 && s[i]-'a' == odd_al){
			center.push_back(s[i]);
			al_now[s[i]-'a']++;
			continue;
		}
		if(al_now[s[i]-'a']+1<= al_pos[s[i]-'a'].size() / 2){
			front.push_back(s[i]);
			al_now[s[i]-'a']++;
		}else{
			back.push_back(s[i]);
			al_now[s[i]-'a']++;
		}
	}

	for(ll i = 0; i < 26; i++) al_now[i]=0;

	vector<ll> kaibun_index;
	for(ll i = 0; i < front.length(); i++){
		kaibun_index.push_back(al_pos[front[i]-'a'][al_now[front[i]-'a']]);
		al_now[front[i]-'a']++;
	}
	for(ll i = 0; i < center.length(); i++){
		kaibun_index.push_back(al_pos[center[i]-'a'][al_now[center[i]-'a']]);
		al_now[center[i]-'a']++;
	}
	for(ll i = front.length()-1; i >= 0; i--){
		kaibun_index.push_back(al_pos[front[i]-'a'][al_now[front[i]-'a']]);
		al_now[front[i]-'a']++;
	}

	for(ll i = 0; i < n; i++) kaibun_index[i]++;

	cout << inverse_number(kaibun_index) << endl;

	return 0;
}

Measured memory_bytes: 8052
#%%
from itertools import permutations
N = int(input())

towns = []
for i in range(N):
    towns.append(list(map(int, input().split())))

perm = list(permutations(towns))

def calc_l2(p_next, p):
    return ((p_next[0] - p[0])**2 + (p_next[1] - p[1])**2) ** 0.5

l2_norm = 0
for p in perm:
    for i in range(len(p) - 1):
        l2_norm += calc_l2(p[i+1], p[i])

print(l2_norm/len(perm))









Measured memory_bytes: 45296
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
  ll N; cin >> N;
  vector<P> a(N); rep(i,N) cin >> a[i].fi >> a[i].sc;
  SORT(a);

  // 最小公倍数でわる
  rep(i,N){
    if(a[i].fi == 0 and a[i].sc == 0) continue;
    ll tmp = gcd(abs(a[i].fi), abs(a[i].sc));
    a[i].fi /= tmp;
    a[i].sc /= tmp;
  }

  // map;
  ll zero = 0;
  map<P,ll> map;
  rep(i,N){
    if(a[i].fi == 0 and a[i].sc == 0){
      zero++;
      continue;
    }
    else if(a[i].fi == 0 and a[i].sc != 0){
      a[i].sc = -1;
    }
    else if(a[i].fi != 0 and a[i].sc == 0){
      a[i].fi = 1;
    }
    else if(a[i].fi < 0 and a[i].sc < 0){
      a[i].fi = abs(a[i].fi); a[i].sc = abs(a[i].sc);
    }
    else if(a[i].fi < 0 and a[i].sc > 0){
      a[i].fi = -a[i].fi; a[i].sc = -a[i].sc;
      // ll tmp = a[i].fi; a[i].fi = a[i].sc; a[i].sc = tmp;
    }
    map[mp(a[i].fi , a[i].sc)]++;
  }

  /*
  for(auto p : map){
    cout << p.fi.fi << " " << p.fi.sc << " " << p.sc << endl;
  }
  */

  // 相方の個数を数える
  ll ans = 1;
  for(auto p : map){
    auto a = -p.fi.sc; auto b = p.fi.fi; auto c = p.fi.sc; auto d = -p.fi.fi;
    if(map[mp(a,b)] > 0 or map[mp(c,d)] > 0){
      ll cnt = modpow( 2 , p.sc , MOD ) - 1
      + modpow(2, map[mp(a,b)] + map[mp(c,d)], MOD) - 1;
      cnt++;
      cnt %= MOD;
      ans *= cnt;
      ans %= MOD;
      map.erase(mp(a,b)); map.erase(mp(c,d));
    }
    else{
      ans *= modpow(2, p.sc , MOD);
      ans %= MOD;
      map.erase(mp(a,b)); map.erase(mp(c,d));
    }
  }
  ans = ans + MOD - 1;
  ans %= MOD;
  ans += zero;
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 18820
#include <iostream>
#include<string>
using namespace std;
int  main() {
	string A, B, C;

	cin >> A >> B >> C;
	if(A.back()==B.front()&&B.back()==C.front())
	{
		cout << "YES" << endl;
	}else 
	{
		cout << "NO" << endl;
	}
	
	return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define pb push_back
#define FR first
#define SC second
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vl >
#define vb vector<bool>
#define vbb vector< vb >
#define vpl vector<pll>
#define vpll vector< vpl >

void solve()
{
	ll x, k, d;
	cin>>x>>k>>d;
	if(x == 0)
	{
	    if(k % 2)
	        cout<<d;
	    else
	        cout<<0;
	}
	else
	{
	    x = abs(x);
	    ll step = x / d;
	    ll mn = x % d;
	    if(step < k)
	    {
	        ll left = step - k;
	        if(left % 2)
	            cout<<abs(mn - d);
	        else
	            cout<<mn;
	    }
	    else
	    {
	        cout<<abs(x - k * d);
	    }
	    
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	K := nextInt()
	S := nextInt()
	for i := 0; i < N; i++ {
		if i < K {
			pf(S, i, N)
		} else if S != 1e9 {
			pf(S+1, i, N)
		} else {
			pf(1, i, N)
		}
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func pf(s int, i int, N int) {
	if i != N {
		fmt.Printf("%d ", s)
	} else {
		fmt.Printf("%d\n", s)
	}
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
long long x,b,check=0;
void find( long long p)
{
    long long k;
    long long l=0,r=3981,mid;
    while (l<=r)
    {
        mid=(l+r)/2;
        k=mid*mid*mid*mid*mid;
        //if (p==1) cout<<l<<" "<<r<<" "<<k<<endl;
        if (k==p) { b=mid; check=1; break;}
        if (k>p) { r=mid-1;}
        else
        {
            l=mid+1;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>x;
    long long i=0;
    while (i<=3981)
    {
        long long a=i*i*i*i*i;
        find(abs(a-x));
        long long t;
        if (a-x<0) t=-1;
        else
        {
            t=1;
        }
        
        if (check==1)
        {
            cout<<i<<" "<<t*b;
            break;
        }
        i++;
    }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int n;
int a[200100],b[200100];
int l[200100],r[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++){
		if(a[i]>b[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=2;i<=n;i++)
		l[i]=i-1;
	l[1]=n;
	for(int j=1;j<n;j++)
		r[j]=j+1;
	r[n]=1;
	long long res=0LL;
	int cnt=0;
	while(1){
		bool ok=true,chg=false;
		for(int i=1;i<=n;i++){
			if(b[i]==a[i])
				continue;
			if(b[i]<a[i]){
				cout<<-1<<endl;
				return 0;
			}
			ok=false;
			long long he=(long long)(b[l[i]]+b[r[i]]);
			if(b[i]-he<a[i])
				continue;
			res+=(long long)((b[i]-a[i])/he);
			b[i]-=((b[i]-a[i])/he)*he;
			chg=true;
		}
		if(ok)
			break;
		if(!chg){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<res<<endl;
	return 0;
}


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int a,b;

int main(){
  scanf("%d %d",&a,&b);
  if(a%3==0 || b%3==0 || (a+b)%3==0){
    printf("Possible\n");
  }else{
    printf("Impossible\n");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[200001];
int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	LL now=0;
	LL pos=0;
	LL ans=0;
	REP(i,N){
		while(((A[i])&(now))!=0){
			now-=A[pos];
			pos++;
		}
		now+=A[i];
		ans+=(i-pos+1);
	}
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int n1 = abs(a - b);
	int n2 = abs(a - c);
	int n3 = abs(b - c);

	int mx = max(n1, max(n2, n3));
	cout << n1 + n2 + n3 - mx << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from fractions import gcd
from functools import reduce

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def gcd_list(numbers):
    return reduce(gcd, numbers)
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    MOD = 10**9+7

    GCD = gcd_list(A)
    LCM = lcm_list(A) % MOD
    ans = 0
    if GCD != 1 and LCM == A[-1]:
        for i in range(N):
            ans = (ans + A[-1] * mod_inv(A[i],MOD)) % MOD
    else:
        for i in range(N):
            ans = (ans + LCM * mod_inv(A[i],MOD)) % MOD

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 69996
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
x=list(map(int,input().split()))
tmp=sorted(x)

if n%2==0:
    heikin=(tmp[n//2]+tmp[n//2-1])/2
    for i in range(n):
        if heikin<x[i]:
            print(tmp[n//2-1])
        else:
            print(tmp[n//2])



Measured memory_bytes: 33108
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

#define NMAX 200000

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

    int n=1;
    int powe=26;
    int c=0;
    while(n<=N){
        n+=powe;
        powe*=26;
        c++;
    }

    powe/=26;
    n-=powe;
    c--;

    //cout<<n<<","<<powe<<","<<c<<endl;

    N-=n;

    n=26;
    while(c!=0){
        n*=26;
        c--;
    }

    n/=26;
    //cout<<n<<","<<N<<","<<c<<endl;
    while(n!=0){
        cout<<(char)(N/n+'a');
        N%=n;
        n/=26;
    }
}


Measured memory_bytes: 3124
#include<iostream>
#include<vector>


using namespace std;

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

  vector<int> d(n);
  vector<int> a(100010,0);

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

  int cnt = 0;
  int flag = 0;
  int flag_e = 0;
  int prev;
  int next;
  for( int i = 0; i < 100010; i++ ){
    if( cnt >= n/2 )flag = 1;
    if(!flag){
      cnt += a[i];
      prev = i;
    }
    next = i;
    if(flag && a[i] != 0)break;
  }


 if(cnt == n/2) cout <<  next - prev << endl;
 else cout << 0 << endl;
}





Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

vector<ll> fac;
vector<ll> ifac;

ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

ll f(ll r, ll c) {
    return (fac[r + c] * ifac[r] % MOD) * ifac[c] % MOD; }

ll g(ll r, ll c) { return f(r+1, c+1) - 1; }

int main() {
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll t = 1;
    fac.push_back(t);
    ifac.push_back(1);
    for(auto i = 1; i < r2 + c2 + 3; i++) {
        t *= i;
        t %= MOD;
        fac.push_back(t);
        ifac.push_back(modinv(t));
    }
    ll ans =
        (g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1) + MOD * 2) % MOD;
    cout << ans << endl;
    return 0;
}

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

#define NILL -1

struct node{
    int left, right, parent, depth;

    node(){
        left = NILL;
        right = NILL;
        parent = NILL;
        depth = NILL;
    }
};

void setDepth(std::vector<node>& tree, int a, int p){
    tree[a].depth = p;
    if(tree[a].left != NILL){
        setDepth(tree, tree[a].left, p+1);
    } 
    if(tree[a].right != NILL) setDepth(tree, tree[a].right, p);
}

std::vector<int> printChild(std::vector<node>& tree, int a){
    std::vector<int> child;
    int b;
    if(tree[a].left != NILL){
        b = tree[a].left;
        while(b != NILL){
            child.push_back(b);
            b = tree[b].right;
        }
    }
    return child;
}

int main(void){
    int n;
    std::cin >> n;
    std::vector<node> tree(n);

    int id, k;
    std::vector<int> c;
    std::vector<int> node_depth;

  
    
    for(int i = 0; i < n; i++){
        std::cin >> id >> k;
        c.resize(k);

        if(k == 0){
            continue;
        }

        for(int j = 0; j < k; j++){
            std::cin >> c[j];
            
        }

        for(int j = 0; j < k; j++){
            tree[id].left = c[0];
            tree[c[j]].parent = id;
            if(j != k-1){
                tree[c[j]].right = c[j+1];
            }
            
        }
        c.clear();
    }

    int root;
    for(int i = 0; i < n; i++){
        if(tree[i].parent == -1){
            root = i;
            break;
        }
    }

    setDepth(tree, root, 0);

    std::string type;
    std::vector<int> child;
    for(int i = 0; i < n; i++){
        if(tree[i].parent == -1){
            type = "root";
        }else if(tree[i].left == NILL){
            type = "leaf";
        }else{
            type = "internal node";
        }
        std::cout << "node " << i << ": parent = " << tree[i].parent << ", depth = " \
        << tree[i].depth << ", "<< type << ", ";
        child = printChild(tree, i);
        std::cout << "[";
        int m = child.size();
        for(int j = 0; j < m; j++){
            
            std::cout << child[j];
            if(j != m-1){
                std::cout << ", ";
            }
        }
        std::cout << "]"<< std::endl;
    }    
    

    return 0;
}


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
typedef long long ll;
//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
/*
vector<int> d(100000);
vector<int> b(100000);
class UnionFind{
	public:
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	signed find(signed x){
		if(d[x]==x){
			return x;
		}else{
			return d[x]=find(d[x]);
		}
	}
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(b[x]<b[y]){
			d[x]=y;
		}else{
			d[y]=x;
			if(b[x]==b[y])b[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
};
*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n==25)cout<<"Christmas"<<endl;
	if(n==24)cout<<"Christmas Eve"<<endl;
	if(n==23)cout<<"Christmas Eve Eve"<<endl;
	if(n==22)cout<<"Christmas Eve Eve Eve"<<endl;

	return 0;
}


Measured memory_bytes: 256