akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string N;
    cin >> N;

    vector<int> ds;
    ds.push_back(0);
    rep(i, N.size()) {
        ds.push_back(N[i]-'0');
    }

    LL ans = 0;
    for (int i = ds.size()-1; 0 <= i; --i) {
        if (ds[i] < 5) {
            ans += ds[i];
        } else if (ds[i] == 5 && ds[i-1] < 5) {
            ans += ds[i];
        } else {
            ans += (10-ds[i]);
            int j = i-1;
            while (0 <= j) {
                ++ds[j];
                if (ds[j] < 10) {
                    j = -1;
                } else {
                    ds[j] -= 10;
                    --j;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8344
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846
 
void solve()
{
	int n; cin >> n;
        vector<int> a(n);
        int d, x; cin >> d >> x;
        forn(i, n) cin >> a[i];
        ll res = 0;
        for(int i = 0; i < n; ++i)
        {
                for(int j = 0; j < d; ++j)
                {
                        if(j * a[i] + 1 <= d) res++;
                }
        }
        cout << res + x;
}
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}

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

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            if (n < 1200)
                Console.WriteLine("ABC");
            else if (n < 2800)
                Console.WriteLine("ARC");
            else
                Console.WriteLine("AGC");
        }
    }
}


Measured memory_bytes: 27480
def _input():
    pred = list(input())
    actual = list(input())
    return pred, actual

def evaluation(pred, actual):
    hit = 0
    for p, a in zip(pred, actual):
        if p == a:
            hit += 1
    return hit

if __name__ == "__main__":
    pred, actual = _input()
    print(evaluation(pred, actual))
    

Measured memory_bytes: 3060
N = int(input())
A = input().split()
num_even = 0
num_approved = 0

for i in range(N):
    if int(A[i]) % 2 == 0:
        num_even += 1
        if int(A[i]) % 3 == 0 or int(A[i]) % 5 == 0:
            num_approved += 1

if num_even == num_approved:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 9120
#include<bits/stdc++.h>
const int MOD = 1e9+7;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define ar array
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	char C11,C12,C13,C21,C22,C23;
	cin >> C11 >> C12 >> C13 >> C21 >> C22 >> C23;

	if (C11==C23 && C12==C22 && C13==C21) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
char s[10];
int main()
{
    while(~scanf("%s",s)){
        if(s[1]=='B')s[1]='R';
        else s[1]='B';
        printf("%s\n",s);
    }
    return 0;
}


Measured memory_bytes: 3760
from collections import Counter, deque, defaultdict
import sys
input = sys.stdin.readline
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def main():
    while True:
        w, h = map(int, input().split())
        if w == 0:
            exit()
        wall = [list(map(int, input().split())) for _ in range(2 * h - 1)]
        check = [[0] * w for _ in range(h)]
        check[0][0] = 1
        q = deque([])
        q.append((0, 0))
        while q:
            y, x = q.popleft()
            for i in range(4):
                ny = y + dy[i]
                nx = x + dx[i]
                if nx < 0 or w-1 < nx or ny < 0 or h-1 < ny:
                    continue
                if check[ny][nx] > 0:
                    continue
                if wall[y + ny][(x + nx) // 2] == 1:
                    continue
                check[ny][nx] = check[y][x] + 1
                q.append((ny,nx))
        print(check[h-1][w-1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 6048
#include<bits/stdc++.h>
using namespace std;
main()
{
    int a,b,c[130],k,i,j,l=0,t;
    cin>>t;
    for(i=0;i<t;i++)
        cin>>c[i];
    sort(c,c+t);
    for(i=0;i<t-1;i++)
        l+=c[i];
    if(c[t-1]>=l)
    printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


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

int main(){
    int K, A, B;
    cin >> K >> A >> B;
    int n = 1;
    while(n*K <= B) {
        if (n*K >= A) {
            cout << "OK" << endl;
            return 0;
        }
        n++;
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<pair<int, int>> P(n);
            REP(i, n) cin >> P[i].first >> P[i].second;
            int m; cin >> m;
            vector<pair<char, int>> Go(m);
            REP(i, m) cin >> Go[i].first >> Go[i].second;
            pair<int, int> now = make_pair(10, 10);
            vector<bool> Get(n, false);
            REP(i, m){
                REP(j, Go[i].second){
                    if(Go[i].first == 'N') now.second++;
                    else if(Go[i].first == 'S') now.second--;
                    else if(Go[i].first == 'E') now.first++;
                    else if(Go[i].first == 'W') now.first--;
                    REP(p, n){
                        if(P[p] == now) Get[p] = true;
                    }
                }
            }
            bool ok = true;
            REP(i, n) if(Get[i] == false) ok = false;
            cout << (ok ? "Yes" : "No") << endl;
        }       
    }
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr ll INF = 2000000000;
constexpr ll mod = 10e8 + 7;

int main() {
	int N; cin >> N;
	ll ans = 1;
	for(ll i=0;i<N;++i) {
		ans *= i + 1;
		ans %= mod;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
int check(char a[12]){
  int i=1;
  for(;i<10;i++){
    if(a[i]<0)return 0;
    a[i]%=3;
    if(a[i]>0){
      if(a[i+1]-a[i]<0 || a[i+2]-a[i]<0)return 0;
      a[i+1]-=a[i];a[i+2]-=a[i];a[i]=0;
    }
  }
  return 1;
}

int rummy(){
  char x[256][12];
  int hai[9];
  char color[9],c[256];
  int i;

  memset(x['R'],0,sizeof(x['R']));
  memset(x['G'],0,sizeof(x['G']));
  memset(x['B'],0,sizeof(x['B']));
  memset(hai,0,sizeof(hai));
  memset(color,0,sizeof(color));
  memset(c,0,sizeof(c));

  { //input
    for(i=0;i<9;i++)scanf("%d",hai+i); //ghaa! %d cannot be used with char array; hai has to be int array! What a shame!!! Thx K.Inaba.
    for(i=0;i<9;i++)scanf(" %c",color+i);
    for(i=0;i<9;i++){
      x[color[i]][hai[i]]++;
      c[color[i]]++;
    }
    if(c['R']%3!=0 || c['G']%3!=0 || c['B']%3!=0)return 0;
  }

  return check(x['R']) & check(x['G']) & check(x['B']);
}

int main(){
  int i=0,n,x;
  scanf("%d",&n);
  for(;i<n;i++){
    x=rummy();
    printf(x ? "1\n" : "0\n");
  }
  return 0;
}

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

int main(void) {
  int n;
  int f = 0, ans = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int cnt = 0, j = i;
    while (true) {
      if (j % 2 == 1) break;
      j /= 2;
      cnt++;
    }
    if (f < cnt) {
      f = cnt;
      ans = i;
    }
  }

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

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=10;
//i_am_noob
string str;

bool noob(string str){
	string tmp=str;
	reverse(all(tmp));
	if(str==tmp) return true;
	return false;
}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	if(noob(str)&&noob(str.substr(0,sz(str)-1>>1))&&noob(str.substr(sz(str)+1>>1,sz(str)-1>>1))) print1("Yes");
	else print1("No");
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

bool solve(string s) {
  int n = s.length();
  REP(i,n) {
    if(s[i] != 'C') continue;
    for(int j = i + 1; j < n; ++j) {
      if(s[j] == 'F') return true;
    }
  }
  return false;
}

int main(){
  string s;
  cin >> s;
  if(solve(s)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



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

int main() {
    int N;
    cin>>N;
    long a[N], b[N], c[N];
    long sum = 0;
    for(int i=0;i<N;++i){
        cin>>a[i];
    }
    for(int i=0;i<N;++i){
        cin>>b[i];
        c[i] = a[i] - b[i];
        sum -= c[i];
    }

    bool ans = true;
    if(sum<0)ans=false;
    long plus = 0;
    long minus = 0;
    for(int i=0;i<N;++i){
        if(c[i]>=0){
            plus+=c[i];
        }
        else{
            if(-c[i]%2==1){
                minus += -c[i]/2+1;
            }
            else{
                minus += -c[i]/2;
            }
        }
    }
    if(sum < plus | sum < minus)ans=false;
    /**
    int plusnum = 0;
    int minusnum = 0;
    for(int i=0;i<N;++i){
        if(a[i] >= b[i]){
            plus += a[i] - b[i];
            if(a[i]>b[i]){
                plusnum++;
            }
        }
        else {
            minus += b[i] - a[i];
            minusnum++;
        }
    }
    if(plus>sum)ans=false;
    if(minus%2==0){
        if(minus/2>sum)ans=false;
    }
    else{
        if(minus/2+1>sum)ans=false;
    }
    if(plusnum>sum)ans=false;
    if(minusnum>sum)ans=false;
    **/
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  if (k == 0) {
    for (int i = 0; i < n; ++i) {
      if (s == 1000000000) {
        cout << 1000000000 - 1 << " ";
      } else {
        cout << s + 1 << " ";
      }
    }
    cout << "\n";
  } else {
    if (s == 1000000000) {
      for (int i = 0; i < n - k; ++i) {
        cout << s - 1 << " ";
      }
      for (int i = 0; i < k; ++i) {
        cout << s << " ";
      }
      cout << "\n";
    } else {
      for (int i = 0; i < n - k; ++i) {
        cout << s + 1 << " ";
      }
      for (int i = 0; i < k; ++i) {
        cout << s << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1280
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

x = INT()
if x >= 30:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Measured memory_bytes: 10272
#include <iostream>

using namespace std;

void change(string& s, int n)
{
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] + n > 'Z') s[i] = s[i] + n - 26;
        else s[i] += n;
    }
}

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

    change(s, n);

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstdlib>

const double EPS = 1e-10;

double add( double a, double b )
{
	if( abs( a + b ) < EPS * ( abs( a ) + abs( b ) ) )
		return 0;

	return a + b;
}

struct P
{
	double x, y;

	P()
	:	x( 0 ), y( 0 )
	{}

	P( double x, double y )
	:	x( x ), y( y )
	{}

	P operator+ ( const P& p ) const
	{
		return P( add( x, p.x ), add( y, p.y ) );
	}

	P operator- ( const P& p ) const
	{
		return P( add( x, -p.x ), add( y, -p.y ) );
	}

	P operator* ( double d ) const
	{
		return P( x * d, y * d );
	}

	double dot( const P& p ) const
	{
		return add( x * p.x, y * p.y );
	}

	double cross( const P& p ) const
	{
		return add( x * p.y, -y * p.x );
	}
};

bool compare( const P& p, const P& q )
{
	if( p.x != q.x )
		return p.x < q.x;

	return p.y < q.y;
}

int n;
P ps[100];

int main()
{
	while( true )
	{
		scanf( "%d", &n );
		if( !n )
			break;

		for( int i = 0; i != n; ++i )
		{
			double x, y;
			scanf( "%lf,%lf", &x, &y );
			ps[i] = P( x, y );
		}

		std::sort( ps, ps + n, compare );

		int k = 0;
		std::vector<P> qs( n * 2 );

		for( int i = 0; i != n; ++i )
		{
			while( k > 1 && ( qs[k-1] - qs[k-2] ).cross( ps[i] - qs[k-1] ) <= 0 )
				--k;
			qs[k++] = ps[i];
		}
		
		for( int i = n - 2, t = k; i >= 0; --i )
		{
			while( k > t && ( qs[k-1] - qs[k-2] ).cross( ps[i] - qs[k-1] ) <= 0 )
				--k;

			qs[k++] = ps[i];
		}

		std::cout << n - k + 1 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1248
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

n = 0
B = set(A)

C = Counter(A)

for i in C.keys():
    n += C[i] * (C[i]-1) // 2

for i in range(N):
    a = A[i]
    print(n - C[a] + 1)

Measured memory_bytes: 28924
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	LinkedList<E>[] es;

	@SuppressWarnings("unchecked")
	void run(){
		for(;;){
			es=new LinkedList[10];
			for(int i=0; i<es.length; i++){
				es[i]=new LinkedList<E>();
			}
			n=0;
			m=sc.nextInt();
			if(m==0){
				break;
			}
			for(int i=0; i<m; i++){
				int u=sc.nextInt();
				int v=sc.nextInt();
				int w=sc.nextInt();
				es[u].add(new E(v, w));
				es[v].add(new E(u, w));
				n=max(n, u+1);
				n=max(n, v+1);
			}
			solve();
		}
	}

	void solve(){
		int min=INF;
		int v=0;
		for(int i=0; i<n; i++){
			int d=dijkstra(i);
			if(d<min){
				v=i;
				min=d;
			}
		}
		println(v+" "+min);
	}

	int dijkstra(int s){
		int[] d=new int[n];
		PriorityQueue<P> que=new PriorityQueue<P>();

		Arrays.fill(d, INF);
		d[s]=0;
		que.offer(new P(s, 0));
		for(; !que.isEmpty();){
			P p=que.poll();
			if(d[p.v]<p.d){
				continue;
			}
			for(E e : es[p.v]){
				if(d[e.to]>d[p.v]+e.cost){
					d[e.to]=d[p.v]+e.cost;
					que.offer(new P(e.to, d[e.to]));
				}
			}
		}

		int res=0;
		for(int i=0; i<n; i++){
			res+=d[i];
		}
		return res;
	}

	class E{
		int to, cost;

		E(int to, int cost){
			this.to=to;
			this.cost=cost;
		}
	}

	class P implements Comparable<P>{
		int v, d;

		P(int v, int d){
			this.v=v;
			this.d=d;
		}

		@Override
		public int compareTo(P p){
			return d-p.d;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>

#define reps(i,s,n) for( int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

using namespace std;
using ll = long long;
const int max_n = 51;
ll comb[max_n][max_n] = {0};

void calc_comb(){
    comb[0][0] = 1;
    rep(i,max_n){//初期値設定
        comb[i][0] = 1;
        comb[i][i] = 1; 
    }
    reps(j,2,max_n){
        reps(k,1,j+1){
            comb[j][k] = comb[j-1][k-1] + comb[j-1][k];
        }
    }
 
}

int main(){
    int n,a,b,need=0;
    double avg=0;
    map<ll,int> mp;
    ll pat = 0;
    ll total = 0;
    calc_comb();//パスカルの三角形で組み合わせを計算する
    cin >> n >> a >> b;
    vector<ll> value(n,0);
    rep(i,n){
         cin >> value[i];
         mp[value[i]]++;//出現回数をカウント
    }

    sort(value.begin(),value.end(),greater<ll>());
    rep(i,a-1){
        total += value[i];
    }
    need = a-1;
    reps(i,a-1,b){
        total += value[i];
        if(avg < ((double)total/(double)(i+1))){
            avg = ((double)total/(double)(i+1));
            need = i+1;
        }
    }
    printf("%lf\n",avg);//平均の最大値を出力

    int a_th_val_num = 0, a_th_val_pos = 0;
    rep(i,n){
        if(value[i] == value[a-1]){
            a_th_val_num++;
            if(i < a){
                a_th_val_pos++;
            }
        }
    }

    ll cnt = 0LL;
    if(a_th_val_pos == a){
        reps(a_th_val_pos,a,b+1){
            cnt += comb[a_th_val_num][a_th_val_pos];
        }
    }else{
        cnt += comb[a_th_val_num][a_th_val_pos];
    }

    printf("%lld\n",cnt);
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	ll k;
	cin >> n >> k;
	vector<vector<int> >dp(65, vector<int>(n));
	rep (i, n) {
	  cin >> dp[0][i];
	  dp[0][i]--;
	}
	rep (k, 64) {
	  rep (i, n) {
		dp[k + 1][i] = dp[k][dp[k][i]];
	  }
	}
	int p = 0;
	rep (i, 64) {
	  if ((k >> i) & 1) p = dp[i][p];
	}
	cout << p + 1 << endl;
    
    return 0;
}


Measured memory_bytes: 54956
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
    int n,a,b;
    
    scanf("%d%d%d",&n,&a,&b);
    
    if(a*n < b){
        printf("%d\n",a*n);
    }
    else{
        printf("%d\n",b);
    }

    return 0;
}





Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

template <typename T> T gcd(T a, T b) {
	if (b == 0) return abs(a);
	T r; while ((r = a % b) != 0) a = b, b = r;
	return abs(b);
}
template <typename T> T lcm(T a, T b) {
	return a/gcd(a, b) * b;
}

int main()
{
    int N, M; cin >>N>>M;
    vector<int> a(N);
    vector<int> b(N);
    ll m;
    rep(i, N) {
        cin >> a[i];
        b[i] = a[i] / 2;
        m = i==0? b[i] : lcm(m, (ll)b[i]);
    }
    bool ok = true;
    rep(i, N) {
        if (m/(ll)b[i]%2LL==0) {
            ok = false;
            break;
        }
    }

    ll ans = ok ? (M/m+1)/2 : 0;

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int n;
    int count=0;
    cin>>n;
    int s1=n%10;
    n/=10;
    int s2=n%10;
    n/=10;
    int s3=n%10;
    if(s1==1){
        count++;
    }
    if(s2==1)
    count++;
    if(s3==1)
    count++;
    cout<<count;
}

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

int main(int argc, char** argv) {
    int pos;
    string palavra;
    cin >>pos>>palavra;
    int tam=palavra.length();
    for(int x=0;x<tam;x++)
        cout <<(char)(palavra[x]+pos <='Z'? palavra[x]+pos:palavra[x]+pos-'Z'+'A'-1);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans;
int main(void){
	string s; cin>>s;
	int a=s.size();
	for(int i=0;i<s.size();i++){
		if(s[i]=='o'){
			ans++;
		}
	}
	if(ans+(15-s.size())>=8){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	
}


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

using namespace std;

long long k, n, sisa, temp, tmbh, ctr, list[105];

int main() {
	scanf("%lld", &k);
	n = 50;
	sisa = k % n;
	temp = k / n;
	tmbh = temp * (n + 1);
	ctr = 1;
	// printf("%lld %lld %lld\n", sisa, temp, tmbh);
	for(int i = 1; i <= n - sisa; i++) {
		list[ctr++] = 50 + tmbh - (k + 1);
	}
	for(int i = n - sisa + 1; i <= n; i++) {
		list[ctr++] = 50 + tmbh + n - k;
	}
	printf("50\n");
	// sort(list + 1, list + 51);
	for(int i = 1; i < 50; i++) {
		printf("%lld ", list[i]);
	}
	printf("%lld\n", list[50]);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<ctime>
using namespace std;

typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

int main(){
    string s;
    int n,m;
    while(cin>>n>>m){
        while(n--){
            cin>>s;
            cout<<s<<endl<<s<<endl;
        }
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    ll ans = 1;
    rep1(i,n+1){
        ans *= i;
        ans %= 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
using ll = long long;

const int INF = (int) 1e9 + 9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    rep (i, 0, n-1) if (s[i] != s[i+1]) cnt++;
    cnt = max(0, cnt-2*k);
    cout << n-1-cnt << '\n';
    return 0;
}


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

int main() {
  int N;
  int p[4];
  int t[4];
  int temp;
  int ans	= 100000;

  cin >> N;
  for(int i = 0; i < 4; i++)
    cin >> p[i];
  for(int i = 0; i < 4; i++)
    cin>> t[i];

  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N; j++) {
      for(int k = 0; k <= N; k++) {
        for(int l = 0; l <= N; l++) {
          if(i*t[0]+j*t[1]+k*t[2]+l*t[3] >= N) {
            temp = i*p[0]+j*p[1]+k*p[2]+l*p[3];
            if(temp < ans) {
              ans = temp;
            }
          }
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main () {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N);
  
  for (int i=0; i<N; i++) {
    for (int j=0; j<D; j++) {
      int x;
      cin >> x;
      vec.at(i).push_back(x);
    }
  }
  
  int cnt = 0;
  for (int i=0; i < N-1; i++) {
    for (int j=i+1; j<N; j++) {
      double dist = 0;
      for (int k=0; k<D; k++) {
        dist += pow(vec.at(i).at(k) - vec.at(j).at(k), 2);
      }
      dist = sqrt(dist);
      if (ceil(dist) == floor(dist)) cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		long n=s.nextLong();
		
		HashMap<Long,Integer> map=new HashMap<>();
		
		pf(n,map);
		
		int ans=0;
		
		for(Map.Entry<Long,Integer> entry:map.entrySet())
		{
			ans=ans+fun(entry.getValue());
		}
		
		System.out.println(ans);
		
	}
	
	public static int fun(int val)
	{
		int sum=0;
		int count=0;
		
		for(int i=1;i<=val;i++)
		{
			if(sum+i<=val)
			{
				sum=sum+i;
				count++;
			}
			else
				break;
		}
		
		return count;
	}
	
	public static void pf(long n,HashMap<Long,Integer> map) 
    { 
        while (n%2==0) 
        { 
            if(map.containsKey(2l))
            {
            	map.put(2l,map.get(2l)+1);
            }
            else
            {
            	map.put(2l,1);
            }
            
            n /= 2; 
        } 
  
        for (long i = 3; i <= Math.sqrt(n); i+= 2) 
        { 
            while (n%i == 0) 
            { 
            	if(map.containsKey(i))
                {
                	map.put(i,map.get(i)+1);
                }
                else
                {
                	map.put(i,1);
                }
            	
                n /= i; 
            } 
        } 
        
        if (n > 2) 
        {
        	if(map.containsKey(n))
            {
            	map.put(n,map.get(n)+1);
            }
            else
            {
            	map.put(n,1);
            }
        }
    } 
	
}

Measured memory_bytes: 36092
#include <iostream>
#include <sstream>  // istringstream
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

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

    sort(A, A + N);
    sort(B, B + N);
    // sort(A.begin(), A.end());
    // sort(B.begin(), B.end());

    int ans = 0;
    int med_A, med_B;
    if (N % 2 == 1) {
        med_A = A[N/2];
        med_B = B[N/2];
        ans = med_B - med_A + 1;
    }
    else{
        med_A = (A[N/2-1] + A[N/2]) / 2;
        med_B = (B[N/2-1] + B[N/2]) / 2;
        if((A[N/2-1] + A[N/2]) % 2 == 1){
            ans += 1;
            med_A = (A[N/2-1] + A[N/2] + 1) / 2;
        }
        else{
            med_A = (A[N/2-1] + A[N/2]) / 2;
        }

        if((B[N/2-1] + B[N/2]) % 2 == 1){
            ans += 1;
            med_B = (B[N/2-1] + B[N/2] - 1) / 2;
        }
        else{
            med_B = (B[N/2-1] + B[N/2]) / 2;
        }
        ans += (2*(med_B - med_A) + 1);
    }

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

Measured memory_bytes: 5136
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
long long int gcd(long long int a,long long int b)
{
	return b>0?gcd(b,a%b):a;
}

int main()
{
	long long int A,B,C,D;
	scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
	long long int a,b,c,d,e,f,GD;
	GD=gcd(C,D);
	GD=(C/GD)*(D/GD)*GD;
	a=B/C;
	b=(A-1)/C;
	c=B/D;
	d=(A-1)/D;
	e=B/GD;
	f=(A-1)/GD;
	A=B-A+1-a-c+e+b+d-f;
	cout<<A<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<ll> que;
    REP(i,N){
        ll a;
        cin >> a; 
        que.push(a);
    }


    REP(i,M){
        ll a = que.top();
        que.pop();
        a /= 2;
        que.push(a);
    }

    ll ans = 0;
    while(!que.empty()){
        ll a = que.top();
        que.pop();
        ans += a;
    }

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


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  
  ll ans=0;
  rep(r, 3001) rep(g, 3001) if(N-r*R-g*G>=0 and (N-r*R-g*G)%B==0) ans++;
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	int n = N;
	while(n%2 == 0) n /= 2;
	if(n == 1) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	int min_1 = 0;
	while(((N>>min_1)&1) == 0) min_1++;
	vector<int> used(N+1, 0);
	if(N%2 == 0) {
		used[1] = used[1<<min_1] = used[N+1-(1<<min_1)] = 1;
		cout << N << " " << N+1-(1<<min_1) << "\n";
		cout << N+1-(1<<min_1) << " " << 1 << "\n";
		cout << 1 << " " << (1<<min_1) << "\n";
		cout << (1<<min_1) << " " << 2*N << "\n";
		cout << 2*N << " " << 2*N+1-(1<<min_1) << "\n";
		cout << 2*N+1-(1<<min_1) << " " << N+1 << "\n";
		cout << N+1 << " " << N+(1<<min_1) << "\n";
		cout << N-(1<<min_1) << " " << N+1-(1<<min_1) << "\n";
		cout << 1 << " " << 2*N-(1<<min_1) << "\n";
		cout << (1<<min_1)+1 << " " << 1 << "\n";
		cout << (1<<min_1) << " " << N+(1<<min_1)+1 << "\n";
	}
	for(int i = 2; i < N; i += 2) if(used[i] == 0 && used[i+1] == 0) {
		cout << "1 " << i << "\n";
		cout << i << " " << i+1 << "\n";
		cout << "1 " << N+i+1 << "\n";
		cout << N+i+1 << " " << N+i << "\n";
		if(used[1] == 0) {
			cout << N+i << " " << N+1 << "\n";
			used[1] = 1;
		}
	}
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 2688
while 1:
    a, op, b = map(str,input().split())
    a1 = int(a)
    b1 = int(b)
    if op == '?':
        break
    elif op == '+':
        print(a1+b1)
    elif op == '-':
        print(a1-b1)
    elif op == '*':
        print(a1*b1)
    else:
        print(a1//b1)



Measured memory_bytes: 5596
n = int(input())
s = list(input())
i = 0
a = 0
while i < n-2:
  if s[i] == "A":
    i += 1
    if s[i] == "B":
      i += 1
      if s[i] == "C":
        i += 1
        a += 1
  else:
    i += 1
print(a)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a;
    b=a/100;
    c=(a-b*100)/10;
    d=(a-b*100-c*10);
    
    if(b==7||c==7||d==7){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll N, K; cin >> N >> K;
  ll P[N]; rep(i,N) { cin >> P[i]; P[i]--; }
  ll C[N]; rep(i,N) cin >> C[i];

  ll result[N] = {};
  rep(i,N) {
    ll np = i, lc = 0, now = 0;
    ll sum[N+1] = {};

    sum[0] = C[np]; np = P[np]; lc++;
    while (np!=i) {
      sum[lc] = sum[lc-1] + C[np];
      np = P[np];
      lc++;
    }
    ll me = *max_element(sum,sum+lc);
    ll meleft = *max_element(sum,sum+(K-1)%lc+1);
    ll ml = sum[lc-1];
    // cout << me << " " << meleft << " " << lc << endl;
    // debug(sum,sum+N);

    if (K-1>=lc) {
      if (ml>0) result[i] = max( ml * ((K-1)/lc) + meleft, ml * ((K-1)/lc-1) + me );
      else result[i] = me;
    }
    else result[i] = meleft;
  }
  // debug(result,result+N);

  cout << *max_element(result,result+N) << endl;
  return 0;
}

Measured memory_bytes: 3760
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	N := nextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i], B[i] = nextInt(), nextInt()
	}

	sort.Ints(A)
	sort.Ints(B)

	if N%2 == 0 {
		med_min_mult2 := A[N/2-1] + A[N/2]
		med_max_mult2 := B[N/2-1] + B[N/2]
		fmt.Fprintln(out, med_max_mult2-med_min_mult2+1)
	} else {
		med_min := A[N/2]
		med_max := B[N/2]
		fmt.Fprintln(out, med_max-med_min+1)
	}
}


Measured memory_bytes: 10484
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0, mod = 0;
    vector<int> v;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        if(x % 2 == 0) ans += x / 2;
        else v.push_back(x);
    }
    sort(v.begin(), v.end(), greater<int>());
    int sum = 0;
    if(v.size() % 2 == 0) for(int x : v) sum += x;
    else for(int i = 0; i < v.size() - 1; i++) sum += v[i];
    ans += sum / 2;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3184
protocol InitFromString {
    init?(_ str: String)
}

extension Int: InitFromString {}
extension Int8: InitFromString {}
extension Int16: InitFromString {}
extension Int32: InitFromString {}
extension Int64: InitFromString {}
extension String: InitFromString {}

func input<T: InitFromString>() -> [T] {
    readLine()!.split(separator: " ").map(String.init).compactMap(T.init)
}

let i: Int = input()[0]
if "\(i)".contains("7") {
    print("Yes")
} else {
    print("No")
}


Measured memory_bytes: 8072
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
#define MIN(x,y,z) min(x,min(y,z))
vector<int> adj[2005];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=1;i<=n-1;i++)
    {
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }  
    adj[x].push_back(y);
    adj[y].push_back(x);
    int ans[n]={0};
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int dist=MIN(abs(j-i),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i));
            ans[dist]++;
        }
    }
    for(int i=1;i<n;i++)
    {
        cout<<ans[i]<<"\n";
    }
  }  
  return 0;
}

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

using namespace std;

void solve() {
    int mina, maxa;
    mina = 1000; maxa = 0;
    int n;
    cin >> n;
    for (int i=0;i<n;++i){
        int ai;
        cin >> ai;
        if (ai > maxa)
            maxa = ai;
        if (ai < mina)
            mina = ai;
    }
    cout << maxa - mina;

}

int main() {

	solve();
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  char s,t;cin>>s>>t;
  if(s!=t)cout<<'D'<<endl;
  else cout<<'H'<<endl;
  return 0;
}

Measured memory_bytes: 256
w, h, n = gets.split.map(&:to_i)
arr = [nil, 0, w, 0, h]

n.times do
  x, y, a = gets.split.map(&:to_i)
  
  if a == 1
    arr[a] = x if arr[a] < x
  elsif a == 2
    arr[a] = x if x < arr[a]
  elsif a == 3
    arr[a] = y if arr[a] < y
  elsif a == 4
    arr[a] = y if y < arr[a]
  end
end

puts (arr[1]...arr[2]).to_a.length * (arr[3]...arr[4]).to_a.length


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

int main(){
  int n;
  std::cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) std::cin >> d[i];
  std::sort(d, d+n);
  
  int lower, upper;
  lower = d[n/2 - 1];
  upper = d[n/2];
  if (lower == upper) std::cout << 0 << std::endl;
  else std::cout << upper - lower << std::endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main() {
  using namespace std;

  int x[5];

  for (int i = 0; i < 5; i++) {
    cin >> x[i];
  }

  for (int i = 0; i < 5; i++) {
    if (x[i] == 0) {
      cout << i + 1 << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3604
N = int(input())
a =int(input())
b=int(input())
if a>b:
    max1 = a
    max2 = b
else:
    max1 = b
    max2 = a

list = []
list.append(a)
list.append(b)
#print(max1,max2)                                                              
for _ in range(N-2):
    i = int(input())
    list.append(i)
    if i > max1:
        max2 = max1
        max1 = i
    elif i > max2:
        max2 = i
if max1==max2:
    for i in range(N):
        print(max1)

else:
    for i in list:
        if i == max1:
            print(max2)
        else:
            print(max1)

Measured memory_bytes: 12520
import java.util.*
fun readint()=readLine()!!.toInt()
fun readll()=readLine()!!.toLong()
fun readstring()=readLine()!!
fun readlint()=(readLine()!!.split(" ").map{it.toInt()}).toIntArray()
fun readlll()=(readLine()!!.split(" ").map{it.toLong()}).toLongArray()

fun solve() {
    val n = readint();
    val v = readlll();
    for (i in v) {
        if (i == 0L) {
            println(0);
            return;
        }
    }
    var d = 1.0;
    var ans = 1L;
    for (i in v) {
        d *= i;
        ans *= i;
        //println("$d $ans");
    }
    if (d > 1e18 || ans > 1000000000000000000) {
        println(-1);
    }
    else {
        println(ans);
    }
}
fun main(args: Array<String>) {
    val t = 1;
    repeat(t) {
        solve();
    }
}

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

bool sortbysec(const pair<string, int> &a, const pair<string, int> &b) {
  return a.second < b.second;
}
int main() {
  map<string, int> mapa;
  string s;
  int n;
  cin >> n;
  while (n--) {
    cin >> s;
    if (mapa.count(s))
      mapa[s]++;
    else
      mapa[s] = 1;
  }

  vector<pair<string, int> > v;
  int m = -1;
  for (auto it = mapa.cbegin(); it != mapa.cend(); ++it)
    m = m == -1 ? (*it).second : (m < (*it).second ? ((*it).second) : m);

  for (auto it = mapa.cbegin(); it != mapa.cend(); ++it)
    if ((*it).second == m)
      cout << (*it).first << '\n';

  return 0;}


Measured memory_bytes: 25216