akhauriyash/Code-Regression huggingface dataset:
def dfs(k, path, n):
    """連結情報path,頂点の個数Nが与えられたとき
    頂点Kから各頂点までの距離をlistで返す"""
    from collections import deque # deque(),popleft()
    dist = [-1] * n
    dist[k] = 0
    que = deque([])
    que.append(k)
    while que:
        label = que.popleft()
        for i,c in path[label]: # 頂点labelと連結している頂点iと距離c
            if dist[i] == -1:
                dist[i] = dist[label] + c
                que += [i] # 次に調べる頂点に
    return dist

n = int(input())
path = [[] for i in range(n)]
# path = [{1,2}] * 3
# print(path)
for i in range(n-1):
    a, b, c = map(int, input().split())
#     print(a,b,c)
    path[a-1] += [(b-1, c)]
    path[b-1] += [(a-1, c)]

q, k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(q)]
dis = dfs(k-1, path, n)
for i in range(q):
    print(dis[xy[i][0] - 1] + dis[xy[i][1] - 1])


Measured memory_bytes: 68096
def a(q)
puts"? "+q.join(" ")
STDOUT.flush
gets
end
N=gets.to_i
s="! "
I=(1..2*N).to_a
f=a I[0,N]
l,r=1,N+1
9.times{
m=(l+r)/2
f==a(I[m-1,N])?l=m:r=m
}
x=I[l,N-1]
y=I-I[l-1,N+1]
I.map{|i|
s+=a([i]+(x.index(i)?y:x))[0]
}
puts s

Measured memory_bytes: 2372
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int L; cin>>L;
	long double h=L/3.0;
	long double result=h*h*h;
	printf("%.9Lf",result);
}


Measured memory_bytes: 256
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))
switch=1
flag=0
count=0
for i in range(N):
    switch=a[switch-1]
    if switch==2:
        flag=1
        count=i+1
        break
if flag==1:
    print(count)
else:
    print(-1)

Measured memory_bytes: 7084
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, A, B, maxn, minn;

	cin >> N >> A >> B;

	maxn = min(A, B);
	minn = max(A + B - N, 0);

	cout << maxn << ' ' << minn << endl;

	return 0;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;

void solve() {
  int k = read();
  int a = read(), b = read();
  rep(i, 0, 1000) {
    if (k * i >= a && k * i <= b) {
      puts("OK"); return;
    }
  }
  puts("NG");
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<stdio.h>
#include<ios>
#include<cmath>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<assert.h>
#include<bitset>
#include<tuple>
#include<climits>
#include<deque>
#include<utility>
#include<unordered_map>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<ext/pb_ds/assoc_container.hpp>
#include<chrono>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int n;cin>>n;
    int a[n];read(a);
    int i=0,j=n-1,si=0,sj=0;
    while(i<=j)
    {
    	if(si<=sj) si+=a[i++];
    	else if(sj<si) sj+=a[j--];
    }
    cout<<abs(si-sj);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N;
char In[2020];
vector <int> E[2020];

int down[2020];
void pdfs(int x, int fa) {
	down[x] = (In[x] == '1');
	for(int e : E[x]) if(e != fa) {
		pdfs(e, x);
		down[x] += down[e];
	}
}

typedef pair<pii, int> ppi;

pii Do(int x, int fa) {
	pii res = pii(0, 0);
	vector <pii> w;
	for(int e : E[x]) if(e != fa) {
		pii r = Do(e, x);
		r.Fi += down[e];
		r.Se += down[e];
		w.pb(r);
	}
	sort(all(w));
	if(szz(w) == 0) return res;
	int MX = 0;
	for(pii e : w) MX += e.Se;
	int MN = 0;
	int sum = 0;
	int m = szz(w);
	rep(i, m-1) sum += w[i].Se;
	if(sum < w[m-1].Fi) {
		MN = w[m-1].Fi - sum;
		return pii(MN, MX);
	}
	else {
		MN = MX % 2;
		return pii(MN, MX);
	}
}

int solve(int x) {
	pdfs(x, -1);
	pii r = Do(x, -1);
	if(r.Fi != 0) return 1e9;
	else return r.Se / 2;
}

int main() {
	scanf("%d", &N);
	scanf("%s", In+1);
	for(int i=1;i<N;i++) {
		int x, y; scanf("%d%d", &x, &y);
		E[x].pb(y);
		E[y].pb(x);
	}
	int ans = 1e9;
	for(int i=1;i<=N;i++) {
		ans = min(ans, solve(i));
	}
	if(ans > 1e8) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

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

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))

char s[1010];

int main()
{
    cin>>s;
    int len=strlen(s);
    cout<<s[0]<<len-2<<s[len-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
#define pb push_back
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int main()
{
	ll n;
	cin >> n;
	n++;
	ll ct=0;
	while(n>10)
	{
		ct+=9;;
		n/=10;
	}
	ct+=n-1;
	cout << ct << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    if N>=30:
        print('Yes')
    else:
        print('No')



if __name__ == "__main__":
    main()


Measured memory_bytes: 10136
#include "bits/stdc++.h"
using namespace std ;
typedef long long ll ;


vector < int > primes ;
int p[10000005] ;
void computePrimes(){
 	int i = 2 ;
 	for( ; i <= sqrt(10000005) ; i++ ){
 		if( p[i] != 0 ) continue ;
 		for( int j = i+i ; j < 10000005 ; j = j + i ){
 			p[j] = i ;
 		}
 	}
 	for( int j = 1 ; j < 10000005 ; j++  ){
 		if( p[j] == 0 ){
 			p[j] = j ;
 		}
 	}
}

ll f( int N ){
	if( N == 1 ) return 1 ;
	if( p[N] == N  ) return 2 ;
	// puts("Hi");
	int x ;
	ll ans = 1 ;
	x = N ;
	while( x != 1 ){
		int c = 0 ; 
		int d = p[x] ;
		while( x % d == 0 ){
			x = x / d ;
			c++ ;
		}
		ans = ans * (c+1) ;
	}
	return ans ; 
}

int main(){
	int N ;
	cin >> N ;
	computePrimes() ;
	ll ans = 0 ;

	for( int i = 1 ; i <= N ; i++ ){
		ans += (i*f(i));
		// cout << f(i) <<endl ;
	}
	cout << ans << endl ;
	return 0 ;
}

Measured memory_bytes: 42704
#include<iostream>
using std::cout;
using std::endl;
int main()
{
	for (int x = 1; x <= 9; x++)
	{
		for (int y = 1; y <= 9; y++)
		{
			cout << x <<"x"<< y <<"="<<x*y<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main (void){
        int len;
        char S[102],T[102];
        char tmp;
        scanf("%s",S);
        scanf("%s",T);
        len=strlen(S);
        for (int i = 0; i < len; i++) {
          if (strcmp(S,T)==0) {
            printf("Yes\n");
            return 0;
          }else{
            tmp=S[0];
            for (int j = 0; j < len-1; j++) {
              S[j]=S[j+1];
            }
            S[len-1]=tmp;
          }
        }
        printf("No\n");
        return 0;
}


Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n = int(input())
    ans = 0
    for m in range(1, n + 1):
        if m % 2 == 0: continue
        factor = 0
        i = 1
        while i * i < m:
            if m % i == 0: factor += 2
            i += 1
        if i * i == m: factor += 1
        if factor == 8: ans += 1
        #print("factor[{}]={}".format(m, factor))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
S = input()
chokudai = 753
minValue = abs(chokudai-int(S[0:3]))
for i in range(len(S) - 2):
    if minValue > abs(chokudai-int(S[i:i+3])):
        minValue = abs(chokudai - int(S[i:i + 3]))
print(minValue)


Measured memory_bytes: 2940
s = int(input())
alist = [s]
aset=set()
for i in range(1000000):
  n = alist[-1]
  if n in aset:
    print(len(alist))
    break
  aset.add(n)
  if n%2 ==0:
    x = n//2
  else:
    x = 3*n+1
  alist.append(x)

Measured memory_bytes: 3060
import std.stdio, std.string, std.conv, std.array, std.algorithm;

void main(){
	auto a = readln.split.map!(to!int);
	int n = a[0];
	int m = a[1];
	int c;
	int cnt,gomi;

	for(uint i;i<m;++i){
		auto b = readln.split.map!(to!int);
		c = b[0];
		if(c<n){
			cnt += n-c;
			if(n-c>gomi) gomi = n-c;
		}
	}
	writeln(cnt-gomi);
}

Measured memory_bytes: 2452
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
int a[1000100];
map<int,int> mp;

int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
		mp[a[i]]++;
	}
	ll ans=0;
	vector<int> vi;
	for(auto p:mp){
		
		if(p.second>=4)
			ans=max(ans,(ll)p.first*p.first);
		if(p.second>=2){
			vi.push_back(p.first);
			//cout<<p.first<<endl;
		}
	}
	sort(vi.begin(),vi.end());
	if (vi.size() >= 2)
		ans=max(ans, (ll)vi[vi.size() - 2] * vi.back());
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5376
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        float d = in.nextFloat();
        float t = in.nextFloat();
        float s = in.nextFloat();
        
        if(d/s > t) System.out.println("No");
        else System.out.println("Yes");
    }
}

Measured memory_bytes: 37332
from collections import deque, _heapq
N, K = map(int, input().split())
V = deque(map(int, input().split()))

class Money:
    def __init__(self):
        self.yen = 0
        self.red = []

    def value(self):
        return self.yen + sum(self.red)

    def add(self, yen):
        if yen >= 0:
            self.yen += yen
        else:
            self.red.append(yen)

    def remove(self, yen):
        if yen >= 0:
            self.yen -= yen
        else:
            self.red.remove(yen)

#mny = Money()
def get(cnt, mny, lstop, rstop):
    ans = mny.value()

    if cnt <= 0:
        return ans

    if len(V) > 0:

        if not lstop:
            w = V.popleft()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, lstop, rstop))
            mny.remove(w)
            V.appendleft(w)

        if not rstop:
            w = V.pop()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, True, rstop))
            mny.remove(w)
            V.append(w)

    if len(mny.red) > 0:
        w = min(mny.red)
        mny.red.remove(w)

        V.appendleft(w)
        ans = max(ans, get(cnt-1, mny, True, True))
        V.popleft()

        mny.red.append(w)    

    return ans

print(get(K, Money(), 0, 0))


Measured memory_bytes: 3444
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5+3;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n,i;
	cin>>n>>i;
	cout<<n-i+1<<endl;

	return 0;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
shima = [list(map(int,input().split())) for k in range(M)]
shima = sorted(shima, key = lambda x: x[1])

now = 0
ans = 0
for i in shima:
    if now < i[0]:
        now = i[1]-1
        ans += 1
print(ans)

Measured memory_bytes: 29852
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2+5;

int n;
int m;
char grid[N][N];

int main(){
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            grid[i][j] = '#';
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> grid[i][j];
        }
    }
    for(int i = 0; i <= n+1; i++){
        for(int j = 0; j <= m+1; j++){
            cout << grid[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 256
cd i n
  | i > n     = []
  | otherwise =
      if (n `mod` i) == 0
      then i:(cd (i+1) n)
      else cd (i+1) n

ans x =
  let g = foldr1 gcd x
      c = cd 1 g
  in
    c

main = do
  _ <- getLine
  l <- getLine
  let i = map read $ words l :: [Int]
      o = ans i
  mapM_ print o
  

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int x,a,b,c;
int main(void)
{
    scanf("%d %d %d",&a,&b,&c);
    x = 3*max({a,b,c})-(a+b+c);
    printf("%d",x&1?(x+3)>>1:x>>1);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - Cats and Dogs
https://beta.atcoder.jp/contests/abc094/tasks/abc094_a

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    ans = 'YES'
    A, B, X = map(int, input().split())
    if A > X:
        ans = 'NO'
    if A + B < X:
        ans = 'NO'
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3060
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,a,n)    for(int i=a;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int n;
    cin>>n;
    vii a(n,0);
    rep(i,0,n-1)
    {
        int x;
        cin>>x;
        a[x-1]++;
    }
    rep(i,0,n)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}


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

#define DEBUG

#ifndef LOCAL
#undef DEBUG
#endif

#ifdef DEBUG
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) ;
#endif

#define maxn 111111
int a[maxn];
map<int,int> mp;
int n;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		mp[x]++;
	}
	int ans=0;
	for(int i=0;i<=100000;i++)
	{
		ans=max(ans,mp[i-1]+mp[i]+mp[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}


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

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

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

    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        vector<int> Z = z_algorithm(s.substr(i));
        for(int j = 0; j < s.length() - i; j++){
            if (Z[j] <= j)ans = max(ans, Z[j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3204
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int foo(string s) {
	s = s.substr(1, s.length() - 2);
	if (s[0] != '[') {
		stringstream ss(s);
		int x; ss >> x;
		return x / 2 + 1;
	}
	int y = 0, _i = 0;
	vector<int> v;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '[') y++;
		else if (s[i] == ']') y--;
		if (y == 0) {
			string sub = s.substr(_i, i - _i + 1);
			v.push_back(foo(sub));
			_i = i + 1;
		}
	}
	sort(v.begin(), v.end());
	int sum = 0;
	for (int i = 0; i < v.size() / 2 + 1; i++)
		sum += v[i];
	return sum;
}

int main() {
	int T; cin >> T;
	while (T--) {
		string s; cin >> s;
		cout << foo(s) << endl;
	}
}

Measured memory_bytes: 1312
#include <cstdio>
#include <map>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;

map<int,int> m;

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int v;
    scanf("%d", &v);
    m[v]++;
  }
  int res = 0;
  FOR(it, m) {
    if(it->first <= it->second) {
      res += it->second - it->first;
    } else {
      res += it->second;
    }
    // cerr << ">" << res << endl;
  }
  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 4736
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
using namespace std;


int main() 
{
	int i;
	string s;
	cin >> s;
	for (i = 0; i < s.length(); i++)
	{
		if (i % 2 )
		{
			if (s[i] == 'R') break;
		}
		else
		{
			if (s[i] == 'L') break;
		}
	}
	if (i != s.length()) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
  ll n,ans=0;
  cin>>n;
  if(n==1)
  {
      cout<<"0"<<endl;
      return 0;
  }
  for(int i=1;i<=n;i++)
  {
      if(n/2>i)
      {
          ans++;
      }
  }
  if(n%2==0)
  cout<<ans<<endl;
  else
    cout<<ans+1<<endl;
return 0;
}



Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, fn = 0;
	scanf("%d", &n);
	for(int m=n; m; m/=10) fn += m%10;
	puts(n%fn? "No":"Yes");
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c; cin >> a >> b >> c;
  if(a == b && b == c) {
    if(a % 2 == 0) {
      cout << -1 << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
  else {
    int count = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
      int ca = a, cb = b, cc = c;
      a = cb/2 + cc/2;
      b = ca/2 + cc/2;
      c = ca/2 + cb/2;
      count++;
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
template <class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = INT_MAX;
const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vi P(N);
    rep(i, N) cin >> P[i];
    int ans = 0;
    int i_min = INF;
    rep(i, N) {
        if (chmin(i_min, P[i])) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int x,p,n;
char c;
string S;
set<int>st[6],uni;
set<int>bnf();
set<int>::iterator it;
void Prin(set<int> ans){
  //if(!ans.size())cout<<"NULL"<<endl;
  for(it=ans.begin();it!=ans.end();it++){
    if(it!=ans.begin())cout<<' ';
    cout<<*it;
  }
  if(!ans.size())cout<<"NULL";
  cout<<endl;
}
set<int> U(set<int> a,set<int> b){
  set<int>s=b;
  it=a.begin();
  while(it!=a.end())s.insert(*it),it++;
  return s;
}
set<int> I(set<int> a,set<int> b){
  set<int>s;
  it=a.begin();
  while(it!=a.end()){
    if(b.count(*it))s.insert(*it);
    it++;
  }
  return s;
}
set<int> D(set<int> a,set<int> b){
  set<int>s;
  it=a.begin();
  while(it!=a.end()){
    if(!b.count(*it))s.insert(*it);
    it++;
  }
  return s;
}
set<int> C(set<int> a,set<int> b){
  set<int>s;
  it=a.begin();
  while(it!=a.end()){
    if(!b.count(*it))s.insert(*it);
    it++;
  }
  return s;
}
set<int> ge(){
  set<int>s;
  if(S[p]=='(')p++,s=bnf(),p++;
  else if(S[p]=='c'){
    p++;
    s=C(uni,ge());
  }
  else if('A'<=S[p]&&S[p]<='Z')s=st[S[p++]-'A'];
  return s;
}
set<int> bnf(){
  set<int>s=ge();
  while('a'<=S[p]&&S[p]<='z'){
    int t=p++;
    set<int>g=ge();
    if(S[t]=='u')s=U(s,g);
    if(S[t]=='i')s=I(s,g);
    if(S[t]=='d')s=D(s,g);
    if(S[t]=='s')s=U(D(s,g),D(g,s));
  }
  return s;
}
main(){
  while(cin>>c){
    p=0;
    uni.clear();
    r(i,6)st[i].clear();
    cin>>n;
    r(i,n)cin>>x,st[c-'A'].insert(x),uni.insert(x);
    while(1){
      cin>>c>>n;
      if(c=='R')break;
      r(i,n)cin>>x,st[c-'A'].insert(x),uni.insert(x);
    }
    cin>>S;
    set<int>ans=bnf();
    Prin(ans);
  }
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
const int INF = 2001001001;

int main(){
  int n, x, l;
  cin >> n;
  vector<P> arm(n);
  for(int i=0; i<n; ++i){
    cin >> x >> l;
    arm[i].first = x+l;
    arm[i].second = x-l;
  }
  sort(arm.begin(),arm.end());
  
  int ans=0, mx = -INF;
  for(int i=0; i<n; ++i){
    if(arm[i].second >= mx){
      ++ans;
      mx = arm[i].first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef vector<ll>   vll;
typedef vector<int>   vi;
typedef set<ll>      sll;
typedef set<int>      si;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

ll i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}

// #define cerr if(0)cerr
void solve()
{
  ll n,k; cin>>n>>k;
  if(k>((n-2)*(n-1))/2) {cout<<"-1\n"; return;}

ll ct=(n-2)*(n-1); ct/=2;
vector< pll > v;

  v.pb({1,2});
  rep(i,3,n)
  	v.pb({2,i});
  
  rep(i,3,n)
    if(ct>k)
    {
    	v.pb({1,i});
    	--ct;
    }

  rep(i,3,n)
    rep(j,i+1,n)
     if(ct>k)
     {
     	v.pb({i,j});
      --ct;
     }

     cout<<sz(v)<<'\n';
     rep(i,0,sz(v)-1)
     cout<<v[i].fi<<' '<<v[i].se<<'\n';
}

Measured memory_bytes: 512
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int r = scan.nextInt() * 100;
    int g = scan.nextInt() * 10;
    int b = scan.nextInt();
    if((r + g + b) % 4 == 0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
import itertools

N = int(input())
L = list(map(int,input().split()))
count = 0
for x in itertools.combinations(L,3):
  dup = [i for i in set(x) if x.count(i) > 1]
  if dup == [] and x[0] < x[1]+x[2] and x[1] < x[2] + x[0] and x[2] < x[0] + x[1]:
    count += 1
  
print(count)

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dc[4] = {1, -1, 0,  0};
const int dr[4] = {0,  0, 1, -1};
//const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
//const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

string s;
ll ans = 0;

void calc(string t)
{
    ll sum = 0;
    int i = 0; 
    int n = t.size();
    reverse(t.begin(), t.end());
    while(i < n) {
        ll x = 0;
        ll d = 1;
        while(i < n && t[i] != '+') {
            x += (t[i]-'0') * d;
            d *= 10;
            i++;
        }
        sum += x;
        i++;
    }
    ans += sum;
}

void solve(v_int d, int n) 
{
    string t;
    irep(i, n) {
        t += s[i];
        if(d[i] && i < n-1) { t += "+"; }
    }
    calc(t);
}

void dfs(v_int d, int n)
{
    if(d.size() == n-1) {
        solve(d, n);
        return ;
    }
    
    d.push_back(0);
    dfs(d, n);
    d.pop_back();

    d.push_back(1);
    dfs(d, n);
    d.pop_back();
}

int main(void)
{
    cin >> s;
    int n = s.size();

    v_int d;
    if(n == 1) {
        cout << s << endl;
    } else {
        dfs(d, n);
        cout << ans << endl;
    }
    return 0;
}
/*atcoder*/


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

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

    auto values = std::priority_queue<double, std::vector<double>, std::greater<double>>();

    for(int i = 0; i < n; ++i) {
        int v;
        std::cin >> v;
        values.push(v);
    }

    while(values.size() >= 2) {
        const auto a = values.top();
        values.pop();
        const auto b = values.top();
        values.pop();

        values.push((a + b) / 2);
    }

    std::cout << std::fixed << std::setprecision(10);

    std::cout << values.top() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long


signed main(void) {
  int a[5];
  int k;
  rep(i, 5) {
    cin >> a[i];
  }
  cin >> k;

  string ans = "Yay!";

  if (a[4] - a[0] <= k) {

  } else {
    ans = ":(";
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*input 
9999 1
0
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);

int N, K;
bool bad[10];

bool good(int n) {
	while (n > 0) {
		if (bad[n % 10]) return 0;
		n /= 10;
	}
	return 1;
}

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

	cin >> N >> K;
	F0R(i, K) {
		int c; cin >> c;
		bad[c] = 1;
	}
	int ans = -1;
	for (int i = N;; i++) {
		if (good(i)) {
			ans = i;
			break;
		}
	}
	cout << ans << '\n';
}


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

int main(){
  int x_ans = -1;
  int y_ans = -1;
  int z_ans = -1;
  int N,Y;
  cin >> N >> Y;
  for(int x = 0; x <= N; x++){
    for(int y = 0; y <= N ; y++){
      int z = N - x - y;
      if(1000 * z + 5000 * y + 10000 * x == Y && z >= 0){
        x_ans = x;
        y_ans = y;
        z_ans = z;
        break;
      }
    }
  }
  cout << x_ans << " " << y_ans << " " 
    << z_ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long LL;
int N,i,j,x,A[200000],here[200000],town[200000];LL K;
int main(void)
{
  i=scanf("%d %lld",&N,&K);
  for(i=0;i<N;i++)here[i]=-scanf("%d",&A[i]);
  for(i=0,j=0;;i=A[i]-1,j++)if(here[i]<0)here[i]=j,town[j]=i;else{x=here[i];break;}
  if(K>=j)K=(K-x)%(x-j)+x;
  return printf("%d\n",town[K]+1),0;
}

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

using namespace std;
constexpr int64_t MOD =   998'244'353;

constexpr int     MAX =       200'005;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

template< typename T >
T mod_pow(T x, T n) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= MOD;
        (x *= x) %= MOD;
        n >>= 1;
    }
    return ret;
}
int main(void) {
    int64_t N, M, K;
    cin >> N >> M >> K;
    COMinit();

    int64_t ans = 0;
    for(int64_t i=0; i<=K; i++) {
        ans += COM(N-1, i) * mod_pow(M-1, N-1-i);
        ans %= MOD;
    }

    ans *= M;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8288
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const 
#define fr first 
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e9 + 1;
cs int base = 2333;
cs int mod = 1e9 + 7;

int n, a[ff], b[ff], c[ff], tag, cnt[ff];
int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }
signed main()
{
	cin >> n;
	rep(i, 1, n) cin >> a[i], c[a[i]] ++; b[n + 1] = a[n];
	sep(i, n, 1) b[i] = gcd(b[i + 1], a[i]);
	
	sort(a+1, a+1+n);
	rep(i, 2, a[n])
	{
		int s = 0;
		for(int j = i; j <= a[n]; j = j + i)
			s += c[j];
		if(s >= 2) tag = 1;
	}
	if(tag == 0) cout << "pairwise coprime";
	else if(b[1] == 1) cout << "setwise coprime";
	else cout << "not coprime";
}

Measured memory_bytes: 26892
#!/usr/bin/env python
MOD = 10 ** 30 + 7

N, M = map(int, raw_input().split())
s = raw_input()

p27 = [1 for i in range(500000)]
for i in range(1, 500000):
    p27[i] = p27[i - 1] * 27
    p27[i] %= MOD

m = {}
P = (ord(s[0]) - ord('a') + 1)
l = 0
r = 0
for loop in range(M):
    S = raw_input()
    if S == 'L++':
        P -= (ord(s[l]) - ord('a') + 1) * p27[r - l]
        P %= MOD
        l += 1
    elif S == 'L--':
        l -= 1
        P += (ord(s[l]) - ord('a') + 1) * p27[r - l]
        P %= MOD
    elif S == 'R++':
        r += 1
        P *= 27
        P += (ord(s[r]) - ord('a') + 1)
        P %= MOD
    elif S == 'R--':
        P -= (ord(s[r]) - ord('a') + 1)
        P %= MOD
        for i in range(27):
            if (P + MOD * i) % 27 == 0:
                P = (P + MOD * i) / 27
                break
        r -= 1
    m[P] = 1
print len(m)


Measured memory_bytes: 72952
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int& x:a)
    cin>>x;
  sort(a.begin(),a.end());
  long long answer=0;
  for(int i=0;i<n-k;++i)
    answer+=a[i];
  
  cout<<answer<<endl;
  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

ll f[N],inv[N];
ll comb(int n, int r) {
  ll num = f[n];
  ll den = inv[r] * inv[n-r] % mod;
  return (num * den) % mod;
}
ll numberOfPaths(int x, int y, int a, int b) {
  int n = a - x, m = b - y;
  return comb(n + m, n);
}
void solve() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  f[0] = 1;
  REP(i,1,N-1) {
    f[i] = f[i-1] * i % mod;
  }
  inv[N-1] = power(f[N-1],mod-2);
  REPN(i,N-2,0) {
    inv[i] = inv[i+1] * (i+1) % mod;
  }
  ll ans = 0;
  for(int x = h - a, y = b + 1; x > 0 && y <= w; x--, y++) {
    ll dis1 = numberOfPaths(1, 1, x, y);
    ll dis2 = numberOfPaths(x, y, h, w);
    ans = (ans + dis1 * dis2) % mod;
  }
  cout << ans;
}
int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 6748
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var ab = new Tuple<int, int, int>[n];
			for (int i = 0; i < n; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				ab[i] = new Tuple<int, int, int>(temp[0], temp[1], i);
			}

			var sorted = ab.OrderByDescending(x => x.Item1 + x.Item2).ToArray();
			long tsum = 0;
			long asum = 0;
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0) {
					tsum += sorted[i].Item1;
				} else {
					asum += sorted[i].Item2;
				}
			}

			long ans = tsum - asum;
			Console.WriteLine(ans);
		}
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, K;
  cin >> N >> K;

  llong ans = 0;
  llong mini = 0, maxi = 0;
  for (int i = 1; i <= N + 1; ++i) {
    mini += i - 1;
    maxi += N - i + 1;

    if (mini <= maxi && i >= K) {
      ans = (ans + (maxi - mini + 1)) % mod;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636