akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n;LL a[Maxn],Pow[20],f[Maxn],g[Maxn];
struct Seg{int l,r,lc,rc;LL sum;}tr[Maxn<<1];
int tot=0;
void up(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	tr[x].sum=tr[lc].sum+tr[rc].sum;
}
void build(int l,int r)
{
	int x=++tot;
	tr[x].l=l;tr[x].r=r;tr[x].sum=0;
	if(l==r)return;
	int mid=l+r>>1;
	tr[x].lc=tot+1,build(l,mid);
	tr[x].rc=tot+1,build(mid+1,r);
}
void modify(int x,int p,int v)
{
	if(tr[x].l==tr[x].r){tr[x].sum=v;return;}
	int lc=tr[x].lc,rc=tr[x].rc,mid=tr[x].l+tr[x].r>>1;
	if(p<=mid)modify(lc,p,v);
	else modify(rc,p,v);
	up(x);
}
int V;
int go(int x,int o)
{
	if(tr[x].l==tr[x].r){V=tr[x].sum;return tr[x].l;}
	int lc=tr[x].lc,rc=tr[x].rc;
	if(o==0)
	{
		if(tr[lc].sum)return go(lc,0);
		return go(rc,0);
	}
	else
	{
		if(tr[rc].sum)return go(rc,1);
		return go(lc,1);
	}
}
int w(int x,int y)
{
	if(x==y)return 0;
	if(x<y)
	{
		for(int i=1;i<=15;i++)
		if(x>y/Pow[i])return i-1;
	}
	if(x>y)
	{
		for(int i=1;i<=15;i++)
		if(y>=x/Pow[i])return i;
	}
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	build(1,n);modify(1,n,inf);
	Pow[0]=1;for(int i=1;i<=15;i++)Pow[i]=Pow[i-1]<<2;
	f[n]=0;
	for(int i=n-1;i;i--)
	{
		int t=w(a[i],a[i+1]);f[i]=f[i+1];
		if(a[i]<=a[i+1])modify(1,i,t);
		else
		{
			int lst=i;
			while(1)
			{
				int p=go(1,0);
				if(V>=t)
				{
					f[i]+=(LL)(p-lst)*t*2LL;
					if(V!=inf)modify(1,p,V-t);
					break;
				}
				else
				{
					f[i]+=(LL)(p-lst)*t*2LL;
					lst=p;t-=V;modify(1,p,0);
				}
			}
		}
	}
	tot=0;build(1,n);modify(1,1,inf);
	g[1]=0;
	for(int i=2;i<=n;i++)
	{
		int t=w(a[i],a[i-1]);g[i]=g[i-1];
		if(a[i]<=a[i-1])modify(1,i,t);
		else
		{
			int lst=i;
			while(1)
			{
				int p=go(1,1);
				if(V>=t)
				{
					g[i]+=(LL)(lst-p)*t*2LL;
					if(V!=inf)modify(1,p,V-t);
					break;
				}
				else
				{
					g[i]+=(LL)(lst-p)*t*2LL;
					lst=p;t-=V;modify(1,p,0);
				}
			}
		}
	}
//	for(int i=1;i<=n;i++)printf("%d ",f[i]);puts("");
	for(int i=1;i<=n;i++)g[i]+=i;
	LL ans=1LL<<60;g[0]=0;
	for(int i=1;i<=n;i++)ans=min(ans,g[i-1]+f[i]);
	printf("%lld",ans);
}

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

int main(){
  int N;
 cin >> N;
  
  vector <tuple<string,int,int>> p(N);
  string S;
  int P,num;
  for(int i=0;i<N;i++){
    cin >> S >> P;
    P *= -1;
    p.at(i) = make_tuple(S,P,i+1);
  }
  sort(p.begin(),p.end());
  
  for(int i=0;i<N;i++) {
    tie(ignore,ignore,num) = p.at(i);
    cout << num <<endl;
  }
  
}

Measured memory_bytes: 256
//36
#include<iostream>
#include<vector>

using namespace std;

vector<int> v;

bool dfs(int n,int *c){
  if(n==0){
    for(int i=v.size()-1;i>=0;i--){
      cout<<v[i]<<(i?' ':'\n');
    }
    return true;
  }else{
    for(int i=1;i<=13;i++){
      if(c[i]&&n%i==0){
	c[i]--;
	v.push_back(i);
	if(dfs(n-i,c))return true;
	v.pop_back();
	c[i]++;
      }
    }
    return false;
  }
}

int main(){
  for(int n;cin>>n,n;){
    int c[14]={};
    int s=0;
    for(int i=0;i<n;i++){
      int cc;
      cin>>cc;
      s+=cc;
      c[cc]++;
    }
    v.clear();
    if(!dfs(s,c)){
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main()
{
    getline(cin,s1);
    getline(cin,s2);
    cout<<s1[0];
    for(int i=0;i<s1.size()+s2.size()-1;i++)
    {   
        if(i%2==1)cout<<s1[i/2+1];
        else cout<<s2[i/2];
    }
return 0;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for i in range(3)]
print(['Yes', 'No'][any([c[i][j] - c[i+1][j] - c[i][j+1] + c[i+1][j+1] for i, j in [[0, 0], [0, 1], [1, 0], [1, 1]]])])

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

int main()
{
	int n = 0 , a = 0 , i = 0;
	cin >> n ;
	int day[n] ;
	for ( i = 0 ; i < n ; i++ )
	{
		cin >> a ;
		day[i] = a ;
	}
	for ( i = n-1 ; i > 0 ; i -- )
	{
		cout << day[i] <<" " ;
	}
	cout << day[0] << endl ;
	return 0;
}



Measured memory_bytes: 3096
k=int(input())

x=7
if k%2==0 or k%5==0:
    print(-1)
    exit()
for i in range(k):
    y=x%k
    
    if y==0:
        print(i+1)
        exit()
    x=10*y+7

    
        
    
      
    
    
        
        
    
    
    
    
        


Measured memory_bytes: 63016
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    //v[i][0] = x  v[i][1] = y
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1];
        a[i] = i;
    }

    double sum_dist = 0;
    while (true)
    {

        for (int i = 1; i < n; i++)
        {
            sum_dist += sqrt(pow(v[a[i]][0] - v[a[i - 1]][0], 2) + pow(v[a[i]][1] - v[a[i - 1]][1], 2));
        }

        if (!next_permutation(a.begin(), a.end()))
        {
            break;
        }
    }

    int k = 1;
    for (int i = 2; i <= n; i++)
    {
        k *= i;
    }
    double ave_dist = sum_dist / k;

    printf("%.10f\n", ave_dist);

    return 0;
}

Measured memory_bytes: 256
b = input()
templist = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
temp = 0
index = 0
for i in b:
    if i == "A" or i == "C" or i == "G" or i == "T":
        temp = temp + 1
        templist[index] = 1 + templist[index]
    else:
        temp = 0  
        index = index + 1

print(max(templist))

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int n;
cin>>n;
int a[n];
map<int,int>m;
int count=0;
rep(i,n){
  cin>>a[i];
         if(1<=a[i]&&a[i]<=399){m[1]++;}
  else if(400<=a[i]&&a[i]<=799){m[2]++;}
  else if(800<=a[i]&&a[i]<=1199){m[3]++;}
  else if(1200<=a[i]&&a[i]<=1599){m[4]++;}
  else if(1600<=a[i]&&a[i]<=1999){m[5]++;}
  else if(2000<=a[i]&&a[i]<=2399){m[6]++;}
  else if(2400<=a[i]&&a[i]<=2799){m[7]++;}
  else if(2800<=a[i]&&a[i]<=3199){m[8]++;}
  else
  {
    count++;
  }
  
}
int ans=0;
for(auto i:m){
  ans++;
}
if(ans==0){
cout<<1<<" ";
}else{
cout<<ans<<" ";
}
  
  
    cout<<ans+count<<endl;
  
  


  return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  int m = 1000, i_min;
  for (int i = 1; i <= N; i++) {
    if (abs(L + i - 1) < m) {
      i_min = i;
      m = abs(L + i - 1);
    }
  }
  cout << N*(L - 1) + N*(N + 1)/2 - (L + i_min - 1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,q,i,j,k,s[10005],t[505],cnt=0,key;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(j=0;j<q;j++) scanf("%d",&t[j]);

  for(i=0;i<q;i++){
    key=t[i];
    for(j=0;j<n;j++){
      if(key==s[j]){
        //printf("%d %d %d %d %d\n",key,t[j],cnt,i,j);
        cnt++;
        break;
      }
    }
  }
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<ctime>
#define ll long long
using namespace std;
const int maxn=300005,ha=998244353;
inline void add(int &x,int y){ x+=y; if(x>=ha) x-=ha;}
inline int ksm(int x,int y){
	int an=1;
	for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
	return an; 
}

int jc[maxn],ni[maxn];
int N,A,B,ans;
ll K;

inline int C(int x,int y){ return jc[x]*(ll)ni[y]%ha*(ll)ni[x-y]%ha;}

inline void init(){
	jc[0]=1;
    for(int i=1;i<=N;i++) jc[i]=jc[i-1]*(ll)i%ha;
    ni[N]=ksm(jc[N],ha-2);
    for(int i=N;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
}

inline void solve(){
	const int b=B,T=min((ll)N,K/A);
	
	for(int i=0;i<=T;i++){
		if((K-A*(ll)i)%b) continue;
		ll lef=(K-A*(ll)i)/b;
		if(lef>N) continue;
		
		add(ans,C(N,i)*(ll)C(N,lef)%ha);
	}
}

int main(){
	scanf("%d%d%d%lld",&N,&A,&B,&K);
	
	init(),solve();
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
const int MaxN=100010,mod=1000000007;
int N,A[MaxN],fac[MaxN],f[MaxN];
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",A+i);
	for(int i=*fac=1;i<=N;i++)fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=1;i<=N;i++)f[i]=(f[i-1]+inv(i+1))%mod; 
	int s=0;
	for(int i=0;i<N;i++){
		s=(s+1ll*A[i]*(1+f[i]+f[N-i-1]))%mod;
	}
	s=1ll*s*fac[N]%mod;
	printf("%d\n",s);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, cur = 0, a, b, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		if (a == b) cur++;
		else cur = 0;
		ans = max(ans, cur);
	}
	if (ans >= 3) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
double L;
double ma=0;
bool C(double x){
	if(x*(L-x)/2*(L-x)/2>ma){
		ma=x*(L-x)/2*(L-x)/2;
		return true;
	}
	return false;
}
double binarys(){
	double mid=L/2,l=0,r=L;
	ma=pow(L/3,3);
	for(int i=0;i<100;i++)
	{
		//cout<<mid<<" "<<l<<" "<<r<<endl;
		if(C(mid)){
			l=mid;
			mid=(l+r)/2;
		}
		else{
			r=mid;
			mid=(l+r)/2;
		}
	}
	return ma;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>L;
	double ans=binarys();
	printf("%.8f",ans);
	return 0;
}

Measured memory_bytes: 256
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
c = dict()
a = []
for p in ps:
    if p in c:
        a.append(c[p])
        continue
    p = [ord(c) for c in p]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(19, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))

Measured memory_bytes: 1081060
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
    elif op == '?':
        break



Measured memory_bytes: 5592
N, M = map(int, input().split())
A = []
for _ in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x:x[0])

money = 0
for i in range(N):
    if A[i][1] > M:
        money += M * A[i][0]
        break
    money += A[i][0] * A[i][1]
    M -= A[i][1]
print(money)

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

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

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define rrep(i, b, a) for(int i = b; i >= a; --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

const int N = 2e5+1;
int n, m;
int a[N];
int b[N];
int main() {
  cin.tie(0); cin.exceptions(cin.failbit);
  scanf("%d", &n);

  rep(i, 1, n+1) scanf("%d", a+i);

  rrep(i, n, 1){
    int balls = 0;
    for(int j = 2; j*i <= n; j++){
      balls += b[i*j];
    }
    if(balls%2 != a[i]){
      b[i] = 1;
      m++;
    }
  }

  printf("%d\n", m);

  rep(i, 1, n+1) if(b[i]) printf("%d ", i);
  puts("");
}


Measured memory_bytes: 2432
class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


import sys

readline = sys.stdin.buffer.readline

N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, readline().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[n-1]<< endl;
    return 0;
}


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

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

	for (int i = 0; i < S.size(); i++) {
		for (int j = i; j < S.size(); j++) {
			if (S[i] == 'C'&&S[j] == 'F') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

#define For(i, n) for(int i = 0; i < n; i++)

#define Tcmp(X, Y) (abs(aryvec[i]->x) == X && abs(aryvec[i]->y) == Y)

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
};

int main(){

	int x[5];

	input(x, 5);

	int time = 0;
	int maxloss = 0;

	For(i, 5){
		time += (x[i] % 10 == 0) ? x[i] : ((x[i] / 10 + 1) * 10);
		if(x[i] % 10 && (x[i] / 10  + 1) * 10 - x[i] > maxloss){
			maxloss = (x[i] / 10 + 1) * 10 - x[i];
		}
	}

	time -= maxloss;

	out(time);
	
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100001]={0};
int b[100001]={0};
int main()
{
	int n,t;
	cin>>n>>t;
	for (int i=1;i<=n;++i)
	    cin>>a[i];
	b[n]=a[n];
	int max=0;
	for (int i=n-1;i>0;--i)
	{
	    if (a[i]>b[i+1]) b[i]=a[i];
	        else b[i]=b[i+1];
	    if (b[i]-a[i]>max) max=b[i]-a[i];
	}
	int ans=0;
	for (int i=1;i<=n;++i)
	    if (b[i]-a[i]==max) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
card = []
for i in range(0, 3):
    a = map(int, input().split())
    card.append(list(a))

n = int(input())
done = []
for j in range(0, n):
    b = int(input())
    done.append(b)

flag = []
for k in range(0, 3):
    for l in range(0, 3):
        for m in range(0, n):
            if done[m] == card[k][l]:
                num = k*3+l
                flag.append(num)

def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr


a=len(intersect_list(flag, [0, 1, 2]))
b=len(intersect_list(flag, [3, 4, 5]))
c=len(intersect_list(flag, [6, 7, 8]))
d=len(intersect_list(flag, [0, 3, 6]))
e=len(intersect_list(flag, [1, 4, 7]))
f=len(intersect_list(flag, [2, 5, 8]))
g=len(intersect_list(flag, [0, 4, 8]))
h=len(intersect_list(flag, [2, 4, 6]))

if a >= 3:
    print("Yes")
elif b >= 3:
    print("Yes")
elif c >= 3:
    print("Yes")
elif d >= 3:
    print("Yes")
elif e >= 3:
    print("Yes")
elif f >= 3:
    print("Yes")
elif g >= 3:
    print("Yes")
elif h >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#A
K = int(input())
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[K-1])

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, b, c = 0, d = 0;
		N = sc.nextInt();
		Integer[] a = new Integer[N];
		for (int i = 0; i < N; i++) {
			b = sc.nextInt();
			a[i] = b;
		}
		Arrays.sort(a, Collections.reverseOrder());
		for (int i = 0; i < N; i++) {
			c += a[i];
			i++;
			if(i<N) {
			d += a[i];
			}
		}
		System.out.println(c - d);
		sc.close();
	}

}

Measured memory_bytes: 21844
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])

let count = 0

const ans = () => {
  dfs(0)

  console.log(count)
}

const dfs = val => {
  const strVal = String(val)

  if (val > n) {
    return
  }

  if (strVal.indexOf('3') >= 0 && strVal.indexOf('5') >= 0 && strVal.indexOf('7') >= 0) {
    count++
  }

  dfs(10 * val + 3)
  dfs(10 * val + 5)
  dfs(10 * val + 7)
}

ans()


Measured memory_bytes: 12096
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
   ll d,t,s;
  cin>>d>>t>>s;
  t*=s;
  if(t>=d)cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 3592
//ABC137C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin >> s.at(i);
		sort(s.at(i).begin(),s.at(i).end());
	}
	sort(s.begin(),s.end());
	vector<long long int> count(n);
	long long int ans = 0;
	for(int i=0;i<n;i++){
		count.at(i) = 1;
	}
	int j = 0;
	for(int i=0;i<n-1;i++){
		if(s.at(i) == s.at(i+1)){
			count.at(j)++;
		}else{
			j++;
		}
	}
	for(int i=0;i<n;i++){
		ans += count.at(i)*(count.at(i)-1)/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
const int N = 3e5 + 10;
const ll mod = 1e9 + 7;
ll a[N];
signed main(){
    int n;
    ll x;
    si(n);
    sl(x);
    ll res=0;
    rep(i,1,n){
        sl(a[i]);
        if(a[i]+a[i-1]>x){
            ll tmp=a[i]+a[i-1]-x;
            res+=tmp;
            a[i]-=tmp;
        }
    }
    pl(res);
   return 0;
}

Measured memory_bytes: 4572
#include <bits/stdc++.h>
using namespace std;
# define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,K;
	cin>>N>>K;
	vector<ll> P(N);
    rep(i,N){
        cin>>P[i];
    }
    ll ans_ll = 0;
    ll sum = 0;
    rep(i,K){
        sum+=P[i];
    }
    ans_ll = max(ans_ll,sum);
    rep(i,N-K){
        sum-=P[i];
        sum+=P[K+i];
        ans_ll = max(ans_ll,sum);
    }

    // double ans = double(ans_ll+K)/2.0;
    if((ans_ll+K)%2==0){
        cout<<(ans_ll+K)/2<<"\n";
    }else{
        cout<<(ans_ll+K)/2<<".5"<<"\n";
    }
    // cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  vector<int>buttons(n);
  for(int i=0;i<n;i++){
  	cin>>buttons[i];
  }
  int tot=0,pos=0,rot=0;
  while(buttons[pos]!=2){
  	pos=buttons[pos]-1;
  	rot++;
  	if(rot>101010){
  		cout<<-1<<endl;
  		return 0;
  	}
  }
  cout<<rot+1<<endl;
} 







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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

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

    if(a == b) cout << "Draw" << endl;
    else if(a == 1) cout << "Alice" << endl;
    else if(b == 1) cout << "Bob" << endl;
    else if(a < b) cout << "Bob" << endl;
    else cout << "Alice" << endl;

    return 0;
}

Measured memory_bytes: 256
/*
 * Ref http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
 * 3.3 満点解法
 *
 * DP
 */
#include <cstdio>
#include <iostream>

typedef long long ll;
using namespace std;

ll x[51];

// dp_j[t] : possible #of sum = t - n*X using card y[i] (0<=i<=j) where y[i] := x[i] - a
ll dp[2][2*51*51];

int main(){
    //freopen("c4.in", "r", stdin);
    ll n, a;
    ll X = 0;  // Maximum absolute value of y[i], up to 50

    cin >> n >> a;

    for (ll i = 0; i < n; ++i) {
        cin >> x[i];
        x[i] -= a;
        X = max(X, abs(x[i]));
    }

    // Init
    dp[0][n*X] = 1LL;
    for (int j = 0; j < n; ++j) {
        for (int t = 2*n*X; t >= 0; --t) {
            ll prevt = t-x[j];
            if (0 <= prevt && prevt <= 2*n*X) {
                dp[1][t] = dp[0][t] + dp[0][prevt];
            }
        }
        swap(dp[0], dp[1]);
    }

    cout << dp[0][n*X] - 1 << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main() {
    int K, S;
    cin >> K >> S;

    int ct = 0;

    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            int dist = S - (i + j);
            if (K >= dist && dist >= 0) ct++;
        }
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	v := make([]float64, n)
	for i := 0; i < n; i++ {
		v[i], _ = strconv.ParseFloat(input(), 64)
	}
	sort.Float64s(v)

	ans := v[0]
	for i := 1; i < n; i++ {
		ans = (ans + v[i]) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));
  $sum = 0;
  $count = [];
  for ($i=0; $i<$n; $i++) {
    if(!isset($count[$a[$i]])) $count[$a[$i]] = 0; 
    $count[$a[$i]]++;
    $sum += $a[$i];
  }
  $sum = array_sum($a);

  list($q) = explode(" ", trim(fgets(STDIN)));
  for ($i=0; $i<$q; $i++) {
    list($b, $c) = array_map('intval', explode(" ", trim(fgets(STDIN))));
    $count_b = 0;
    if(isset($count[$b])) {
      $count_b = $count[$b];
      if(!isset($count[$c])) $count[$c] = 0;
      $count[$c] += $count_b;
      $count[$b] = 0;
      $sum += ($c - $b) * $count_b;
    }
    echo $sum.PHP_EOL;
  }


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


void solve(std::string S){
    for (auto &c :S){
        c = 'x';
    }
    cout << S <<endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;


int main(){
//    cout << fixed << setprecision(10);
    
    long long N;
    cin >> N;
    map<int, int> m;
    long long result = 0;
    vector<int> A = vector<int>(N, 0);
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        m[A[i]]++;
    }
    
    for (auto i = m.begin(); i != m.end() ; ++i) {
        long long x = i->second;
        result += x * (x - 1) / 2;
    }
    
    for (int i = 0; i < N; i++) {
        cout << result - (m[A[i]] - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 9600
x,n= map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    p.sort()
    i=0
    while p[i]<x:
        i+=1
    if p[i]!=x:
        print(x)
    else:
        l=x-1
        h=x+1
        j=i-1
        k=i+1
        while  j>=0 and l==p[j]:
            j-=1
            l-=1
        if j==-1:
            l=p[0]-1
        while k<n and h==p[k] :
            k+=1
            h+=1
        if k==-1:
            h=p[k]-1
        if x-l<=h-x:
            print(l)
        else:
            print(h)
else:
    print(x)


Measured memory_bytes: 61960
using System;
using System.Linq;

namespace ABC157
{
    class B
    {
        static void Main(string[] args)
        {
            int[,] A = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < 3; j++)
                {
                    A[i, j] = input[j];
                }
            }

            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                int b = int.Parse(Console.ReadLine());

                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (A[j, k] == b) A[j, k] = 0;
                    }
                }
            }

            // yoko
            if (A[0, 0] == 0 && A[0, 1] == 0 && A[0, 2] == 0) { Console.WriteLine("Yes"); return; }
            if (A[1, 0] == 0 && A[1, 1] == 0 && A[1, 2] == 0) { Console.WriteLine("Yes"); return; }
            if (A[2, 0] == 0 && A[2, 1] == 0 && A[2, 2] == 0) { Console.WriteLine("Yes"); return; }

            // tate
            if (A[0, 0] == 0 && A[1, 0] == 0 && A[2, 0] == 0) { Console.WriteLine("Yes"); return; }
            if (A[0, 1] == 0 && A[1, 1] == 0 && A[2, 1] == 0) { Console.WriteLine("Yes"); return; }
            if (A[0, 2] == 0 && A[1, 2] == 0 && A[2, 2] == 0) { Console.WriteLine("Yes"); return; }

            // naname
            if (A[0, 0] == 0 && A[1, 1] == 0 && A[2, 2] == 0) { Console.WriteLine("Yes"); return; }
            if (A[0, 2] == 0 && A[1, 1] == 0 && A[2, 0] == 0) { Console.WriteLine("Yes"); return; }

            Console.WriteLine("No");

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin >> n;
  vector<int> v(n),c(n);
  for (int i=0;i<n;i++){
    cin >> v[i+1];
  }
  for (int i=0;i<n;i++){
    cin >> c[i+1];
    if (v[i+1]-c[i+1] > 0){
      ans+=v[i+1]-c[i+1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3548
/*
       ()       ()()()()     ()        ()       ()        ()        ()
      ()()      ()     ()    ()()      ()      ()()       ()()      ()
     ()  ()     ()      ()   ()  ()    ()     ()  ()      ()  ()    ()
    ()()()()    ()      ()   ()    ()  ()    ()()()()     ()    ()  ()
   ()      ()   ()     ()    ()      ()()   ()      ()    ()      ()()
  ()        ()  ()()()()     ()        ()  ()        ()   ()        ()

*/
#include <bits/stdc++.h>
#define MOD  (int)(1e9+7)
#define SIZE (int)(1e5+5)
#define all(x) x.begin(),x.end()
#define si(i)  scanf("%d",&i)
#define sf(f)  scanf("%f",&f)
#define pi(i)  printf("%d",i)
#define pd(d)  printf("%lf",d)
#define deb(x) cout<<#x<<" is "<<x<<"\n";
#define lb     lower_bound
#define ub     upper_bound
#define pb     push_back
#define prDouble(x) cout<<fixed<<setprecision(10)<<x;
#define IOfast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int64_t exponentiation(int64_t base,int exp)
{
    if (exp == 0)
        return 1;

    if (exp == 1)
        return base;

    int64_t t = exponentiation(base, exp / 2);

    t = (t * t);

    if (exp % 2 == 0)
        return t;
    else
        return base * t;
}
int dp[2][SIZE];

int solve(vector<int>& arr,int player,int value)
{   
  if(value < arr[0]){
    //cout<<"for value: "<<value;
    //if(player^1 ) cout<<" :second "; else cout<<"first ";
    return player^1;
  }

  if(dp[player][value]!=-1)
    return dp[player][value];
  
  int i=0;

  while(i!=arr.size())
  {
    if(arr[i]>value)
      break;
    if(player == solve(arr,player^1,value-arr[i])){
      dp[player][value] = player;     
      return player;
    }
    i++;  
  }

  dp[player][value] = player^1;
  return player^1;  
}


int main()
{
  IOfast;
 
  int q=1;
  //cin>>q;
  memset(dp,-1,sizeof(dp));
  while(q--)
  {
    int n,k;
    cin>>n>>k;
    vector<int> arr(n);
    for(auto &item:arr) cin>>item;

    int ans = solve(arr,0,k); //taro started this game ;  
    if(ans)
      cout<<"Second";
    else
      cout<<"First";
  }
  
  return 0;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    
    string field[105][105];
    bool width[W], height[H];
    memset( height, true, H );
    memset( width, false, W );
    
    for ( int i = 0; i < H; i++ ) {
        string s; cin >> s;
        int cnt = 0;
        for ( int j = 0; j < W; j++) {
            if ( s[j]=='#' ) {
                width[j] = true;
                cnt++;
            }
            field[i][j] = s[j];
        }
        if (cnt==0) height[i]=false;
    }
    
    for ( int i = 0; i < H; i++ ) {
        if (height[i]==false) continue;
        for ( int j = 0; j < W; j++) {
            if (width[j]==false) continue;
            cout << field[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

ll COM(int a, int b) {
  ll ret = 1;
  for (int i = a; i >= a - b + 1; --i) {
    (ret *= i) %= mod;
  }
  rep3(i, 1, b + 1) {
    (ret *= modpow(i, mod - 2)) %= mod;
  }
  return ret;
}
void solve() {
  int n, a, b;
  cin >> n >> a >> b;
  ll ans = modpow(2, n);
  
  (ans += mod - COM(n, a)) %= mod;
  (ans += mod - COM(n, b)) %= mod;
  (ans += mod - 1) %= mod; // 0 本はなし
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>

using std::map;
typedef map<int,int>::iterator miter;
const int N = 100010;
int _w;

int n, c, k, t[N];
map<int,int> ins;
int q[N], begin, end;

int main() {
	_w = scanf( "%d%d%d", &n, &c, &k );
	for( int i = 1; i <= n; ++i ) {
		_w = scanf( "%d", t+i );
		++ins[t[i]];
		ins[t[i]+k] += 0;
	}
	int ans = 0;
	for( miter it = ins.begin(); it != ins.end(); ++it ) {
		while( it->second-- ) q[end++] = it->first;
		while( begin != end && it->first == q[begin] + k ) {
			++ans;
			for( int i = 0; i < c && begin != end; ++i, ++begin );
		}
	}
	printf( "%d\n", ans );
	return 0;
}



Measured memory_bytes: 10368
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct Input
{
    uint64_t a;
    uint64_t b;
};

static Input read_input()
{
    Input input{};
    cin >> input.a >> input.b;
    return input;
}

static bool is_common_divisor(const Input& input, int n)
{
    return (input.a % n) == 0 && (input.b % n) == 0;
}

static vector<uint64_t> solve_brute_force(const Input& input)
{
    vector<uint64_t> divisors;
    divisors.push_back(1);

    const auto smaller = std::min(input.a, input.b);
    for (auto n = 2; n <= smaller; ++n) {
        if (!is_common_divisor(input, n)) continue;

        bool found = false;
        for (auto it = divisors.begin() + 1; it != end(divisors); ++it) {
            if ((n % *it) == 0) {
                found = true;
                break;
            }
        }
        if (found) continue;

        divisors.push_back(n);
    }

    return divisors;
}

static uint64_t calc_gcd(uint64_t a, uint64_t b)
{
    while (b > 0) {
        const auto next_b = a % b;
        a = b;
        b = next_b;
    }
    return a;
}

static vector<uint64_t> solve_gcd(const Input& input)
{
    auto gcd = calc_gcd(input.a, input.b);
    vector<uint64_t> divisors;
    divisors.push_back(1);
    for (uint64_t i = 2; i*i < gcd; ++i) {
        if ((gcd % i) != 0) continue;
        while ((gcd % i) == 0) {
            gcd /= i;
        }
        divisors.push_back(i);
    }
    if (gcd > 1) {
        divisors.push_back(gcd);
    }

    return divisors;
}

static void solve(const Input& input)
{
    const auto divisors = solve_gcd(input);
    cout << divisors.size() << endl;
}

static void setup()
{
}

int main(int argc, char** argv)
{
    setup();

    const auto input = read_input();
    solve(input);

    return 0;
}


Measured memory_bytes: 768
/*
 * $File: p1000.cpp
 * $Author: Wayne <tletletle@163.com>
 *
 * Task:
 *   Compute A + B.
 * 
 * Solution:
 *   Straight forward.
 *   Remember to process to EOF.
*/

#include <cstdio>

int main() {
	for (int a, b; scanf("%d%d", &a, &b) != EOF; )
		printf("%d\n", a + b);
	return 0;
}

Measured memory_bytes: 1028
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Ms = [input().split() for _ in range(M)]


ans = min(As) + min(Bs)
for m in Ms:
  a = int(m[0])-1
  b = int(m[1])-1
  rate = int(m[2])
  price = int(As[a])+int(Bs[b])-rate
  if price < ans:
    ans = price
print(ans)
  

Measured memory_bytes: 45740
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

import functools

def solve():
    n = input()
    nums = map(int, input().split())
    print(functools.reduce(lcm, nums))

solve()

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

const int Maxn = 100005;

int n, L;
int a[Maxn];

int main()
{
    scanf("%d %d", &n, &L);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i + 1 <= n; i++) if (a[i] + a[i + 1] >= L) {
        printf("Possible\n");
        for (int j = 1; j < i; j++)
            printf("%d\n", j);
        for (int j = n - 1; j > i; j--)
            printf("%d\n", j);
        printf("%d\n", i);
        return 0;
    }
    printf("Impossible\n");
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  static const int MAX = 200020;
  int N, as[200020], memo[200020];
  ll K;

  void init() {
    cin >> N >> K;
    rep(i, N) {
      cin >> as[i];
      as[i]--;
      memo[i] = -1;
    }
  }

  void solve() {
    memo[0] = 0;
    int p = -1, q = -1, past = 0;
    while(1) {
      if(memo[as[past]] >= 0) {
        p = as[past];
        q = memo[past] + 1 - memo[p];
        break;
      } else {
        memo[as[past]] = memo[past] + 1;
        past = as[past];
      }
    }
    if(K<memo[p]) {
      ll move = K;
      ll ans = 0;
      while(move > 0) {
        ans = as[ans];
        move--;
      }
      cout << ans+1 << "\n";
    } else {
      ll move = (K-memo[p]) % q;
      ll ans = p;
      while(move > 0) {
        ans = as[ans];
        move--;
      }
      cout << ans+1 << "\n";
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	ll ans=999999999999;
	for(int i=1;i<=sqrt(n);i++)
	{
		if((n%i) == 0)
		{
			ans=min(ans, i+(n/i)-2);
		}
	}
	cout<<ans<<"\n";
}


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

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

double EPS=1e-9; 
int INF=1000000005; 
long long INFF=1000000000000000005ll; 
double PI=acos(-1); 
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; 
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; 
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n") 
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
#define OUT(x) cout << x << endl 
#define debug(...) fprintf(stderr, __VA_ARGS__) 
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a)) 
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) 
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) 
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) 
#define EACH(a, b) for (auto&(a) : (b)) 
#define REP(i, n) FOR(i, 0, n) 
#define REPN(i, n) FORN(i, 1, n) 
#define MAX(a, b) a=max(a, b) 
#define MIN(a, b) a=min(a, b) 
#define SQR(x) ((ll)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define TC(t) while (t--) 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

ll dp[3050][3050][5];
ll val[3050][3050];

int main()  
{ 
    FAST_INP;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
    #endif
    
    // int tc; cin >> tc;
    // TC(tc) solve();
    ll r, c, k;
    cin >> r >> c >> k;
    vl col(k), row(k), v(k);
    REP(i, k) cin >> col[i] >> row[i] >> v[i];
    REP(i, k) col[i]--, row[i]--;
    REP(i, k) val[col[i]][row[i]] += v[i];

    if (val[0][0] > 0) dp[0][0][1] += val[0][0];
    REP(x, r) REP(y, c) REP(z, 4) {
        if (z == 3) {
            MAX(dp[x][y + 1][z], dp[x][y][z]);
            MAX(dp[x + 1][y][1], dp[x][y][z] + val[x + 1][y]); 
            MAX(dp[x + 1][y][0], dp[x][y][z]);
        } else {
            MAX(dp[x][y + 1][z + 1], dp[x][y][z] + val[x][y + 1]);
            MAX(dp[x][y + 1][z], dp[x][y][z]);
            MAX(dp[x + 1][y][1], dp[x][y][z] + val[x + 1][y]); 
            MAX(dp[x + 1][y][0], dp[x][y][z]);
        }
    }
    r--, c--;
    OUT(max({dp[r][c][3], dp[r][c][2], dp[r][c][1], dp[r][c][0]}));
    return 0; 
} 

Measured memory_bytes: 436880
<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $inputs[] = explode(' ', trim(fgets(STDIN)));
}

#var_dump([$n, $m, $inputs]);

$r = ['AC' => 0, 'WA' => 0];

$tmp = [];
foreach ($inputs as $input) {
    $qid = $input[0];
    $ans = $input[1];

    if (!isset($tmp[$qid])) {
        $tmp[$qid] = ['AC' => 0, 'WA' => 0];
    }

    if ($tmp[$qid]['AC'] >= 1) {
        continue;
    }

    $tmp[$qid][$ans]++;
}

foreach ($tmp as $x) {
    if ($x['AC'] > 0) {
        $r['AC'] += $x['AC'];
        $r['WA'] += $x['WA'];
    }
}


echo $r['AC'] . " " . $r['WA'];


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

long long f(vector<long long> m,vector<long long> c,int n,int w,vector<long long> &dp)
{
    long long mx=0;
    for (int i=1;i<=n;i++)
        for (int j=w;j>=0;j--)
            if(m[i-1]<=j)
                dp[j]=max(dp[j],dp[j-m[i-1]]+c[i-1]);
    mx=*max_element(dp.begin(),dp.end());
    return mx;
}
int main()
{
    int n,w;
    cin >> n >> w;
    vector<long long> m(n);
    vector<long long> c(n);
    vector<long long> dp(w+1,0);
    for (int i=0;i<n;i++)
        cin >> m[i] >> c[i];
    cout << f(m,c,n,w,dp) << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define endl "\n"
using namespace std;
using ll = long long;
using bnum = int64_t;
ll pi= static_cast<ll>(3.1415926535897932384626433l);

int main(){
  int a,b;
  cin >> a >> b;
  a==b? cout << "Yes" << endl : cout << "No" << endl;
}


Measured memory_bytes: 3568
#include <stdio.h>

int main(void) {
	int N, K;
	scanf("%d%d", &N, &K);

	int i, j, cnt = 0, memo = 0;
	double ans1 = 1.0, ans2 = 0;
		for (i = 1; i <= N; i++) {
			cnt = 0;
			memo = i;
			ans1 = 1.0;
			for (j = 1; memo < K; j++) {
				memo *= 2;
				cnt++;
			}
			for (j = 0; j < cnt; j++) {
				ans1 *= 0.5;
			}
			ans2 += ans1 * (1.0 / N);
		}
	printf("%.12lf\n", ans2);


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool ans=false;
    for(int i=1;i<s.size();i++)
        if(s[i]==s[i-1])
            ans=true;
    if(ans)
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define fr first
#define se second
const ll mod = 1e9+7;

void solve(ll cas){
    ll n;cin>>n;
    ll ans=0;
    for(ll a=1;a<n;a++){
        ans+=n/a;
        if(n%a==0) ans--;
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll qu=1;
    // cin>>qu;
    for(ll cas=1;cas<=qu;cas++){
        solve(cas);
    }
}


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

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

void solve() {
    int A, B; cin >> A >> B;
    int ans = A - 2 * B;
    if(ans < 0) cout << 0 << "\n"; else cout << ans << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.*; 
public class Main {

  public static void main(String[] args) {
  
  Scanner sc=new Scanner(System.in);
  String s=sc.next();
  String t=sc.next();
  int l=s.length();
  char x;
  int ind;
  boolean ans=true;
  char a[]=new char[27];
  char b[]=new char[27];
  for(int i=0;i<l;i++){
     x=s.charAt(i);
     ind=x-'a';
    if(a[ind]==0){
      a[ind]=t.charAt(i);
      
      if(b[(int)(t.charAt(i)-'a')]==1){
        ans=false;
        break;
      }
      b[(int)(t.charAt(i)-'a')]=1;
    }else if(t.charAt(i)!=a[ind]){
      ans=false;
    }
    
  }
  
  
  System.out.println(ans?"Yes":"No");
  
  }
  
}

Measured memory_bytes: 26556
B=[]
for _ in range(3):B+=list(map(int,input().split()))
S=set(int(input()) for _ in range(int(input())))
for i,b in enumerate(B):
    if b in S:B[i]=0
if B[0]+B[1]+B[2]==0 or B[3]+B[4]+B[5]==0 or B[6]+B[7]+B[8]==0 or B[0]+B[3]+B[6]==0 or B[1]+B[4]+B[7]==0 or B[2]+B[5]+B[8]==0 or B[0]+B[4]+B[8]==0 or B[2]+B[4]+B[6]==0:
    print('Yes')
else:print('No')

Measured memory_bytes: 3064