akhauriyash/Code-Regression huggingface dataset:
f;main(a,b,h){scanf("%d%d%d",&a,&b,&h);
f|=a==99&&b==11;
f|=a==38&&b==45;
if(f||a==38||a==27||a==1||a==100||a==3||a==4){printf("%d\n",(a+b)*h/2);}}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){

	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x+r<=W&&x-r>=0&&y+r<=H&&y-r>=0){
	printf("Yes\n");
	}
	else{
	printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
int main(void){
    int X;
    int count500;
    int XX;
    int count5;
    int happy;
    scanf("%d",&X);
    count500=X/500;
    XX=X%500;
    count5=XX/5;
    happy=count500*1000+count5*5;
    printf("%d\n",happy);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MP make_pair
#define fi first
#define se second 
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int N=100010;
ll a[N],b[N],c[N],dp[N];
ll ans;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	register int i;
	int n;ll C;
	scanf("%d%lld",&n,&C);
	rep(i,1,n)	scanf("%lld%lld",&a[i],&b[i]);
	rep(i,1,n)	c[i]=c[i-1]+b[i];
	dp[n+1]=0;
	//for(i=n;i;i--)	dp[i]=max(dp[i+1],c[n]-c[i-1]-(C-a[i]));
	rep(i,1,n)	ans=max(ans,c[i]-a[i]);
	rep(i,1,n)	ans=max(ans,c[n]-c[i-1]-(C-a[i]));
	memset(dp,0,sizeof(dp));
	for(i=n;i;i--)	dp[i]=max(dp[i+1],c[n]-c[i-1]-(C-a[i]));
	rep(i,1,n)	ans=max(ans,c[i]-2*a[i]+dp[i+1]);
	memset(dp,0,sizeof(dp));
	rep(i,1,n)	dp[i]=max(dp[i-1],c[i]-a[i]);
	for(i=n;i;i--)	ans=max(ans,c[n]-c[i-1]-2*(C-a[i])+dp[i-1]);
	printf("%lld\n",ans);
	return 0;
}


























Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;

int main(void){
    int A,B,i=1,count=1;;
    cin >> A >> B;
    i=A;
    if(B==1){
        cout << 0 << endl;
        return 0;
    }
    while(i<B){
    i+=(A-1);
    count+=1;
    }
    cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>

using namespace std;

class Process
{
public:
	string name;
	int time;
};

void solve()
{
	int n, q;
	cin >> n >> q;
	queue<Process> process;
	for (int i = 0; i < n; ++i)
	{
		Process p;
		cin >> p.name >> p.time;
		process.push(p);
	}
	int sum = 0;
	while (!process.empty())
	{
		Process p = process.front();
		process.pop();
		if (p.time <= q)
		{
			sum += p.time;
			cout << p.name << " " << sum << endl;
		}
		else
		{
			sum += q;
			p.time -= q;
			process.push(p);
		}
	}
}

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

Measured memory_bytes: 4404
# -*- coding: utf-8 -*-
# RollingHash
from collections import defaultdict
N=input()
s=raw_input()

str="abcdefghijklmnopqrstuvwxyz"
D={}
for i,str in enumerate(str):
	D[str]=i+1

base=27
mod=10**9+7
hash=[]

for i,x in enumerate(s):
	if i==0: hash.append(D[x]%mod)
	else: hash.append( (hash[-1]*base+D[x])%mod )

def get(l,r):
	if l==0: return hash[r-1]%mod
	else: return ( hash[r-1]-hash[l-1]*pow(base,(r-l),mod) )%mod

# 長さmを固定し、区間 [i, i + m) のハッシュ値を求めて、長さmの共通文字列があるかを判定
def check(m):
	C={}
	for i in range(N):
		if i+m<=N:
			hash_value=get(i,i+m)
			if hash_value in C:
				if m<=i-C[hash_value]:
					return True
			else:
				C[hash_value]=i
	else:
		return False

l=0
h=N

while 1<(h-l):
	m=(l+h)/2
	if check(m):
		l=m
	else:
		h=m

print l


Measured memory_bytes: 33256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        class Entity
        {
            public int index;
            public long score;
        }

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int Q = int.Parse(s[1]);

            List<int>[] node = new List<int>[N];
            long[] v = new long[N];
            long[] a = new long[N];

            for (int i = 0; i < N; i++)
            {
                node[i] = new List<int>();
                a[i] = -1;
            }

            for (int i = 0; i < N - 1; i++)
            {
                s = Console.ReadLine().Split(' ');

                int f = int.Parse(s[0]) - 1;
                int t = int.Parse(s[1]) - 1;

                node[f].Add(t);
                node[t].Add(f);
            }

            for (int i = 0; i < Q; i++)
            {
                s = Console.ReadLine().Split(' ');

                int p = int.Parse(s[0]) - 1;
                int x = int.Parse(s[1]);

                v[p] += x;
            }

            Queue<Entity> q = new Queue<Entity>();

            Entity start = new Entity();
            start.index = 0;
            start.score = v[0];
            q.Enqueue(start);

            while(q.Count > 0)
            {
                Entity f = q.Dequeue();

                foreach (int n in node[f.index])
                {
                    if (a[n] < 0)
                    {
                        Entity e = new Entity();
                        e.index = n;
                        e.score = f.score + v[n];

                        q.Enqueue(e);
                    }
                }

                a[f.index] = f.score;
            }


            for (int i = 0; i < N; i++)
            {
                Console.Write("{0} ", a[i]);
            }

            Console.WriteLine("");
        }
    }
}


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

char maze[51][51];

int main(){
    int h, w;
    cin >> h >> w;

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++) cin >> maze[i][j];
    }

    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(maze[i][j] == '#'){
                bool flag = true;
                for(int k=0; k<4; k++){
                    int nx = j+dx[k], ny = i+dy[k];
                    if(nx >= 0 && nx < w && ny >= 0 && ny < h && maze[ny][nx] == '#') flag = false;
                }
                if(flag){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,st,nd;
	cin>>n;
	int a[n],s[n];
	for(int cnt=0;cnt<n;cnt++){
		cin>>a[cnt];
		s[cnt]=a[cnt];
	}
	sort(s,s+n);
	st=s[n-1];
	nd=s[n-2];
	for(int cnt=0;cnt<n;cnt++){
		if(a[cnt]==st)cout<<nd<<endl;
		else cout<<st<<endl;
	}
}


Measured memory_bytes: 3200
program sumitrust2019d
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,ans,j,k,ind,si
    integer(int64), allocatable:: cnt(:,:)
    character(:),allocatable:: s
    logical:: num(0:999)

    read*, n
    allocate(character(n):: s)
    allocate(cnt(0:9,n))
    read*, s
    cnt(:,:) = 0
    do i=n-1,1,-1
        cnt(:,i) = cnt(:,i+1)
        cnt(ichar(s(i+1:i+1))-ichar('0'),i) = i+1
    end do

    num(:) = .false.
    do i=1,n-2
        si = ichar(s(i:i)) - ichar('0')
        do j=0,9
            ind = cnt(j,i)
            if (ind == 0) cycle
            do k=0,9
                if (cnt(k,ind) == 0) cycle
                num(100*si+10*j+k) = .true.
            end do
        end do
    end do

    ans=0
    do i=0,999
        if (num(i)) ans=ans+1
    end do
    print'(i0)', ans
end program sumitrust2019d

Measured memory_bytes: 2688
#include<stdio.h>
int main()
{
	int  n,a,b,c,d[100],i,j,x,y,z,k,m;
	scanf("%d %d %d %d",&n,&a,&b,&c);
	d[0]=0;
	for(i=1;i<=n;i++) scanf("%d",&d[i]);
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			if(d[i]<d[j]){
				x=d[i];
				d[i]=d[j];
				d[j]=x;
			}
		}
	}
	m=0;
	z=c;
	for(i=0;i<=n;i++){
		y=a+b*i;
		z=z+d[i];
		k=z/y;
		if(k>m)	m=k;
	}
	printf("%d\n",m);
	return 0;
}
		


Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
const int mod = 1000000007;
int n;
set<ll>a;
int main(){
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    ll temp;
    cin >> temp;
    decltype(a)::iterator it = a.find(temp);
    if (it != a.end()) {
      cout << "NO" << endl;
      return 0;
    }
    a.insert(temp);
  }
  cout << "YES" << endl;
}


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

int main(void)
{
  int water;
  int fee;
  while (true)
  {
    cin >> water;
    if ( water == -1 ) break;

    if (water <= 10)
    {
      fee = 1150;
    }
    else if (water <= 20)
    {
      fee = 1150 + (water - 10) * 125;
    }
    else if (water <= 30)
    {
      fee = 1150 + 10 * 125 + (water - 20) * 140;
    }
    else 
    {
      fee = 1150 + 10 * 125 + 10 * 140 + (water - 30) * 160;
    }

    cout << 4280 - fee << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
sum_max = 0
sum_temp = sum(p[0:K])
k_temp = 0
for k in range(1,N-K+1):
	sum_temp -= p[k-1]
	sum_temp += p[k+K-1]
	if sum_temp > sum_max:
		sum_max = sum_temp
		k_temp = k
ans = 0

for j in range(k_temp,k_temp+K):
	ans += (p[j]+1)/2
print(ans)


Measured memory_bytes: 25060
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let r: usize = iter.next().unwrap().parse().unwrap();
    let d: usize = iter.next().unwrap().parse().unwrap();
    let mut x: usize = iter.next().unwrap().parse().unwrap();

    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
#include<cstdio>
using namespace std;

int main(void) {
	int N, X;
	scanf("%d %d", &N, &X);
	int L[110];
	int D = 0;
	int cnt = 1;
	for (int i = 0; i < N; i++) {
		scanf("%d", &L[i]);
		D += L[i];
		if (D <= X) cnt++;
	}
	printf("%d\n", cnt);

	return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int x, y;
	cin >> x >> y;
	if (x == 2 || y == 2 || x == 11 || y == 4)
		cout << "No" << "\n";
	else if (x == 4 || x == 6 || x == 9) {
		if (y == 6 || y == 9 || y == 11)
			cout << "Yes" << "\n";
		else
			cout << "No" << "\n";
	}
	else {
		if (y == 6 || y == 9 || y == 11)
			cout << "No" << "\n";
		else
			cout << "Yes" << "\n";
	}
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <algorithm>
 
#define MaxN 100005
 
using namespace std;
 
int fr[MaxN],N,M,X,Y,bad=0;
 
int main()
{
	cin>>N>>M;
	for(int i=1;i<=M;i++)
	{
		cin>>X>>Y;
		fr[X]++;
		fr[Y]++;
		if(fr[Y]%2==0)
			bad--;
		if(fr[X]%2==0)
			bad--;
		if(fr[X]%2==1)
			bad++;
		if(fr[Y]%2==1)
			bad++;
	}
	if(bad==0)
		cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 640
W,H,N = map(int,input().split())
rows = [list(map(int,input().split())) for _ in range(N)]

Xleft = 0
Xright = W
Ylow = 0
Yhigh = H
for X,Y,A in rows:
    if A == 1:
        Xleft = max(X,Xleft)
    elif A == 2:
        Xright = min(X,Xright)
    elif A == 3:
        Ylow = max(Y,Ylow)
    else:
        Yhigh = min(Y,Yhigh)

ans = max(Yhigh-Ylow,0) * max(Xright-Xleft,0)
print(ans)

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

using namespace std;
typedef long long ll;

int main(void){
ll a,b,c;

cin >> a >> b >> c;

ll d = c - a - b;
if(d > 0 && d * d > 4 * a * b){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}

return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(s) - len(t), -1, -1):
        ok = True
        for j in range(len(t)):
            if s[i + j] != t[j] and s[i + j] != "?":
                ok = False
        if ok:
            print((s[:i] + t + s[i + len(t):]).replace("?", "a"))
            exit()
    print("UNRESTORABLE")

Measured memory_bytes: 3064
using System;


namespace aoj8c_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            int[] counter = new int[26];

            while((line = Console.ReadLine()) != null)
            {
                char[] ch = line.ToCharArray();
                for ( int i = 0; i < line.Length; i++)
                {
                    if (char.IsUpper(ch[i]))
                    {
                        ch[i] = char.ToLower(ch[i]);
                    }

                    if (char.IsLower(ch[i]))
                    {
                        counter[ch[i] - 'a']++;
                    }
                }
                
            }
            for (int i = 0; i < 26; i++)
            {
                Console.WriteLine(Convert.ToChar(i + 'a') + " : " + counter[i]);
            }
        }
    }
}

Measured memory_bytes: 9164
#include <stdio.h>
   
int main(){
 int a,b,sum,counter,i;
 while(scanf("%d %d",&a,&b) != -1){
   sum = a + b;
   for (i=0; sum!=0; i++)
    sum = sum / 10;
   printf("%d\n",i);
 }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;

int gcd(int a,int b){
int r, tmp;
if (a < b) {
	tmp = a;
	a = b;
	b = tmp;
}
if (b == 0)return a;
r = a % b;
while (r != 0) {
	a = b;
	b = r;
	r = a % b;
}

return b;
}

int main() {
	int N;
	int A[100000];
	int G[100001] = { 0 };
	int L[100003] = { 0 };
	cin >> N;
	int i;
	rep(i, N) {
		cin >> A[i];
	}
	for(i=2;i<=N;i++) {
		G[i] = gcd(G[i-1], A[i - 2]);
	}
	for (i = N; i > 0; i--) {
		L[i] = gcd(L[i+1], A[i-1]);
	}
	int M = 0;
	rep(i, N+1) {
		int g = gcd(G[i], L[i+1]);
		M = (M > g ? M : g);
	}
	cout << M;
	return 0;
}


Measured memory_bytes: 1408
while as = gets
   as = as.split.map(&:to_i)
   bs = gets.split.map(&:to_i)
   hit,blow = 0,0
   as.each_with_index do|a,i|
      bs.each_with_index do|b,j|
         if a == b
            if i == j
               hit += 1
            else
               blow += 1
            end
         end
      end
   end
   print "%d %d\n" % [hit,blow]
end

Measured memory_bytes: 6116
solveEven [] i = False
solveEven s i | i < 0 = True
              | odd i = solveEven s (i-1)
              | [s !! i] == "R" = solveEven s (i-1)
              | [s !! i] == "U"= solveEven s (i-1)
              | [s !! i] == "D" = solveEven s (i-1)
              | otherwise = False

solveOdd [] i = False
solveOdd s i | i < 0 = True
             | even i = solveOdd s (i-1)
             | [s !! i] == "L" = solveOdd s (i-1)
             | [s !! i] == "U" = solveOdd s (i-1)
             | [s !! i] == "D" = solveOdd s (i-1)
             | otherwise = False
 
main = do
    s <- getLine
    putStrLn $ if (solveEven s (length(s)-1)) && (solveOdd s (length(s)-1)) then "Yes" else "No"


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int a,b,n,stk[maxn],tp,ans[maxn];
char tmp[10];
inline int ask(int i,int j){
	printf("? %d %d\n",i-1,j-1);
	fflush(stdout);
	scanf("%s",tmp);
	return tmp[0]=='Y';
}
int main(){
	a=read();b=read();n=a+b;
	if(a<=b){
		puts("Impossible");
		fflush(stdout);
		return 0;
	}
	FOR(i,1,n){
		if(tp && !ask(stk[tp],i)) tp--;
		else stk[++tp]=i;
	}
	FOR(i,1,n) ans[i]=ask(stk[tp],i);
	printf("! ");
	FOR(i,1,n) printf("%d",ans[i]);
	fflush(stdout);
}

Measured memory_bytes: 3824
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int n = in.nextInt();
		int p = in.nextInt();
		if (n + p == 0) return false;


		int[] cnt = new int[n];
		int cur = 0, q = p;
		while (true) {

			if (p > 0) {
				p--;
				cnt[cur]++;
				if (cnt[cur] == q) {
					out.println(cur);
					break;
				}
			} else {
				p += cnt[cur];
				cnt[cur] = 0;
			}

			cur = (cur + 1)%n;
		}

		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26492
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int r; cin >> r;
  cout << 3*r*r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(long long N, std::vector<long long> V, std::vector<long long> C){
	ll res = 0;
	REP(i, N) {
		if (V[i] > C[i]) res += V[i] - C[i];
	}
	cout << res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> V(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&V[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(V), std::move(C));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[100000];
int cnt1[100000];
int cnt2[100000];
int main(){
  int i, m1, m2, res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
    }
  }
  for(i=0;i<N;i+=2){
    cnt1[A[i]]++;
  }
  for(i=1;i<N;i+=2){
    cnt2[A[i]]++;
  }
  {
    int FmcKpFmN, Q5VJL1cS, RZTsC2BF, cTE1_r3A, e98WHCEY=0;
    for(Q5VJL1cS=0;Q5VJL1cS<((100000)-1)+1;Q5VJL1cS++){
      RZTsC2BF = cnt1[Q5VJL1cS];
      if(e98WHCEY==0 || cTE1_r3A<RZTsC2BF){
        cTE1_r3A = RZTsC2BF;
        e98WHCEY = 1;
        FmcKpFmN = Q5VJL1cS;
      }
    }
    m1 =FmcKpFmN;
  }
  {
    int KrdatlYV, WYIGIcGE, ao_dF3pO, tU__gIr_, t_ynMSdg=0;
    for(WYIGIcGE=0;WYIGIcGE<((100000)-1)+1;WYIGIcGE++){
      ao_dF3pO = cnt2[WYIGIcGE];
      if(t_ynMSdg==0 || KrdatlYV<ao_dF3pO){
        KrdatlYV = ao_dF3pO;
        t_ynMSdg = 1;
        tU__gIr_ = WYIGIcGE;
      }
    }
    m2 =tU__gIr_;
  }
  res = 0;
  for(i=0;i<100000;i++){
    if(i!=m1){
      chmax(res, cnt1[m1] + cnt2[i]);
    }
  }
  for(i=0;i<100000;i++){
    if(i!=m2){
      chmax(res, cnt1[i] + cnt2[m2]);
    }
  }
  res = N - res;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, A[1d5];
// 
// int cnt1[1d5], cnt2[1d5];
// {
//   int i, m1, m2, res;
//   rd(N,(A--)(N));
// 
//   for(i=0;i<N;i+=2) cnt1[A[i]]++;
//   for(i=1;i<N;i+=2) cnt2[A[i]]++;
//   m1 = argmax(cnt1(1d5));
//   m2 = argmax(cnt2(1d5));
// 
//   res = 0;
//   rep(i,1d5) if(i!=m1) res >?= cnt1[m1] + cnt2[i];
//   rep(i,1d5) if(i!=m2) res >?= cnt1[i] + cnt2[m2];
//   res = N - res;
// 
//   wt(res);
// }


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll K, X;
    cin >> K >> X;

    for (ll i = X - (K - 1); i <= X + (K - 1); ++i)
        cout << i << " ";

    cout << '\n';

    return 0;
}

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

int main(){
	int a, b;
  cin>>a>>b;
  if(b < a){
  	a^=b;
    b^=a;
    a^=b;
  }
  string ans(b, (char)(a + (int)'0'));
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // 全探索
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> C(H);
  rep(i, H) {
    cin >> C[i];
  }
  int ans = 0;  
  for (int i = 0; i < (1<<H); i++) {
    for (int j = 0; j < (1<<W); j++) {
      // iが縦の組み合わせ
      int cnt = 0;
      for (int k = 0; k < H; k++) {
        if (i&(1<<k)) continue;
        for (int l = 0; l < W; l++) {
          // kが縦の列
          if (j&(1<<l)) continue;
          if (C[k][l] == '#') {
            ++cnt;
          }
        }
      }
      if (cnt == K) {
        ++ans;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
main()
{
  int G[101][101];
  int i,j,n,u,k,v;
  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
	{
	  G[i][j]=0;
	}
    }

  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&u,&k);
      for(j=1;j<=k;j++)
	{
	  scanf("%d",&v);
	  G[u][v]=1;	
	}
    }

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

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    vvi mat(3, vi(3, 0));
    auto tmp = mat;
    REP(i, 0, 3)
        REP(j, 0, 3)
            cin >> mat[i][j];
    ll n, a, flg = 0;
    cin >> n;
    REP(k, 0, n) {
        cin >> a;
        REP(i, 0, 3)
            REP(j, 0, 3)
                if (mat[i][j] == a)
                    tmp[i][j] = 1;
    }
    vi chk(3, 1);
    REP(i, 0, 3) {
        if (tmp[i] == chk) {
            flg = 1;
            break;
        }
    }
    REP(i, 0, 3) {
        vi xc;
        REP(j, 0, 3)
            xc.pb(tmp[j][i]);
        if (xc == chk) {
            flg = 1;
            break;
        }
    }
    vi xc;
    REP(i, 0, 3)
        xc.pb(tmp[i][i]);
    if (xc == chk)
        flg = 1;
    xc.clear();
    REP(i, 0, 3)
        xc.pb(tmp[i][2-i]);
    if (xc == chk)
        flg = 1;
    if (flg)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
def tl():
    n,t=map(int,input().split())
    ct=[list(reversed(list((map(int,input().split()))))) for i in range(n)]
    ct.sort()

    if ct[0][0]<=t:
        cos=[[i[1],i[0]] for i in ct]
        cos.sort()
        for i in cos:
            if i[1]<=t:
                print(i[0])
                exit()
    else:
        ans='TLE'
    return ans

print(tl())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin>>N;
  
  int A[N];
  for(int i=0; i<N; i++){
    cin>>A[i];
  }
  
  int B[N];
  B[0]=0;
  
  for(int i=0; i<N; i++){
    if(i%2==0){
      B[0]+=A[i];
    }
    else{
      B[0]-=A[i];
    }
  }
  
  for(int i=1; i<N; i++){
    B[i]=2*A[i-1]-B[i-1];
  }
  
  for(int i=0; i<N; i++){
    cout<<B[i]<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    
    vector<ll>A(N);

    ll inx;
    rep(i,N){
        cin>>A[i];
        if(A[i]==1){
            inx=i;
        }
    }

    ll L1 = N-1;
    /*if(inx==0 || inx == N-1){
        L1--;
    }*/
    ll L2 = N-inx-1;
    ll ans=0;
    if(L1%(K-1)==0){
        ans+=L1/(K-1);
    }else{
        ans+=L1/(K-1)+1;
    }
    /*if(L2%(K-1)==0){
        ans+=L2/(K-1);
    }else{
        ans+=L2/(K-1)+1;
    }*/

    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4048
#include "bits/stdc++.h"
using namespace std;
const int MAX=100005;

int main(){
	int N;
	cin >> N;
	int A[MAX]={0};
	for(int i=0;i<N;i++){
		int x;
		cin >> x;
		A[x]++;
	}

	int ans = 0;
	for(int i=0;i<MAX-2;i++){
		ans = max(ans,A[i]+A[i+1]+A[i+2]);
	}
	cout << ans <<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(a <= k){
        ans += a;
        k -= a;
    }
    else{
        ans += k;
        k = 0;
    }
    if(b <= k){
        k -= b;
    }
    else{
        k = 0;
    }
    if(c <= k){
        ans -= c;
        k -= c;
    }
    else{
        ans -= k;
        k = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
int main()
{
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if (a[i] != a[j] and a[j] != a[k] and a[i] != a[k] and a[i] < a[j] + a[k] and a[j] < a[i] + a[k] and a[k] < a[j] + a[i])
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int D = sc.nextInt();
  
   if(N <= (2*D + 1)){
     System.out.println(1);
   }else{
     int num = 0;
    while(N>0){
     N -= (2*D + 1);
      num++;
    }
    System.out.println(num);
   }
   
 }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int a,b;
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		
		if(a<b)
			System.out.println("a < b");
		else if(a>b)
			System.out.println("a > b");
		else
			System.out.println("a == b");

	}

}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;

    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> a >> b;
    if(a + b >= 10){
        cout << "error" << endl;
        return 0;
    }
    cout << a + b << endl;
}


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

int N;
int A[110000];

int main () {
	std::ios::sync_with_stdio (0);
	std::cin >> N;
	for (int i = 0; i < N; ++i) std::cin >> A[i];
	int ord = 0, ans = 1;
	for (int i = 0; i < N - 1; ++i) {
		if (A[i] == A[i + 1]) continue;
		else if (ord == 0) {
			ord = (A[i] < A[i + 1]) ? -1 : 1;
		} else if ((ord == 1 && A[i] < A[i + 1]) || (ord == -1 && A[i] > A[i + 1])) {
			ord = 0;
			++ans;
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int calc( int , int , int );

//配列の外部変数
int A[20];

int main(){
    int n, q, m, i;

    scanf("%d", &n);
    for( i = 0 ; i < n ; i++ ){
        scanf("%d",&A[i]);
    }

    scanf("%d",&q);
    for( i = 0 ; i < q ; i++ ){
        scanf("%d", &m);

        if(calc( 0 , n , m ) == 1) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

int calc(int i ,int n ,int m){

    if( m == 0 ){
        return 1;
    }else if( i > n && m != 0 ){
        return 0;
    }
    return calc( i + 1 , n , m) || calc( i + 1 , n , m - A[i]);//審議判定( a または b が真の場合)
}



Measured memory_bytes: 2120
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {

	static int N;

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		N = sc.nextInt();

		List<Integer> H = new ArrayList<>();

		for (int i = 0; i < N; i++)
			H.add(sc.nextInt());

		for (int i = H.size() - 1; i > 0; i--) {
			if (2 > H.get(i - 1) - H.get(i) && H.get(i - 1) - H.get(i) >= 1)
				H.set(i - 1, H.get(i - 1) - 1);

			else if (H.get(i - 1) - H.get(i) >= 2) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");

	}

	public static int check(int a) {
		return String.valueOf(a).length();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 26968
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MAX_M = 100000;

int dp[5005][5005];


int main(int argc, char *args[]) {
	ll N;
	cin >> N;
	ll counter = 1001001001001001;
	for (int i = 1; i <= sqrt(N); i++) {
		ll ans = N / i;
		int r = N % i;
		if (r == 0) {
			ll tmp = i + ans;
			counter = min(counter, tmp);
		}
	}
	cout << counter - 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>i>>j;
    cout<<(i+j-1)/j;

    return 0;
}



Measured memory_bytes: 256
/**********************************************************
* @Author: 			   Kirito
* @Last Modified by:   Kirito
* @Remark:
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn=211111;
ll town[maxn],n,k;
ll book[maxn];

int main()
{
    FAST;cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>town[i];
    }
    CSE(book,0);
    ll ad=1,be=1;
    while(true){
        if(book[be]==0){
            book[be]=ad++;
            if(k==0){
                cout<<be<<endl;
                return 0;
            }
            k--;
            be=town[be];
        }
        else{
            int sz=ad-book[be];
            k%=sz;
            while(k--){
                be=town[be];
            }
            cout<<be<<endl;
            return 0;
        }
    }
	return 0;
}


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

using namespace std;

int main(void) {

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

  for (int i = 0; i < n; i++) {
    cout << A[i] << endl;
  } 
  return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace boost::multiprecision;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};


int gcd(int a, int b) {
    if(a < b) swap(a,b);
    
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
  int N;
  cin >> N;
  
  SegmentTree< int > seg(N, [](int a, int b) { return gcd(a, b); }, 0);
  for(int i= 0; i < N; i++){
    int a;
    cin >> a;
    seg.update(i,a);
  }
  int max_val = 0;
  for(int i = 0; i < N; i++){
    int tmp;
    if(i == 0){
      tmp = seg.query(i+1, N);
    } else if(i == N-1){
      tmp = seg.query(0, N-1);
    } else { 
      tmp = gcd(seg.query(0, i), seg.query(i+1, N));
    }
    if(tmp > max_val) max_val = tmp;
  }
  cout << max_val << endl;
}




Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> pii;

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50, mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs;}
inline int inv(int a) {return power(a,mod-2);}

int n,m,k,ans=1,scc;
int dfn[N],low[N],ind;
int vis[N],vs;
vector <int> edge[N];
stack <pii> stk;
struct combin {
	int fac[N],ifac[N];
	combin() {
		fac[0]=1;
		for(int i=1;i<N;i++) fac[i]=mul(fac[i-1],i);
		ifac[0]=ifac[1]=1;
		for(int i=2;i<N;i++) ifac[i]=mul(mod-mod/i,ifac[mod%i]);
		for(int i=2;i<N;i++) ifac[i]=mul(ifac[i-1],ifac[i]);
	}
	inline int C(int a,int b) {return mul(fac[a],mul(ifac[b],ifac[a-b]));}
} C;

struct polya {
	int npr[N],pr[N],pt;
	int phi[N];
	polya() {
		phi[1]=1;
		for(int i=2;i<N;i++) {
			if(!npr[i]) {pr[++pt]=i; phi[i]=i-1;}
			for(int j=1;j<=pt;j++) {
				int k=i*pr[j]; if(k>=N) break;
				npr[k]=1;
				if(i%pr[j]) phi[k]=phi[i]*phi[pr[j]];
				else {phi[k]=phi[i]*pr[j]; break;}
			}
		}
	}
	inline int solve(int n) {
		int ans=0;
		for(int i=1;i<=n;i++) 
			if(!(n%i)) ans=add(ans,mul(phi[n/i],power(k,i)));
		return mul(ans,power(n,mod-2));
	}
} P;
inline void dfs(int x,int f) {
	dfn[x]=low[x]=++ind;
	for(auto v:edge[x]) if(v!=f) {
		if(!dfn[v]) {
			int top=stk.size();
			stk.push(pii(v,x));
			dfs(v,x);
			low[x]=min(low[x],low[v]);
			if(low[v]>=dfn[x]) {
				++vs; int c1=0, c2=stk.size()-top;
				while(stk.size()>top) {
					pii v=stk.top(); stk.pop();
					if(vis[v.first]!=vs) ++c1, vis[v.first]=vs;
					if(vis[v.second]!=vs) ++c1, vis[v.second]=vs;
				}
				if(c1>c2) ans=mul(ans,power(k,c2));
				else if(c1==c2) ans=mul(ans,P.solve(c2));
				else ans=mul(ans,C.C(c2+k-1,k-1));
			}
		} else if(dfn[v]<dfn[x]) stk.push(pii(v,x)), low[x]=min(low[x],dfn[v]);
	}
}
int main() {
	n=rd(), m=rd(), k=rd();
	for(int i=1;i<=m;i++) {
		int x=rd(), y=rd();
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	for(int i=1;i<=n;i++) 
		if(!dfn[i]) dfs(i,0);
	cout<<ans<<'\n';
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
#include <map>
 
using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);

    int N;

    cin >> N;

    int c = 0;

    for(int i = 1; i <= N; i++) {
        if((static_cast<int>(log10(i)) + 1) % 2 != 0) {
            c++;
        }
    }

    cout << c << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<0&&b<0){
        if((b-a+1)%2==0) printf("Positive");
        else printf("Negative");
    }else if(a==0||b==0) printf("Zero");
    else if(a<0&&b>0) printf("Zero");
    else printf("Positive");
}

Measured memory_bytes: 256
import sys
inp = lambda t: t(sys.stdin.readline().strip())
inpm = lambda t: map(t, sys.stdin.readline().split())
inpl = lambda t: list(map(t, sys.stdin.readline().split()))
print = lambda x, end='\n': sys.stdout.write(str(x) + end)

x, a, b = inpm(int)
if abs(a - x) < abs(b - x):
	print('A')
else:
	print('B')

Measured memory_bytes: 3316
//============================================================================
// Name        : A.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

bool is_prime(int a){
	for (int i = 2; i * i <= a; ++i) {
		if(a % i == 0) return false;
	}
	return true;
}

vector<int> ps;

int f(int a){
	vector<ll> v;
	for(int p : ps){
		if(a % p == 0) v.push_back(p);
	}
	if(v.size() == 0) return 0;
	ll ret = v.back();
	for(int i = 0; i < (int)v.size() - 1; i++){
		ret -= v[i];
	}
	return ret;
}

int main() {
	for(int i = 2; i <= 2000000; i++){
		if(is_prime(i)) ps.push_back(i);
	}

	int n, m;
	while(cin >> n >> m , n + m){
		if(f(n) > f(m)){
			cout << "a" << endl;
		}
		else{
			cout << "b" <<endl;
		}
	}
}

Measured memory_bytes: 3708
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin >> A >> B;
    if (A == B)
        cout << "Draw";
    else if (A > B)
    {
        if (B == 1)
            cout << "Bob";
        else
            cout << "Alice";
    }
    else
    {
        if (A == 1)
            cout << "Alice";
        else
            cout << "Bob";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    rep(i,N){
        if(A[i]%2==0){
            if(A[i]%3==0||A[i]%5==0){

            }else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;

    return 0;
}

Measured memory_bytes: 256