akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
    }

    println!("{}", if a == b && b == c { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i, 0, n){
        ans = min(ans * 2, ans + k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def solve(N, A):
    x = [0 for i in range(N)]
    x[0] = sum([A[i]*(-1)**i for i in range(0, N)]) // 2
    for i in range(0, N-1):
        x[i+1] = A[i] - x[i]
    x = [2 * x[i] for i in range(N)]
    return ' '.join(map(str, x))

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


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

const int MOD = (int) 1e9 + 7;
const int N = 1005;
char a[N][N];
int dp[N][N];

int main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= m; ++j)
        {
            cin >> a[i][j];
        }
    }
    a[1][0] = '.';
    dp[1][0] = 1;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j<= m; ++j)
        {
            int cur = 0;
            if(a[i-1][j] == '.')
                cur += dp[i-1][j];
            if(a[i][j-1] == '.')
                cur += dp[i][j-1];
            if(cur >= MOD)
                cur %= MOD;
            dp[i][j] = cur;
        }
    }
    cout << dp[n][m];
    return 0;
}


Measured memory_bytes: 5248
#include<stdio.h>
int main()
{
int x,y;
while(1)
{
   scanf("%d %d",&x,&y);
   if(x==0&&y==0)
   {
   break;
   }
   else if(x<=y)
   {
   printf("%d %d\n",x,y);
   }
   else
   {
   printf("%d %d\n",y,x);
   }
}
return 0;
}

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

using namespace std;

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

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

ll N, M;
string s;
ll ans = 0;

void solve() {
    cin >> N >> M;
    ll x[N], y[N], z[N];
    rep(i,N) cin >> x[i] >> y[i] >> z[i];
    rep(i,8) {
        ll s[N] = {};
        rep(j,N) {
            s[j] += (i >> 0 & 1) ? -x[j] : x[j];
            s[j] += (i >> 1 & 1) ? -y[j] : y[j];
            s[j] += (i >> 2 & 1) ? -z[j] : z[j];
        }
        sort(s, s+N);
        ll sum = 0;
        rep(j,M) sum += s[N-j-1];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

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


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int A, B;
    cin >> A >> B;

    set<int> ans{1,2,3};
    ans.erase(A);
    ans.erase(B);

    cout << *ans.begin() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int x[10],y[10];
ll fac[2010100],fnv[2010100],ret;
ll walk(int p,int q,int r,int s) {
	r-=p; s-=q;
	return fac[r+s]*fnv[r]%mod*fnv[s]%mod;
}
ll solve(int p,int q,int r,int s) {
	ll ret=0,cur=walk(p,q,x[2],y[2])*walk(x[2],y[2],r,s)%mod;
	ret=cur;
	int px=x[2],py=y[2],qx=x[2],qy=y[2];
	rep(i,x[2]+y[2]+1,x[3]+y[3]) {
		if (py+1>y[3]) cur-=walk(p,q,px,py)*walk(px,py+1,r,s)%mod,px++;
		else cur+=walk(p,q,px-1,py+1)*walk(px,py+1,r,s)%mod,py++;
		if (qx+1>x[3]) cur-=walk(p,q,qx,qy)*walk(qx+1,qy,r,s)%mod,qy++;
		else cur+=walk(p,q,qx+1,qy-1)*walk(qx+1,qy,r,s)%mod,qx++;
//		printf("%d %d %d %d %lld\n",px,py,qx,qy,cur);
		cur%=mod;
		ret+=cur;
	}
	if (x[2]!=x[3]||y[2]!=y[3]) ret+=walk(p,q,x[3],y[3])*walk(x[3],y[3],r,s)%mod;
	ret%=mod;
//	rep(i,x[2],x[3]+1) rep(j,y[2],y[3]+1) ret+=walk(p,q,i,j)*walk(i,j,r,s)%mod;
//	exit(0);
	return ret;
} 
int main() {
	fac[0]=1;
	rep(i,1,2000004) fac[i]=fac[i-1]*i%mod;
	fnv[2000003]=powmod(fac[2000003],mod-2);
	per(i,1,2000004) fnv[i-1]=fnv[i]*i%mod;

	rep(i,0,6) scanf("%d",x+i);
	rep(i,0,6) scanf("%d",y+i);
	++x[5]; ++y[5];
	--x[0]; --y[0];
	rep(i,0,16) {
		ret+=(__builtin_popcount(i)%2?-1:1)*solve(x[i%2],y[i/2%2],x[i/4%2+4],y[i/8%2+4]);
	}
	ret%=mod;
	if (ret<0) ret+=mod;
	printf("%lld\n",ret);
}


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

using namespace std;

long long a, b, c;

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

    cin >> a >> b >> c;

    for (int i = 0; i < 1000000; i++) {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
            cout << i << endl;

            return 0;
        }

        long long ta = (b + c) / 2, tb = (a + c) / 2, tc = (a + b) / 2;
        a = ta, b = tb, c = tc;
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
class Element:
    def __init__(self, x):
        self.x = x
        self.lh = None
        self.rh = None

class MyDeque:
    def __init__(self):
        self.top = self.tail = None
    
    def insert(self, x):
        elm = Element(x)
        if self.top is None:
            self.top = self.tail = elm
        else:
            elm.rh = self.top
            self.top.lh = self.top = elm
        
    def delete(self, x):
        elm = self.top
        while elm is not None:
            if elm.x == x:
                if elm.lh is None and elm.rh is None:
                    self.top = self.tail = None
                else:    
                    if elm.lh is None:
                        self.top = elm.rh
                    else:
                        elm.lh.rh = elm.rh
                        
                    if elm.rh is None:
                        self.tail = elm.lh
                    else:
                        elm.rh.lh = elm.lh
                break
            
            elm = elm.rh
            
    def delete_first(self):
        if self.top is self.tail:
            self.top = self.tail = None
        else:
            self.top = self.top.rh
            self.top.lh = None
                
    def delete_last(self):
        if self.top is self.tail:
            self.top = self.tail = None
        else:
            self.tail = self.tail.lh
            self.tail.rh = None
                
    
    def print_que(self):
        elm = self.top
        q=[]
        while elm is not None:
            q.append(elm.x)
            elm = elm.rh
        print(*q)

from sys import stdin

que = MyDeque()
N = int(input())
for _ in range(N):
    cmd = stdin.readline().strip().split()
    if cmd[0] == 'insert':
        que.insert(cmd[1])
        #que.print_que()        
        
    elif cmd[0] == 'delete':
        que.delete(cmd[1])
        #que.print_que()
        
    elif cmd[0] == 'deleteFirst':
        que.delete_first()
        #que.print_que()
        
    elif cmd[0] == 'deleteLast':
        que.delete_last()
        #que.print_que()
    
que.print_que()


Measured memory_bytes: 227792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

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

	int n, k, cou =1, count =0;//couは整数、countは操作の回数
	cin >> n >> k;
	if(n == 1){
		cout << 2 <<endl;
		return 0;
	}
	while( cou <= k && count <= n ){ //nが1の時にwhileの中を通ってくれないis何故
		cou = cou *2;
		count++;
	}

	if(count == n ){
		cout << cou << endl;
		return 0;
	}
	else{
		for(int i = 0; i < n; i++){
			if( count == n ){
				cout << cou <<endl;
				return 0;
			}
			cou = cou + k;
			count++;
		}
	}

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

char abc[27] = "abcdefghijklmnopqrstuvwxyz";

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

  char s[n][51];
  for(int i = 0;i < n;i ++){
    scanf("%s",s[i]);
  }

  int count[50][26] = {0};
  for(int i = 0;i < n;i ++){
    for(int j = 0;s[i][j] != '\0';j ++){
      count[i][s[i][j] - 'a'] ++;
    }
  }

  int min[26] = {0} , k = 100;
  for(int i = 0;i < 26;i ++){
    for(int j = 0;j < n;j ++){
      if(k > count[j][i]){
        k = count[j][i];
      }
    }
    min[i] = k;
    k = 100;
  }

  for(int i = 0;i < 26;i ++){
    while(min[i] > 0){
      printf("%c",abc[i]);
      min[i] --;
    }
  }

  return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;

  vector<int> a(n), b(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = abs(x - a[i]);
  }

  sort(b.begin(), b.begin());
  int d = b[0];

  for (int i = 0; i < n; i++) {
    if (b[i] % d != 0) d = b[i] % d;
  }

  cout << d << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
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;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct Edge {
  int from, to, cost;
};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int L;
  cin >> L;
  int N = floor(log2(L));
  vec<Edge> E;
  REP(i, N) {
    Edge e = {i, i + 1, 0};
    E.pb(e);
    e = {i, i + 1, BIT(i)};
    E.pb(e);
  }  // 最上位ビットが0の場合完成。
     //ここの実装に思ったよりも時間がかかった。
  REP(i, N) {
    if (L & BIT(i)) {
      Edge e = {i, N, (L - 1) - (L - 1) % BIT(i + 1)};
      E.pb(e);
    }
  }

  int sizeE = E.size();
  cout << N + 1 << " " << sizeE << "\n";
  FORA(e, E) cout << 1 + e.from << " " << 1 + e.to << " " << e.cost << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int distance(short ax, short ay, short bx, short by);

short X[100];
short Y[100];
int H[100];

int main(){
	short i;
	short is;
	int N;
	if(scanf("%hd", &N));
	short A = -1;
	for(i=0; i<N; i++){
	if(scanf("%hd%hd%d", &X[i], &Y[i], &H[i]));
		if(A==-1 && H[i]!=0){A=i;}
	}
	short CX=0, CY=0;
	int CH=0;
	for(CX=0; CX<=100; CX++){
		for(CY=0; CY<=100; CY++){
			CH = H[A]+distance(CX, CY, X[A], Y[A]);
			is = 1;
			for(i=0; i<N; i++){
				if(H[i] == 0){
					if(distance(CX, CY, X[i], Y[i]) < CH){
						is = 0;
						break;
					}
				}else{
					if(H[i]+distance(CX, CY, X[i], Y[i]) != CH){
						is = 0;
						break;
					}
				}
			}
			if(is){break;}
		}
		if(is){break;}
	}
	printf("%d %d %d\n", CX, CY, CH);
	return 0;
}

int distance(short ax, short ay, short bx, short by){
	return (ax>bx?ax-bx:bx-ax)+(ay>by?ay-by:by-ay);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

	int h, w;
	string s[50];
	cin >> h >> w;
	for(int i=0; i<h; i++){
		cin >> s[i];
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]=='.'){
				int cnt=0;
				for(int k=max(0, i-1); k<=min(h-1, i+1); k++){
					for(int l=max(0, j-1); l<=min(w-1, j+1); l++){
						if((k!=i || l!=j) && s[k][l]=='#'){
							cnt++;
						}
					}
				}
				s[i][j]=cnt+'0';
			}
		}
	}
	for(int i=0; i<h; i++){
		cout << s[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define repsr(i, n, s) for (int i = (n); i >= (s); --i)
#define all(xs) (xs).begin(), (xs).end()
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

int main() {
  int A, B, Q; cin >> A >> B >> Q;
  vector<int64_t> s(A + 2), t(B + 2);
  s[0] = t[0] = -inf; s[A + 1] = t[B + 1] = inf;
  rep(i, A) cin >> s[i + 1];
  rep(i, B) cin >> t[i + 1];
  rep(i, Q) {
    int64_t x; cin >> x;
    auto s1 = lower_bound(all(s), x); auto s2 = s1 - 1;
    auto t1 = lower_bound(all(t), x); auto t2 = t1 - 1;
    int64_t ans = min({
      abs(x - *s1) + abs(*s1 - *t1),
      abs(x - *s1) + abs(*s1 - *t2),
      abs(x - *s2) + abs(*s2 - *t1),
      abs(x - *s2) + abs(*s2 - *t2),
      abs(x - *t1) + abs(*t1 - *s1),
      abs(x - *t1) + abs(*t1 - *s2),
      abs(x - *t2) + abs(*t2 - *s1),
      abs(x - *t2) + abs(*t2 - *s2)
    });
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2944
# -*- coding:utf-8 -*-

def solve():
    N, M = list(map(int, input().split()))
    As = list(map(int, input().split()))

    total = sum(As)

    if N - total < 0:
        print(-1)
    else:
        print(N-total)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 10048
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0) 
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x,y,z;
  string s,t;
  //

  // ここから
  IN(n);
  pair<pair<string,int>,int> p[110];
  REP(i,n) {
    string str;
    int tmp;
    IN2(str,tmp);
    p[i] = make_pair(make_pair(str, -tmp),i);
  }
  sort(p, p+n);
  REP(i,n){
    OUT(p[i].second+1);
  }
}

Measured memory_bytes: 256
a=[int(input()) for i in range(20)]
A=[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]]
x=sorted(A)
B=[a[10],a[11],a[12],a[13],a[14],a[15],a[16],a[17],a[18],a[19]]
y=sorted(B)
print(x[7]+x[8]+x[9],y[7]+y[8]+y[9])


Measured memory_bytes: 5600
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

signed main(){
/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/
  int N;
  cin >> N;

  int res = 0;
  if (N >= 400 && N <= 599) res = 8;
  else if (N >= 600 && N <= 799) res = 7;
  else if (N >= 800 && N <= 999) res = 6;
  else if (N >= 1000 && N <= 1199) res = 5;
  else if (N >= 1200 && N <= 1399) res = 4;
  else if (N >= 1400 && N <= 1599) res = 3;
  else if (N >= 1600 && N <= 1799) res = 2;
  else if (N >= 1800 && N <= 1999) res = 1;

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <ctime>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 1LL << 62
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    
    ll ans = 0;
    rep(k, K + 1) {
        for(int out = k; out >= 0; out--) {
            int in = k - out;
            if(out > N || in > N || out < in || out < 0) continue;
            for(int left = 0; left <= out; left++) {
                int right = out - left;
                vector<ll> B;
                rep(i, left) B.push_back(A[i]);
                rep(i, right) B.push_back(A[N - i - 1]);
                sort(all(B));
                ll tmp = 0;
                rep(j, B.size()) {
                    if(j < in) continue;
                    tmp += B[j];
                }
                ans = max(tmp, ans);
            }
        }
    }
    output(ans);
    
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL R, G, B, N;
	in >> R >> G >> B >> N;

	LL ans = 0;
	for (LL r = 0; r <= 3000; ++r)
	{
		for (LL b = 0; b <= 3000; ++b)
		{
			LL want = N - R * r - B * b;
			if (want < 0) continue;
			LL g = want / G;
			if (g * G == want) ++ans;
		}
	}
	out << ans << std::endl;
}


Measured memory_bytes: 764
//参考
//https://beta.atcoder.jp/contests/abc075/submissions/2602267
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    val s = mutableListOf<MutableList<Char>>()
    for (i in 1..h) {
        s.add(readLine()!!.toMutableList())
    }
    val d = listOf(-1 to 0, -1 to 1, 0 to 1, 1 to 1, 1 to 0, 1 to -1, 0 to -1, -1 to -1)
    for (y in 0..(h - 1)) {
        val line = mutableListOf<Char>()
        for (x in 0..(w - 1)) {
            if (s[y][x] == '#') {
                line.add('#')
                continue
            }
            var c = 0
            for ((dy, dx) in d) {
                if (y + dy !in 0..(h - 1)) {
                    continue
                }
                if (x + dx !in 0..(w - 1)) {
                    continue
                }
                if (s[y + dy][x + dx] == '#') {
                    c++
                }
            }
            line.add(c.toString().toCharArray()[0])
        }
        println(line.joinToString(separator = ""))
    }
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int ans = 0;
    for(int i=0;i<s.size()-t.size()+1;i++){
        int tmp = 0;
        int count = 0;
        for(int j=i;j<i+t.size();j++){
            if(t[tmp]==s[j]) count++;
            tmp++;
        }
        ans = max(count,ans);
    }
    cout<<t.size()-ans<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int t = 0;
  int x = 0;
  int y = 0;
  bool flag = true;

  int t1, x1, y1;
  while (cin >> t1 >> x1 >> y1) {
    int dt = t1 - t;
    int dx = x1 - x;
    int dy = y1 - y;
    int cost = abs(dx) + abs(dy);
    if (dt < cost || (dt - cost) % 2 != 0)
      flag = false;
    t = t1;
    x = x1;
    y = y1;
  }

  cout << (flag ? "Yes" : "No") << endl;
}


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

int main()
{
    long long int n,a[100006],dp[100006];
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)dp[i]=1e9;
    dp[1]=0; 
    for(int i=1;i<=n;i++){ 
        if(i+1<=n)dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        if(i+2<=n)dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
    } 
    cout<<dp[n]<<"\n";
     
     
     
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**6)


class UnionFind(object):
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        else:
            return False


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    uf = UnionFind(N)
    for i in range(M):
        uf.union(X[i]-1, Y[i]-1)
    cnt = 0
    for elem in uf.table:
        if elem < 0:
            cnt += 1
    print(cnt)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    Z = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14188
#include <stdio.h>

int main(void){
    int a,b,c,x,y,z;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a > b){
        x = a;
        a = b;
        b = x;
    }
    
    if(b > c){
        y = b;
        b = c;
        c = y;
    }
    
    if(a >b){
        z = a;
        a = b;
        b = z;
    }
    
    printf("%d %d %d\n",a,b,c);
    
    return 0;
}

Measured memory_bytes: 2716
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


int num[9];

void solve(){
  rep(i,9)cin>>num[i];
  vector<PI> in;
  rep(i,9){
    char ch;
    cin>>ch;
    in.pb(mp(ch,num[i]));
  }
  sort(ALL(in));

  do{
    bool ok=true;
    rep(i,3){
      if(in[i*3].F==in[i*3+1].F && in[i*3+1].F==in[i*3+2].F &&
         (in[i*3].S==in[i*3+1].S-1 && in[i*3+1].S==in[i*3+2].S-1 ||
          in[i*3].S==in[i*3+1].S && in[i*3+1].S==in[i*3+2].S))continue;
      ok=false;
      break;
    }
    if(ok){
      cout<<1<<endl;
      return;
    }
  }while(next_permutation(ALL(in)));

  cout<<0<<endl;
}

main(){
  int T;
  cin>>T;
  while(T--)solve();
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  ll n,k;
  cin >> n >> k;
  if(k>=n){
    if(k-n>=n) cout << n << endl;
    else cout << k-n << endl;
  }
  else{
    if((k-n%k)>= n%k)cout << n%k << endl;
    else cout << k-n%k << endl;
  }
 
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] S=sc.next().toCharArray();
        char[] T=sc.next().toCharArray();
        int[] Si=new int[S.length+1];
        int[] Ti=new int[T.length+1];
        Si[0]=0;
        for(int i=0;i<S.length;i++){
            Si[i+1]=Si[i]+S[i]-'A'+1;
        }
        Ti[0]=0;
        for(int i=0;i<T.length;i++){
            Ti[i+1]=Ti[i]+T[i]-'A'+1;
        }
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            int d=sc.nextInt();
            int result=0;
            result=Si[b]-Ti[d]-Si[a-1]+Ti[c-1];
            if(result%3==0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }

    }
}

Measured memory_bytes: 130196
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 8);
int main(){
  double ax, ay, bx, by, cx, cy;char c;
  cin>>ax>>c>>ay>>bx>>c>>by;
  double ans=0;
  while(cin>>cx>>c>>cy){
    double d1 = pow((pow(ax-bx, 2)+pow(ay-by, 2)), 0.5);
    double d2 = pow((pow(bx-cx, 2)+pow(by-cy, 2)), 0.5);
    double d3 = pow((pow(cx-ax, 2)+pow(cy-ay, 2)), 0.5);
    double z = (d1+d2+d3)*0.5;
    ans += pow((z*(z-d1)*(z-d2)*(z-d3)), 0.5);
    bx=cx;by=cy;
    // cout<<fixed<<setprecision(10)<<ans<<endl;
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3372
#include<cstdio>
#include<iostream>
#define maxn 300010
#define int long long
using namespace std;
int n,x,y,i,j,a[maxn],cnt;
signed main()
{
	scanf("%lld%lld%lld",&n,&x,&y);
	if(n<y+x-1||n>x*y)
	{
		puts("-1");
		return 0;
	}
	a[1]=y;
	for(i=2;i<=x;i++)
		a[i]=1;
	n-=y+x-1;
	for(i=2;i<=x;i++)
		if(y-1>n)
		{
			a[i]=n+1;
			break;
		}else
		{
			n-=y-1;
			a[i]=y;
		}
	for(i=1;i<=x;i++)
	{
		for(j=1;j<=a[i];j++)
			printf("%lld ",cnt+a[i]-j+1);
		cnt+=a[i];
	}
}

Measured memory_bytes: 4096
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()


end = [n]*n

for i in range(min(k, 41)):
    b = [0]*(n+1)
    for j in range(n):
        b[max(j-a[j], 0)] +=1
        if j+a[j] <n:
            b[j+a[j]+1] -=1
    for j in range(1,n):
        b[j] += b[j-1]
    a = b[:n]

for i in range(n):
    print(str(int(a[i]))+" ",end = "" )

Measured memory_bytes: 173144
n, k = map(int, input().split())

x = list(map(int, input().split()))

if k == 1:
    min_num = 10**20
    for i in x:
        if abs(i) < min_num:
            min_num = abs(i)
    print(min_num)
    exit()

min_dist = 10**20

dist = 0

for i in range(n-k+1):
    dist = (x[i+k-1] - x[i])
    dist += min(abs(x[i+k-1]), abs(x[i]))
    if dist < min_dist:
        min_dist = dist

print(min_dist)

Measured memory_bytes: 15628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int s_n = s.size(), t_n = t.size(), cnt = 0, ans = 1e9;
    for(int i=0; i<=s_n-t_n; i++){
        for(int j=0; j<t_n; j++){
            if(s[i+j]!=t[j]){
                cnt++;
            }
        }
        ans = min(cnt, ans);
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(type,var,n) vector<type> var((uint)n);loop(i,0,n)cin>>var[i];
#define linit(type,var,n) list<type> var;loop(i,0,n){type _v;cin>>_v;var.push_back(_v);}
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<(out)<<endl

const ull INF = (ull)(-1LL);

typedef int aint;

typedef vector<aint> vaint;
typedef list<aint> laint;

int main(void){
	init(aint, n);
	init(aint, m);

	vaint ans(n, -1);
	bool error = false;

	loop(i, 0, m){
		aint s, c;
		cin >> s >> c;
		s--;
		if (ans[s] != -1 && ans[s]!=c)error = true;
		ans[s] = c;
	}

	if (n > 1){
		if (ans[0] == 0)error = true;
		if (ans[0] == -1)ans[0] = 1;
	}
	if (error)outl(-1);
	else{
		loop(i, 0, n){
			cout << (ans[i] == -1 ? 0 : ans[i]);
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
    int m,n,row,col;
    for(;;) {
        scanf("%d %d",&m,&n);
         if(m == 0 && n == 0)
            break;
        for(row=1; row<=m; row++) {
            for(col=1; col<=n/2; col++) {

                if(row%2==0) {
                    printf(".");
                    printf("#");
                } else {
                    printf("#");
                    printf(".");
                }


            }
            if(n%2!=0) {
                if(row%2==0)
                    printf(".");
                else
                    printf("#");
            }
            printf("\n");
        }
        printf("\n");



    }
    return 0;
}





Measured memory_bytes: 2068
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;

const int MAXN = 100005;

int n;

ll a[MAXN];

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
		scanf("%lld",&a[i]);
	ll l = 2,r = 2;
	for (int i = n;i >= 1;i--)
	{
		ll nl = (l + a[i] - 1) / a[i] * a[i],nr = r / a[i] * a[i];
		if (nl > nr)
		{
			puts("-1");
			return 0;
		}
		l = nl;
		r = nr + a[i] - 1;
	}
	printf("%lld %lld\n",l,r);
	return 0;
}


Measured memory_bytes: 1024
L = int(input())
ans = []

# 頂点数はbitの長さ
N = len(bin(L)[2:])

# 頂点間に0の辺と2**iの辺を張る
for i in range(N - 1)[::-1]:
    ans.append([i + 1, i + 2, 2 ** (N - i - 2)])
    ans.append([i + 1, i + 2, 0])

# 表現できてないパスの個数
need = L - (2 ** (N - 1))

# 表現できてないコスト（大きい順）
cost = list(range(2 ** (N - 1), 2 ** (N -1) + need))

# コストのリスト上を移動するマーカー
marker = 0

# どこにバイパスを張るか
bit = bin(need)[2:][::-1]

# バイパスを張っていく
for i in range(len(bit)):
    if bit[i] != "1":
        continue

    # 辺を追加
    ans.append([1, N - i, cost[marker]])

    # マーカーを進める
    marker += 2 ** i

print(N, len(ans))
for a in ans:
    print(" ".join(map(str, a)))


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

int main() {
  /* code */
  int h, a;
  cin >> h >> a;
  int ans = h / a;
  if (h % a != 0) ans += 1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import math
import sys
import os
from operator import mul
import numpy as np
# import sympy

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
ans = 0

# 足し方の見方を変える。等差数列の和をKまで足す
# 1 + 2 + 3 + 4 +...
#   + 2     + 4 +...
for i in range(1,N+1):
    # Nを超えない整数
    y = N//i
    sum = y*(y+1)*i/2
    ans += sum

print(int(ans))





# 素数 エラトステネス
def seachPrimeNum(N):
   max = int(np.sqrt(N))
   seachList = [i for i in range(2,N+1)]
   primeNum = []
   while seachList[0] <= max:
       primeNum.append(seachList[0])
       tmp = seachList[0]
       seachList = [i for i in seachList if i % tmp != 0]
   primeNum.extend(seachList)
   return primeNum

# 約数
def divisor_count(n):
    divisors = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors += 1
            if i != n // i:
                divisors += 1

    return divisors

Measured memory_bytes: 27156
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

typedef struct tri{
	int index;
	int pref;
	int num;
	ll  year;
} T;

bool pairCompIndex(T& f, T& s)
{
	return f.index < s.index;
}

bool pairCompYear(T& f, T& s)
{
	return f.year < s.year;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<T> v(M);
	v.resize(M);
	vector<int> num(N, 0);

	for (int i = 0; i < M; i++) {
		v[i].index = i;
		cin >> v[i].pref >> v[i].year;
	}

	sort(v.begin(), v.end(), pairCompYear);

	for (int i = 0; i < M; i++) {
		v[i].num = ++num[v[i].pref];
	}

	sort(v.begin(), v.end(), pairCompIndex);

	for (int i = 0; i < M; i++) {
		printf("%06d%06d\n", v[i].pref, v[i].num);
	}
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll N,K;
    cin>>N>>K;
    vi A(N);
    rep(i,0,N)cin>>A[i],A[i]--;
    vb bit(64,false);
    ll highestbit=-1;
    rep(i,0,64){
        if((K>>i)&1){
            bit[i]=true;
            chmax(highestbit,i);
        }
    }
    vvll doubling(highestbit+1,vll(N,0));
    rep(i,0,N){
        doubling[0][i]=A[i];
    }
    rep(i,1,highestbit+1){
        rep(j,0,N)
            doubling[i][j]=doubling[i-1][doubling[i-1][j]];
    }
    int now=0;
    rep(i,0,highestbit+1){
        if(bit[i])now=doubling[i][now];
    }
    cout<<now+1<<endl;
    return 0;
}




Measured memory_bytes: 99152
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;


int main() {
	int l, r, d;
	cin >> l >> r >> d;
	int count = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			count ++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
string s,t;
int ss,tt;
int main(){
  cin>>s>>t;
  ss=s.size(),tt=t.size();
  bool a=false;
  for(int i=ss-tt;i>=0;i--){
    for(int j=0;j<tt;j++){
      if(s.at(i+j)!='?'&&s.at(i+j)!=t.at(j)){
        break;
      }
      if(j==tt-1)
        a=true;
    }
    if(a){
      for(int j=0;j<i;j++){
        cout<<(s.at(j)=='?'?'a':s.at(j));
      }
      cout<<t;
      for(int j=i+tt;j<ss;j++){
        cout<<(s.at(j)=='?'?'a':s.at(j));
      }
      return 0;
    }
  }
  cout<<"UNRESTORABLE";
}


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

int main() {
    string s;
    cin >> s;
    int a = s.size();
    if(s.at(a-1)=='s'){
        s.push_back('e');
        s.push_back('s');
    }
    else{
        s.push_back('s');
    }
    int b = s.size();
    for(int i=0;i<b;i++){
        cout << s.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 3632
/*
*
*   解説見てないお
*
*/
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

// combination
ll comb(ll n, ll r) {
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for (ll i = 0; i < (ll)v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (ll j = 1; j < (ll)v.size(); j++) {
        for (ll k = 1; k < j; k++) {
            v[j][k] = v[j - 1][k - 1] + v[j - 1][k];
        }
    }
    return v[n][r];
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    vector<ll> v(n);
    REP(i, n) scanf("%lld", &v[i]);
    sort(v.begin(), v.end());
    double ans = 0;
    REP(i, a) {
        ans += double(v[n - 1 - i]) / a;
    }
    printf("%.10f\n", ans);
    auto left = lower_bound(v.begin(), v.end(), v[n - a]);
    auto right = upper_bound(v.begin(), v.end(), v[n - a]);
    // [left,right) が v[a-1]
    // 全部同じ数字
    if (right == v.end()) {
        int cnt = right - left;
        ll ans = 0;
        FOR(i, a, b + 1) {
            if (cnt >= i) {
                ans += comb(cnt, i);
            }
            else {
                break;
            }
        }
        cout << ans << endl;
    }
    // 異なるのがあるならa個しかえらべない
    else {
        cout << comb(right - left, right - v.begin() - n + a) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
  
#define N 500000
  
void merge(int*, int, int);
  
int A[N],n,count=0;
int temp[N];
  
  
int main(){
  
  int i,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  
    merge(A,0,n-1);
  
  for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d",A[n-1]);
  printf("\n%d\n",count);
  
  return 0;
}
  
  
void merge(int A[],int left,int right){
  
  int mid,i,j,k;
  
  if(left>=right) return;
  
  mid=(left+right)/2;
  
  merge(A,left,mid);
  merge(A,(mid+1),right);
  
  for(i=left;i<=mid;i++){
    temp[i]=A[i];
  }
  
  for(i=(mid+1),j=right;i<=right;i++,j--){
    temp[i]=A[j];
  }
  
  i=left;
  j=right;
  
  for(k=left;k<=right;k++){
  
    if(temp[i]<=temp[j]) A[k]=temp[i++];
    else A[k]=temp[j--];
  
    count++;
}
  
}

Measured memory_bytes: 4504
import java.util.*;

public class Main {
 
	public static void main(String[] args) {
      Scanner sr = new Scanner(System.in);
      int N = sr.nextInt();
      int K = sr.nextInt();
      int p[] = new int[N];
      for(int i = 0;i<N;i++)
        p[i] = sr.nextInt();
      Arrays.sort(p);
      int sum = 0;
      for(int j = 0;j<K;j++)
        sum+=p[j];
      System.out.print(sum);
      
	}
}

Measured memory_bytes: 39052
n, k = map(int, input().split())

tmp = k
count = 0
while tmp > 1:
  tmp = tmp / 2
  count += 1

ret = 0
for i in range(1, n+1):
  goal = pow(2, count) * i
  offset = 0
  if i >= k:
    ret += (1/n)
  else:
    while goal >= k:
      goal = goal / 2
      offset += 1
    a = (1 / n) * pow(0.5, count - (offset-1))
    ret += a
print(ret)

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

ll solve(const string &S){
    int N = S.size();
    std::vector<ll> val(2019,0);
    ll fac = 1;
    ll cur = 0;
    val[cur]++;
    rep(i,N){
        ll add = S[N-1-i] -'0';
        cur = (cur+fac*add)%2019;
        val[cur]++;
        fac = (fac*10)%2019;
    }
    ll res = 0;
    rep(i,val.size()){
        res += val[i]*(val[i]-1)/2;
    }
    return res;
}

int main(){
    string S;
    cin >> S;
    cout << solve(S) << endl;
}


Measured memory_bytes: 3728