akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>

using namespace std;

typedef long long LL;

const int N = 50010, mod = 1e9 + 7;

int primes[N], cnt;
bool st[N];

void init(int n)
{
    for(int i = 2; i <= n; i ++)
    {
        if(!st[i])  primes[cnt ++] = i;
        for(int j = 0; primes[j] <= n / i; j ++)
        {
            st[i * primes[j]] = true;
            if(i % primes[j] == 0)  break;
        }
    }
}

int qmi(int a, int k)
{
    int res = 1;
    while(k)
    {
        if(k & 1)  res = (LL)res * a % mod;
        k >>= 1;
        a = (LL)a * a % mod;
    }
    return res;
}

int C(int a, int b)
{
    if(a < b)  return 0;
    
    int up = 1, down = 1;
    for(int i = a, j = b; j; i --, j --)
    {
        up = (LL)up * i % mod;
        down = (LL)down * j % mod;
    }
    return (LL)up * qmi(down, mod - 2) % mod;
}

int main()
{
    //init(N - 1);
    
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    
    int res = (((LL)qmi(2, n) - 1 - C(n, a) - C(n, b)) % mod + mod) % mod;
    printf("%d", res);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc148
{
    class Program
    {
        static void Main(string[] args)
        {
           //Console.SetIn(new StreamReader("input.txt"));
            solve_abc148B();
        }
        public static void solve_abc148C()
        {

        }

        public static void solve_abc148B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] st = Console.ReadLine().Split();
            char[] ans = new char[2 * n];
            int k = 0;
            for (int i = 0; i < n; i++)
            {
                ans[k++] = st[0][i];
                ans[k++] = st[1][i];

            }

            Console.WriteLine(new string(ans));
        }

        public static void solve_abc148A()
        {
            int a  = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());

            if ((a == 1 && b == 2) || (a == 2 &&  b == 1))
            {
                Console.WriteLine(3);
            }
            else if ((a == 1 && b == 3) || (a == 3 && b == 1))
            {
                Console.WriteLine(2);
            }
            else
            {
                Console.WriteLine(1);
            }


        }
    }
}


Measured memory_bytes: 13396
n = int(input())
a = list(map(int, input().split()))

count = 0
sign = 0
num = 0
ans = 0
for i, ai in enumerate(a):
    if count == 0:
        num = ai
        sign = 0
        count += 1
    elif count == 1:
        if ai > num:
            sign = 1
        elif ai < num:
            sign = -1
        else:
            sign = 0
        count += 1
        num = ai
    else:
        if sign == 0:
            if ai > num:
                sign = 1
            elif ai < num:
                sign = -1
            else:
                sign = 0
            count += 1
            num = ai
        elif sign > 0:
            if ai < num:
                num = ai
                count = 1
                sign = 0
                ans += 1
            else:
                num = ai
        else:
            if ai > num:
                num = ai
                count = 1
                sign = 0
                ans += 1
            else:
                num = ai

if count > 0:
    ans += 1

print(ans)

Measured memory_bytes: 14480
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

ans1 = [0 for i in range(4001)]
ans2 = [0 for i in range(4001)]
ans3 = [0 for i in range(4001)]
ans4 = [0 for i in range(4001)]

for i in range(1001):
    ans1[i] = 1
for i in range(1001,4001):
    ans1[i] = 0

for i in range(4001):
    for j in range(1001):
        ans2[i] += ans1[i-j]

for i in range(4001):
    for j in range(1001):
        ans3[i] += ans2[i-j]

for i in range(4001):
    for j in range(1001):
        ans4[i] += ans3[i-j]

#print("DONE")
N = list(get_input())
for l in range(len(N)):
    print(ans4[int(N[l])])


Measured memory_bytes: 5988
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int ans=0;
    while(*max_element(h.begin(),h.end())>0){
        int last=0;
        for(int i=0;i<n;i++){
            if(last<1&h[i]>0){
                ans++;
            }
            last=h[i];
            if(h[i]>0) h[i]--;            
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.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++)

int main() {
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ret = 0
for i in range(A + 1):
  for j in range(B + 1):
    if (X - 500 * i - 100 * j) // 50 in range(C+1):
      ret += 1

print(ret)


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

using namespace std;

class DisjointSet{
public:
	vector<int> rank,p;
	//p???parents shows
	DisjointSet(){}
	DisjointSet(int size){
		rank.resize(size,0);
		p.resize(size,0);
		for (int i = 0; i < size; ++i) {makeSet(i);}
	}
	void makeSet(int x){
		p[x]=x;
		rank[x]=0;
	}
	bool same(int x,int y){
		//findSet(x)==findSet(y);
		return findSet(x)==findSet(y);
	}
	//link(findSet(x),findSet(y);
	void unite(int x,int y){
		link(findSet(x),findSet(y));
	}
	//rank[x]>rank[y]
	//p[y]=x;
	void link(int x,int y){
		if(rank[x]>rank[y]){
			p[y]=x;
		}else{
			p[x]=y;
			if(rank[x]==rank[y]){
				rank[y]++;
			}
		}
	}
	int findSet(int x){
		if(x!=p[x]){//x!=p[x];
			p[x]=findSet(p[x]);//p[x]=findSet(p[x]);
		}
		return p[x];
		//return p[x]
	}
};

int main(){
	int n,a,b,q;
	int t;
	cin>>n>>q;
	DisjointSet ds=DisjointSet(n);

	for (int i = 0; i < q; ++i) {
		cin>>t>>a>>b;
		if(t==0)ds.unite(a,b);
		else if(t==1){
			if(ds.same(a,b))cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
const int N=2003,M=1000000007,inf=2e9;
using namespace std;
map<long long,int>mp;
int n,m,to[N],hd[N],lk[N],ln[N],cnt,
u,v,w,bin[N];
inline void add(int u,int v){
	to[++cnt]=v,hd[cnt]=lk[u],lk[u]=cnt,ln[cnt]=w;
}
void dfs(int x,int y,int d){
	if(x==v){w=d;return;}
	for(int i=lk[x];i;i=hd[i])
	if(to[i]^y)dfs(to[i],x,max(d,ln[i]));
}
long long lim;
struct ed{int u,v,w;}a[N];
int main(){
	scanf("%d%d%lld",&n,&m,&lim),bin[0]=1;
	for(int i=0;i<m;i++)bin[i+1]=bin[i]*2%M,
	scanf("%d%d%d",&u,&v,&w),a[i]={u,v,w};
	sort(a,a+m,[](ed x,ed y){return x.w<y.w;});
	for(int i=0;i<m;i++){
		u=a[i].u,v=a[i].v,w=inf;
		dfs(u,0,0);
		if(w<inf)mp[a[i].w-w]++;
		else mp[0]++,w=a[i].w,lim-=w,add(u,v),add(v,u);
	}
	u=mp[lim],v=0;
	for(auto i:mp)if(i.first>lim)v+=i.second;
	printf("%d",lim?(bin[u]-1ll)*bin[v+1]%M:(bin[u]-2ll)*bin[v]%M);
}

Measured memory_bytes: 384
// AtCoder150 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>
#include <ctype.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}

int main(void)
{
    int i,j,n;
    long long int N,a,b;
    long long int cnt = 0;

    scanf("%lld %lld %lld", &N, &a, &b);

    cnt += (N / (a+b)) * a;
    if(N %(a+b) > a){
        cnt += a;
    }else{
        cnt += N %(a+b);
    }
    printf("%lld", cnt);
    return 0;

}


Measured memory_bytes: 128
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [i-1 for i in a]
visited = [-1]*n
route = []
now = 0
hop = 0
while visited[now] == -1:
    visited[now]=hop
    route.append(now)
    now = a[now]
    hop+=1
loop_st = 0
for r in route:
    if r==now: break
    loop_st+=1
loop = route[loop_st:]
if k < len(route):
    print(route[k]+1)
else:
    print(loop[(k-loop_st)%len(loop)]+1)

Measured memory_bytes: 32328
N,M,K=list(map(int,input().split()))

mod=998244353

com=1
ans=0

for i in range(K+1):
    ans+=M*com*pow(M-1,N-1-i,mod)
    ans%=mod
    com*=(N-1-i)*pow(i+1,mod-2,mod)
    com%=mod

print(ans)

Measured memory_bytes: 73236
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    long long int k,ans1,ans2;
    cin>>k;
    ans1=k%10;
  //  cout<<ans1<<endl;
    k/=10;
    ans2=k%10;
    // cout<<ans2<<endl;
    k/=10;
     //cout<<k<<endl;
    if(ans1==7 || ans2==7 || k==7)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3596
n,c,k=map(int,input().split())
t=[0]*n
for i in range(n):
    t[i]=int(input())
t.sort()
s=0
lt=0
ln=0

if c==1:
    print(n)
    exit()
for i in range(n):

    if i==0:
       lt=i
       ln+=1

    else:
        if t[i]-t[lt]>k:
            s+=1
            lt=i
            ln=0

        ln+=1
        if ln==c:
            s+=1
            lt=i+1
            ln=0

        #print(i, s, lt, ln)


    
if ln>0:
    s+=1

print(s)


Measured memory_bytes: 13384
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second 

using namespace std;

int n;
string s;
char c[100100];
char p[100100];

int main() {
    // ifstream cin("tst.in");
    // ofstream cout("tst.out");
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> s;
    n = s.size();
    s = '+' + s;
    for (int i = 1; i <= n; i++)
        c[i] = s[i];

    for (int i = 1; i <= n / 2; i++)
        if (c[i] != c[n - i + 1])
            return cout << "No", 0;

    int len = (n - 1) / 2;
    for (int i = 1; i <= len; i++)
        p[i] = c[i];

    for (int i = 1; i <= len / 2; i++)
        if (p[i] != p[len - i + 1])
            return cout << "No", 0;

    for (int i = len + 2; i <= n; i++)
        p[i - len - 1] = c[i];

    // for (int i = 1; i <= len; i++)
    //     cout << p[i];

    for (int i = 1; i <= len / 2; i++)
        if (p[i] != p[len - i + 1])
            return cout << "No", 0;

    cout << "Yes";     

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#EDPC H

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
maze = [input() for _ in range(h)]
dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            if j == 0:
                if i+1 < h:
                    if maze[i+1][j] == '.':
                        dp[i+1][j] += dp[i][j]
                        dp[i+1][j] %= mod
            else:
                dp[i][j] += dp[i][j-1]
                dp[i][j] %= mod
                if i+1 < h:
                    if maze[i+1][j] == '.':
                        dp[i+1][j] += dp[i][j]
                        dp[i+1][j] %= mod
print(dp[-1][-1])                   
    


Measured memory_bytes: 52848
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<tuple<string, int, int>> r;
   rep(i, 0, n) {
      string s;
      int p;
      cin >> s >> p;
      r.emplace_back(s, -p, i + 1);
   }
   sort(r.begin(), r.end());
   rep(i, 0, n) {
      int ri = get<2>(r[i]);
      cout << ri << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;

int main() {
	string s, t;
	int count = 0;
	cin >> s;
	t = s;
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size() / 2; i++) {
		if (s[i] != t[i]) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100010],b[100010];
int main(void){
	scanf("%s",a+1);
	int cnt=0;
	for(int i=strlen(a+1);i>=1;i--){
		b[++cnt]=a[i];
	}
	for(int i=1;i<=strlen(a+1);i++){
		if(a[i]=='b') a[i]='d';
		else if(a[i]=='d') a[i]='b';
		else if(a[i]=='p') a[i]='q';
		else if(a[i]=='q') a[i]='p';
		if(a[i]==b[i]) continue;
		else{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

int N;

int card[14];
vector<int> res;

bool isvalid( int n,int i){
  if( (n-i) % i == 0 ) return true;
  return false;
}

bool solve(int n,int cnt){
  if( cnt == 1 ) {
    res.emplace_back( n );
    return true;
  }
  for(int i=13;i>=1;i--){
    if( card[i] == 0 ) continue;
    if( !isvalid(n,i) ) continue;
    card[i]--;
    res.emplace_back( i );
    if( solve( n - i, cnt-1 ) ) return true;
    res.pop_back();
    card[i]++;
  }
  return false;
}

int main(){
  while( cin >> N && N){
    memset( card,0,sizeof(card) );
    res.clear();
    int sum = 0;
    for(int i=0;i<N;i++){
      int a; cin >> a;
      sum += a;
      card[a]++;
    }    
    if( !solve(sum,N) )
      cout << "No" << endl;
    else {
      reverse( res.begin(), res.end() );
      for( int i=0;i<res.size();i++){
        if( i ) cout << " ";
        cout << res[i];
      }
      cout << endl;
    }      
  }
}

Measured memory_bytes: 3032
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define iter ::iterator
#define upb upper_bound
#define lwb lower_bound

#define sz(v) v.size()
#define aloc(i, a, n) i *a = new i[n]

#define for0(i,a) for(ll i = 0; i < a; i++)
#define fori(i,a,b) for(ll i = a; i < b; ++i)
#define rfor0(i,a) for(ll i = a; i >= 0; --i)
#define rfor(i,a,b) for(ll i = a; i >= b; --i)

//##############################################################################

int main(){

	ll N,K,Q;
	cin >> N >> K >> Q;
	aloc(ll, arr, N);
	//for0(i, N) arr[i] = K;
	

	for0(i, Q){	
		int a;
		cin >> a;
		arr[a-1]++;	
	}	

	for0(i, N){
	
		if(K - Q + arr[i] > 0) cout << "Yes\n";
		else cout << "No\n";
	}

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,n,t,temp=9999;
    scanf("%d %d",&n,&t);
    for(int i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        if(b>t)continue;
        else{
            if(a<temp){
                temp=a;
            }
        }
    }
    if(temp==9999){
    printf("TLE\n");
    return 0;
    }
    printf("%d\n",temp);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc111/tasks/arc103_a
# v[::2],v[1::2]に分けて考える
# vの一番多い要素をカウント
# ただし、前者と後者d一番多い要素が等しい場合は、どちらかの二番目を用いる

n = read_a_int()
V = read_ints()

cnt0 = [(0, 0)] + list(Counter(V[::2]).items())
cnt1 = [(0, 0)] + list(Counter(V[1::2]).items())
cnt0.sort(key=itemgetter(1))
cnt1.sort(key=itemgetter(1))

if cnt0[-1][0] == cnt1[-1][0]:
    second = max(cnt0[-2][1], cnt1[-2][1])
    first = max(cnt0[-1][1], cnt1[-1][1])
    print(n - (second + first))
else:
    print(n - (cnt0[-1][1] + cnt1[-1][1]))


Measured memory_bytes: 63064
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

int main(void) {
  int X, X_tmp, N, a;
  
  cin >> X;

  N = X/100;
  a=X-100*N;

  if(5*N>=a) cout << 1 << endl;
  else cout << 0 << endl;

  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int k,x;
  cin >> k >> x;
  rep(i,2*k-2){
    int y=i-k+1;
    cout << x+y << " "; 
  }
  cout << x+k-1 << endl;
}  


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e3 + 5;
	long mod = (long) 1e9 + 7;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		int K = in.nextInt();
		int arr[] = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		boolean dp[] = new boolean[K + 1];
		for (int i = 0; i <= K; i++) {
			for (int x : arr) {
				if (i >= x && !dp[i - x]) {
					dp[i] = true;
				}
			}
		}
		if (dp[K]) {
			pw.println("First");
		} else {
			pw.println("Second");
		}
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 26204
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
    int n;
    cin >> n;
    int a[200001], b[200001];

    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];

    int count = 0;

    bool fail = false;
    int success = 0;

    rep(i, 0, n) if(a[i] == b[i]) success++;

    int i = 0;
    int tgk = 0;
    while(1) {
        if(i == n) i = 0;
        if(a[i] == b[i]) {
            i++;
            continue;
        }
        if(b[i] > b[(n + i - 1) % n] && b[i] > b[(n + i + 1) % n]) {
            int sum = b[(n + i + 1) % n] + b[(n + i - 1) % n];
            if(b[i] / sum == 0) {
                fail = true;
                break;
            }


            if((b[i] - a[i]) % sum == 0) {
                count += (b[i] - a[i]) / sum;
                b[i] = a[i];
            }else {
                count += b[i] / sum;
                b[i] = b[i] % sum;
            }

            if(a[i] == b[i]) success++;
            if(b[i] < a[i]) fail = true;
            i -= 2;
            if(i < 0) i += n;
            tgk = 0;
        }
        i++;
        if(fail) break;
        if(success == n) break;
    }

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

    cout << count << endl;
}


Measured memory_bytes: 3328
import sys
 
def make_connected_group(G):
    C = [None]*len(G)
    group = 0
    for i,p in enumerate(C):
        if p != None: continue
        friends = [i]
        while len(friends) > 0:
            f = friends.pop()
            if C[f] == None:
                C[f] = group
                friends += G[f]
        group += 1
    return C
 
 
if __name__=='__main__':
    n,m = list(map(int,sys.stdin.readline().split()))
    G = [[] for _ in range(n)]
    for j,line in enumerate(sys.stdin):
        if not j < m:
            q = int(line)
            break
        s,t = list(map(int,line.split()))
        G[s].append(t)
        G[t].append(s)
    C = make_connected_group(G)
    for j,line in enumerate(sys.stdin):
        if not j < q: break
        s,t = list(map(int,line.split()))
        print('yes' if C[s] == C[t] else 'no')

Measured memory_bytes: 33568
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    cout << !n << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main()
{
    int x;
    cin >> x;
    int num [x];
    int c=1;
    int tot=0;
    int counter =0;
    for (int y=0;y<x;y++)
    {
        num [y]=c;
        c+=1;
        int z=1;
        for(int d=0;d<x;d++)
        {
            tot=0;
            tot=num[y]+z;
            z+=2;
            if (tot<=x)
            {
                counter++;
            }
        }
    }
    cout << counter;
    return 0;
}


Measured memory_bytes: 3152
X,Y,A,B,C = map(int,input().split())
reds = list(map(int,input().split()))
greens = list(map(int,input().split()))
nos = list(map(int,input().split()))

reds.sort(reverse=True)
greens.sort(reverse=True)
nos.sort(reverse=True)

bests = reds[:X]+greens[:Y]+nos
bests.sort(reverse=True)
print(sum(bests[:X+Y]))

Measured memory_bytes: 23328
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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


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

    queue<ll> A[N];
    rep(i, N){
        rep(j, N - 1){
            ll a;
            cin >> a;
            A[i].push(a - 1);
        }
    }

    ll day = 0;
    ll matchCount = 0;
    ll lastMatch[N];
    rep(i, N){
        lastMatch[i] = 0;
    }
    queue<ll> matchInADay[2];
    ll checkPlayer;
    rep(i, N){
        matchInADay[0].push(i);
    }
    bool noMatch = false;
    while(matchCount < N * (N - 1) / 2){
        day++;
        if(matchInADay[(day - 1) % 2].empty()){
            noMatch = true;
            break;
        }
        while(!matchInADay[(day - 1) % 2].empty()){
            checkPlayer = matchInADay[(day - 1) % 2].front();
            matchInADay[(day - 1) % 2].pop();
            if(!A[checkPlayer].empty() && A[A[checkPlayer].front()].front() == checkPlayer && lastMatch[checkPlayer] < day && lastMatch[A[checkPlayer].front()] < day){
                lastMatch[A[checkPlayer].front()] = day;
                lastMatch[checkPlayer] = day;
                matchInADay[day % 2].push(A[checkPlayer].front());
                matchInADay[day % 2].push(checkPlayer);
                A[A[checkPlayer].front()].pop();
                A[checkPlayer].pop();
                matchCount++;
            }
        }
        // cout << "day: " << day << endl;
        // rep(i, N){
        //     if(A[i].empty()){
        //         cout << "finished" << endl;
        //     }else{
        //         cout << A[i].front() + 1 << endl;
        //     }
        // }
    }

    if(noMatch){
        cout << -1 << endl;
    }else{
        cout << day << endl;
    }

    return 0;
}




Measured memory_bytes: 12288
#include<stdio.h>
int main()
{
    int a,b,c,t,i;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d%d%d",&a,&b,&c);
        if(a>b&&a>c&&(a*a)==(b*b)+(c*c))
            printf("YES\n");
        else if(b>c&&b>a&&(b*b)==(a*a)+(c*c))
            printf("YES\n");
        else if(c>a&&c>b&&(c*c)==(a*a)+(b*b))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1008
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String x = in.next();

	char[] charArray = x.toCharArray();

	int cnt = 0;

	for (char ch : charArray) {
		if(ch == '1'){
			cnt++;
		}
	}
	System.out.print(cnt);

	}
}

Measured memory_bytes: 21844
// ------------------------------------
// Date:2018/ 3/ 4
// Problem:ABC 060 ChoostIntegers b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

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

  bool ok = false;

  FOR(i, 1, b + 1) {
    if ((a * i) % b == c) {
      ok = true;
    }   
  }

  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass
{
	static void Main(string[] args)
	{
      string a = Console.ReadLine();
			string b = Console.ReadLine();
			string Ans = "EQUAL";
			if (a.Length > b.Length)
			{
				Ans = "GREATER";
			}
			else if (a.Length < b.Length)
			{
				Ans = "LESS";
			}
			else
			{
				for (int i = 0; i < a.Length; i++)
				{
					int na = Convert.ToInt32(a[i]);
					int nb = Convert.ToInt32(b[i]);
					if (na > nb)
					{
						Ans = "GREATER";
						break;
					}
					else if (na < nb)
					{
						Ans = "LESS";
						break;
					}
				}	
			}
			Console.WriteLine(Ans);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#define mod 1000000007


int main() {
    long long n, a, b; std::cin >> n >> a >> b;
    std::vector<long long> x(n);
    for(int i = 0; i < n; i++) {
        std::cin >> x[i];
    }

    long long dp[n];
    dp[0] = 0;

    for(int i = 0;i < n - 1; i++) {
        dp[i+1] = std::min(dp[i]+a*(x[i+1]-x[i]),dp[i] + b);
    }

    std::cout << dp[n-1] << std::endl;

}

Measured memory_bytes: 4784
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int L, R, d;
	cin >> L >> R >> d;
	int ans = 0;
	for (int i = L; i <= R; i++) {
		if (i%d == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val s = sc.next

  case class Memo[I, O](f: I => O) extends (I => O) {

    import collection.mutable.{Map => Dict}

    val cache = Dict.empty[I, O]

    override def apply(x: I): O = cache getOrElseUpdate(x, f(x))
  }

  type Calc = Memo[String, (Long, Int)]

  lazy val f: Calc = Memo {
    case "" => (0L, 1)
    case str: String =>
      val len = str.length
      (for {
        i <- 1 to len
        val (sum, cnt) = f(str.substring(i))
      } yield {
        (str.substring(0, i).toLong * cnt + sum, cnt)
      }).reduce((t1, t2) => (t1._1 + t2._1, t1._2 + t2._2))
  }
  println(f(s)._1)
}


Measured memory_bytes: 25528
list1 = []
list1 = [int(i) for i in input()]
len1 = len(list1)
list2 = [0 if i%2==0 else 1 for i in range(len1)]
list3 = [1 if i%2==0 else 0 for i in range(len1)]
dif1 = [(x1 - x2)**2 for (x1, x2) in zip(list1, list2)] 
dif2 = [(x1 - x2)**2 for (x1, x2) in zip(list1, list3)] 
ans1 = sum(dif1)
ans2 = sum(dif2)
if ans1 <= ans2:
    print(ans1)
else:
    print(ans2)


Measured memory_bytes: 7068
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def dense(a, b):
    try:
        return 100 * b / (a + b)
    except ZeroDivisionError:
        return 0


A, B, C, D, E, F = il()
A *= 100
B *= 100
max_dense = 0
max_water = 0
max_sugar = 0
for a in range(31):
    for b in range(31):
        water = a * A + b * B
        if water == 0:
            break
        for c in range((F - water) // C + 1):
            for d in range((F - water) // D + 1):
                sugar = c * C + d * D
                if water + sugar > F or water / 100 * E < sugar:
                    break
                if max_dense <= dense(water, sugar):
                    max_dense = dense(water, sugar)
                    max_water = water
                    max_sugar = sugar
print(max_water + max_sugar, max_sugar)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN = 2e5+5;
int arr[mxN], st[20][mxN];
int jump(int pos, int x)
{
	for(int i=19;i>=0;i--)
		if((x>>i)&1)
			pos = st[i][pos];
	return pos;
}
int main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>arr[i];
    int L;
    cin>>L;
    for(int i=1;i<=n;i++)
    {
    	int l = ub(arr+1,arr+n+1,arr[i]+L)-arr-1;
		st[0][i]=l; 
	}
	for(int i=1;i<20;i++)
		for(int j=1;j<=n;j++)
			st[i][j]=st[i-1][st[i-1][j]];
	int q;
	cin>>q;
	while(q--)
	{
		int x,y;
		cin>>x>>y;
		if(x>y)
			swap(x,y);
		int l=0, r=n;
		while(l<r)
		{
			int mid=(l+r)>>1;
			if(jump(x,mid)>=y)
				r = mid;
			else
				l = mid+1;
		}
		cout<<r<<endl;
	}
}


Measured memory_bytes: 11896
#include<bits/stdc++.h>
/*
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
*/
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    int g[110][110];
    int i, j;
    int u, k, v;
    pair<int, int> p;
    int dist[110];
    bool visited[110];
     
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            g[i][j] = 0;
        }
    }
     
    for(i = 0; i < n; i++){
        dist[i] = -1;
        visited[i] = false;
    }
     
    for(i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        for(j = 0; j < k; j++){
            cin >> v;
            v--;
            g[u][v] = 1;
        }
    }

	queue< pair<int, int> > q;
	for(i = 0; i < n; i++){
		if(g[0][i]) q.push(make_pair(0, i));
	}

	dist[0] = 0;
	visited[0] = true;
	while(!q.empty()){
		p = q.front();
		q.pop();

		if(visited[p.second]) continue;
		visited[p.second] = true;

		dist[p.second] = dist[p.first] + 1;

		for(j = 0; j < n; j++){
            if(g[p.second][j]){
                q.push(make_pair(p.second, j));
            }
        }
	}

	for(i = 0; i < n; i++){
        printf("%d %d\n", i+1, dist[i]);
    }
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 1e5 + 100;
int cnt[MAXN];

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		cnt[a]++;
		cnt[b]++;
	}
	bool yes = true;
	for(int i = 1; i <= N; i++)
		if(cnt[i] % 2 == 1)
			yes = false;
	puts(yes ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, a[10000], b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  ll s = 0;
  FOR(i, 0, n){
    cin >> b;
    b = b - a[i];
    if(b > 0) b >>= 1;
    s += b;
  }
  cout << (s >= 0 ? "Yes" : "No") << endl;
  return 0;
}

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

int n,x,a[3];
double dp[305][305][305];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x),a[x-1]++;
	for(int k=0;k<=a[2];k++)
	{
		for(int j=0;j<=a[2]+a[1]-k;j++)
		{
			for(int i=0;i<=n-j-k;i++)
			{
				if(i||j||k) dp[i][j][k]=1.0*n/(i+j+k);
				if(i) dp[i][j][k]+=1.0*i/(i+j+k)*dp[i-1][j][k];
				if(j) dp[i][j][k]+=1.0*j/(i+j+k)*dp[i+1][j-1][k];
				if(k) dp[i][j][k]+=1.0*k/(i+j+k)*dp[i][j+1][k-1];
			}
		}
	}
	printf("%.12lf\n",dp[a[0]][a[1]][a[2]]);
}

Measured memory_bytes: 219392
using System;
class a
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int d = int.Parse(str[1]);
        int count = 0;
        while (n > 0)
        {
            n = n - (2 * d + 1);
            count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;

class Program
{
    static void Main()
    {
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
            long a, b;
            string[] input = Console.ReadLine().Split();
            a = long.Parse(input[0]);
            b = long.Parse(input[1]);
            long s = (long)Pow(a * b, 0.5);
            if (s * s == a * b)
            {
                if (s == a)
                    Console.WriteLine(2 * s - 2);
                else
                    Console.WriteLine(2 * s - 3);
                continue;
            }
            if (s * (s + 1) < a * b)
                Console.WriteLine(2 * s - 1);
            else
                Console.WriteLine(2 * s - 2);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  for (ll i = 1; i <= N; ++i) {
    ll s = i*(i+1)/2;
    if (s - N < 0) continue;

    if (s - N == 0) {
      for (ll j = 1; j <= i; ++j) {
        cout << j << endl;
      }
      break;
    }

    for (ll j = 1; j <= N; ++j) {
      if (s - j == N) {
        for (ll k = 1; k <= i; ++k) {
          if (k == j) continue;
          cout << k << endl;
        }
      }
    }
    break;
  }
}

Measured memory_bytes: 256
# ABC044C - 高橋君とカード / Tak and Cards (ARC060C)
def main():
    N, A, *X = map(int, open(0).read().split())
    X, D = [i - A for i in X], {0: 1}
    for i in X:
        for j, k in list(D.items()):
            D[i + j] = D.get(i + j, 0) + k
    ans = D[0] - 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
n,m = map(int,input().split())
h = list(map(int,input().split()))
graph = [[] for i in range(n)]

d = {}
for i in range(m):
    a,b = map(int, input().split())
    if (a-1,b-1) in d :
        continue
    d[(a-1,b-1)] = 1
    d[(b-1,a-1)] = 1
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

ans = 0
for i in range(n) :
    check = 0
    for j in graph[i] :
        if h[i] <= h[j] :
            check = 1
            break
    if check == 0 :
        ans += 1

print(ans)

Measured memory_bytes: 132788
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000
#define ST 540

int t[10000][1000];

int main(){
    int n,m;
    while(cin>>n>>m, n|m){
//        vector<vector<int> > t(m, vector<int>(800, 0));
        fill(t[0], t[10000], 0);
        int r;
        cin>>r;
        rep(i,r){
            int ti,a,b,s;
            scanf("%d %d %d %d\n", &ti, &a, &b, &s);
            if(s==0) t[b-1][ti-ST] += -1;
            else t[b-1][ti-ST] += 1;
        }

        // imosu
        rep(i,10000){
            rep(j,750){
                t[i][j+1] += t[i][j];
            }
        }

        int q;
        cin>>q;
        rep(i,q){
            int s,e,a;
            scanf("%d%d%d",&s,&e,&a);
            s-=ST; e-=ST;
            int res=0;
            for(int j=s; j<e; j++){
                if(t[a-1][j]>0) res++;
            }
            cout<<res<<endl;
        }
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
    ll N; 
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for (ll i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
        sum %= MOD;
    }
    ll res = 0;
    for (ll i = 0; i < N; ++i) {
        sum -= A[i];
        if (sum < 0) sum += MOD;
        res += A[i] * sum;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


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

int main () {
  int A, B, ans;
  cin >> A >> B;
  ans = 0;
  for (int i = A; i < B + 1; i++) {
    int a10000, a1000, a100, a10, a1;
    a10000 = i / 10000;
    a1000 = (i - 10000 * a10000) / 1000;
    a100 = (i - 10000 * a10000 - 1000 * a1000) / 100;
    a10 = (i - 10000 * a10000 - 1000 * a1000 - 100 * a100) / 10;
    a1 = (i - 10000 * a10000 - 1000 * a1000 - 100 * a100 - 10 * a10) / 1;
    
    if ((a1 == a10000) && (a10 == a1000)) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	char[] chars;
	List<String> result;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		chars = new char[26];
		for (int i = (int) 'a'; i <= (int) 'z'; ++i) {
			int index = i - (int)'a';
			chars[index] = (char) i;
		}

	}

	List<String> sub(String line) {
		Set<Character> cSet = new HashSet<>();
		for (int i = 0; i < line.length(); ++i) {
			cSet.add(line.charAt(i));
		}
		List<String> list = new ArrayList<>();
		for (int i = 0; i <= cSet.size(); ++i) {
			list.add(line + chars[i]);
		}
		return list;
	}

	void calc() {
		result = new ArrayList<>();
		result.add("a");
		for (int i = 1; i < N; ++i) {
			List<String> temp = new ArrayList<>();
			for (String line : result) {
				temp.addAll(sub(line));
			}
			result = temp;
		}
	}

	void showResult() {
		for (String line : result) {
			System.out.println(line);
		}
	}
}


Measured memory_bytes: 50772
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
    int n,K;
    cin >> n >> K;
    vector<ll>x(n),y(n);
    vector<pair<ll,ll>>p(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        p[i] = make_pair(x[i], y[i]);
    }
    sort(p.begin(),p.end());
    rep(i,n){
        x[i] = p[i].first;
        y[i] = p[i].second;
    }
    ll ans = LONG_LONG_MAX;
    if(K == 2){
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                ans = min(ans, (x[j]-x[i])*abs(y[j]-y[i]));
            }
        }
        cout << ans << endl;
        return 0;
    }
    else if(K == 3){
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = j+1; k < n; k++){
                    int l = i;
                    ll ma = max(y[i],max(y[j],max(y[k],y[l])));
                    ll mi = min(y[i],min(y[j],min(y[k],y[l])));
                    ans = min(ans,(x[k]-x[i])*(ma-mi));
                }
            }
        }
        cout << ans << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                for(int l = k+1; l < n; l++){
                    int cnt = 0;
                    ll ma = max(y[i],max(y[j],max(y[k],y[l])));
                    ll mi = min(y[i],min(y[j],min(y[k],y[l])));
                    for(int m = i; m <= l; m++){
                        if(mi <= y[m] and y[m] <= ma)cnt++;
                    }
                    if(cnt >= K){
                        ans = min(ans, (ma-mi)*(x[l]-x[i]));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    ans = len(S)
    for i in range(1, len(S)):
        if S[i] != S[i - 1]:
            ans = min(ans, max(i, len(S) - i ))
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 40432
N = int(input())
S = ""
while N != 0 :
    if N % (-2) == 0 :
        S = "0" + S
    else :
        S = "1" + S
        N -= 1
    N = N / (-2)
if len(S) == 0 :
    print(0)
else :
    print(S)
    
    

Measured memory_bytes: 2940