akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#define N 101
#define INF 2010
int n;

int A[N][N];
int color[N];
int d[N];

int mst(int root) {
    int totalW = 0;
    d[root] = 0;

    while(true) {
        int added = -1;
        int minw = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] == 0 && d[i] < minw) {
                added = i;
                minw = d[i];
            }
        }

        if (added == -1) {
            break;
        }

        totalW += minw;
        color[added] = 1;
        for (int i = 0; i < n; i++) {
            if (color[i] == 0 && A[added][i] < d[i]) {
                d[i] = A[added][i];
            }
        }
    }

    return totalW;
}

int main() {
    cin >> n;

    int w;
    for (int i = 0; i < n; i++) {
        color[i] = 0;
        d[i] = INF;
        for (int j = 0; j < n; j++) {
            cin >> w;
            if (w == -1) A[i][j] = INF;
            else A[i][j] = w;
        }
    }

    cout << mst(0) << endl;

    return 0;
}



Measured memory_bytes: 3116
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = ''.join(reversed(list(input())))
n = len(s)
ind = 0
flag = True
while ind+4 < n:
    if ind+5 < n and s[ind:ind+6] == 'resare':
        ind+=6
    elif ind+6 < n and s[ind:ind+7] == 'remaerd':
        ind+=7
    elif s[ind:ind+5] == 'maerd' or s[ind:ind+5] == 'esare':
        ind+=5
    else:
        flag=False
        break
if ind == n and flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 81540
import java.util.Scanner;

public class Main{
  
  public static void main(String[] args){
	  
	  Scanner scanner = new Scanner(System.in);
	  int n = scanner.nextInt();
	  scanner.close();
	  String ans = "No";
	  for (int i = 1; i <= 9; i++) {
		  if (n % i == 0) {
			  Integer c = n / i;
			  String dString = c.toString();
			  if (dString.length() == 1) {
				ans = "Yes";
				break;
			}
		}	
	}
	  System.out.println(ans);

  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s;
    cin>>s;
    rep(i,3){
        s[i]=10-(s[i]-'0')+'0';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b;
	cin>>a>>b;
	if(a>9||b>9){
		cout <<-1;
	}
	else{
		cout << a*b;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#define rep(i,j,k) for(register int i = j; i <= k; ++i)
#define dow(i,j,k) for(register int i = j; i >= k; --i)
#define ll long long
#define mp make_pair
#define fi first
#define se second 
#define all(x) x.begin(),x.end()
using namespace std;

inline ll read() { 
    ll s = 0, t = 1; char c = getchar();
    while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
    while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
    return s * t;
}

const int N = 1e5+5, inf = 1e9+7;
inline void Max(ll &x,ll v) { if( v > x ) x = v; }
ll v[N], ans = 0;

int main() {
	int n = read();
	rep(i,1,n) v[i] = read(); 
	sort(v+1,v+n+1);
	ll maxl = 0;
	for(register int r = n, l; r >= 1; r = l) { 
		l = r;
		while( l >= 1 && v[r] == v[l] ) l--;
		if( r - l >= 2 ) { 
			if( r - l >= 4 ) Max(ans,v[r]*v[r]);
			Max(ans,maxl*v[r]), Max(maxl,v[r]);
		} 
	}
	cout<<ans<<endl;
    return 0;
}

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

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    int tmp=0;
    for(int i; i<3; i++){
        if(s.at(i)==t.at(i)) {
            tmp++;
        }
    }
    cout<< tmp;
}

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

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

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

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

	cout << max(a-b,max(a+b,a*b)) << endl;

	return 0;

}


Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var list = new Array(3);
  for(var i = 0; i < 3; i++){
    list[i] = nextIntArray();
  }
  var N = nextInt();
  for(var i = 0; i < N; i++){
    var bi = nextInt();
    for(var j = 0; j < 3; j++){
      for(var k = 0; k < 3; k++){
        if(list[j][k] == bi){
          list[j][k] = -1;
        }
      }
    }
  }
  if((list[0][0] == -1 && list[0][1] == -1 && list[0][2] == -1) || 
    (list[1][0] == -1 && list[1][1] == -1 && list[1][2] == -1) || 
    (list[2][0] == -1 && list[2][1] == -1 && list[2][2] == -1) || 
    (list[0][0] == -1 && list[1][0] == -1 && list[2][0] == -1) || 
    (list[0][1] == -1 && list[1][1] == -1 && list[2][1] == -1) || 
    (list[0][2] == -1 && list[1][2] == -1 && list[2][2] == -1) || 
    (list[0][0] == -1 && list[1][1] == -1 && list[2][2] == -1) || 
    (list[2][0] == -1 && list[1][1] == -1 && list[0][2] == -1)){
    myout("Yes");
  }else{
    myout("No");
  }
}

Measured memory_bytes: 29924
#include <iostream>
#define SIZE 100000
#define NIL -1
using namespace std;

typedef struct
{
    int parent, left, right;
} Tree;

Tree T[SIZE];

int GetDepth(int id)
{
    int depth = 0;
    while (T[id].parent != NIL)
    {
        depth++;
        id = T[id].parent;
    }

    return depth;
}

void CheckStatus(int id)
{
    if (T[id].parent == NIL)
    {
        cout << "root, ";
        return;
    }

    if (T[id].left == NIL)
    {
        cout << "leaf, ";
        return;
    }

    cout << "internal node, ";
}

void Print(int n)
{
    //idと子のみ
    for (int i = 0; i < n; i++)
    {
        cout << "node " << i << ": ";

        //親
        cout << "parent = " << T[i].parent << ", ";

        //深さ
        cout << "depth = " << GetDepth(i) << ", ";

        //属性
        CheckStatus(i);

        //子
        cout << "[";

        if (T[i].left == NIL)
        {
            cout << "]" << endl;
            continue;
        }

        cout << T[i].left;
        int id = T[i].left;
        while (T[id].right != NIL)
        {
            cout << ", " << T[id].right;
            id = T[id].right;
        }
        cout << "]" << endl;
    }
}

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

    int n, k;
    int parent;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        T[i].parent = T[i].right = T[i].left = NIL;
    }

    for (int i = 0; i < n; i++)
    {
        int id;
        cin >> parent >> k;
        id = parent;

        if (k != 0)
        {
            cin >> T[id].left;
            id = T[id].left;
            T[id].parent = parent;
        }

        for (int j = 0; j < k - 1; j++)
        {
            cin >> T[id].right;
            id = T[id].right;
            T[id].parent = parent;
        }
    }

    Print(n);

    return 0;
}



Measured memory_bytes: 4284
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();

		StringBuilder sb = new StringBuilder(((ty - sy) + (tx - sx)) * 4 + 8);
		for (int y = sy; y < ty; y++) {
			sb.append('U');
		}
		for (int x = sx; x < tx; x++) {
			sb.append('R');
		}
		for (int y = sy; y < ty; y++) {
			sb.append('D');
		}
		for (int x = sx; x < tx; x++) {
			sb.append('L');
		}

		sb.append('L');
		for (int y = sy; y < ty + 1; y++) {
			sb.append('U');
		}
		for (int x = sx; x < tx + 1; x++) {
			sb.append('R');
		}
		sb.append('D');

		sb.append('R');
		for (int y = sy; y < ty + 1; y++) {
			sb.append('D');
		}
		for (int x = sx; x < tx + 1; x++) {
			sb.append('L');
		}
		sb.append('U');

		System.out.println(sb);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}
}


Measured memory_bytes: 9932
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define MAXN 1000005
#define mo 999999137
#define pb push_back
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
const int MOD = 998244353;
int fac[4005],inv[4005],invfac[4005],N,K,vis[4005],pw[4005];
int dp[4005][4005];
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int C(int n,int m) {
    if(n < m) return 0;
    if(n < 0 || m < 0) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
        if(c & 1) res = mul(res,t);
        t = mul(t,t);
        c >>= 1;
    }
    return res;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    inv[1] = 1;pw[0] = 1;
    for(int i = 2 ; i <= 4000 ; ++i) {
        inv[i] = mul(inv[MOD % i],MOD - MOD / i);
    }
    fac[0] = invfac[0] = 1;
    for(int i = 1 ; i <= 4000 ; ++i) {
        fac[i] = mul(fac[i - 1],i);invfac[i] = mul(invfac[i - 1],inv[i]);
        pw[i] = mul(pw[i - 1],2);
    }
    read(K);read(N);
    dp[0][1] = 1;
    for(int i = 1 ; i <= N ; ++i) dp[i][1] = 2;
    dp[0][0] = 1;
    for(int j = 2 ; j <= K ; ++j) {
        int s = 1;
        dp[0][j] = 1;
        for(int i = 1 ; i <= N ; ++i) {
            dp[i][j] = inc(mul(s,2),dp[i][j - 1]);
            s = inc(s,dp[i][j - 1]);
        }
    }
    for(int i = 2 ; i <= 2 * K ; ++i) {
        int cnt = 0,t = 0,rest = 0;
        memset(vis,0,sizeof(vis));
        for(int j = 1 ; j <= K ; ++j) {
            if(!vis[j] && j != i - j && i - j >= 1 && i - j <= K) {vis[j] = vis[i - j] = 1;++cnt;}
        }
        if(i % 2 == 0) ++t;
        rest = K - cnt * 2 - t;
        int ans = 0;
        for(int j = N ; j >= 0 ; --j) {
            ans = inc(ans,mul(dp[j][cnt],rest ? C(N - j - 1 + rest,rest - 1) : (N - j == 0)));
        }
        if(t) {
            for(int j = N - 1; j >= 0 ; --j) {
                ans = inc(ans,mul(dp[j][cnt],rest ? C(N - 2 - j + rest,rest - 1) : (N - 1 - j == 0)));
            }
        }
        out(ans);enter;
    }
    return 0;
}


Measured memory_bytes: 32640
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

int A,P;

int main() {

	scanf("%d%d", &A,&P);



	printf("%d\n", (A*3+P)/2);

	return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
int pre[40],in[40];
void post(int l1,int r1,int l2,int r2){
	int root;
	for(root=l2;root<=r2;root++)
	if(in[root]==pre[l1])
	break;
	if(l2<root)	
	post(l1+1,l1+root-l2,l2,root-1);
	if(root<r2)
	post(l1+root-l2+1,r1,root+1,r2);
	printf(in[root]==pre[0]?"%d\n":"%d ",in[root]);
}
int main(int argc, char *argv[])
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&pre[i]);
	for(i=0;i<n;i++)
	scanf("%d",&in[i]);
	post(0,n-1,0,n-1);
	return 0;
}

Measured memory_bytes: 1856
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

void err() {
	puts(-1);
	exit(0);
}

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

	int N;
	cin >> N;
	vector<int>b(N);
	for (int i = 0; i < N; i++)cin >> b[i];

	vector<int>ans;
	while (b.size()) {
		int ok = 0;
		for (int i = b.size() - 1; i >= 0; i--) {
			if (i + 1 == b[i]) {
				ans.pb(b[i]);
				b.erase(b.begin()+i);
				ok = 1;
				break;
			}
		}
		if (!ok)err();
	}

	for (int i = ans.size() - 1; i >= 0; i--)puts(ans[i]);

	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000000LL;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  while (scanf("%d", &n) == 1) {
    int space = 0;
    while (n > 0) {
      int x = n & -n;
      if (space) {
        printf(" ");
      }
      else {
        space = 1;
      }

      printf("%d", x);
      n -= x;
    }
    printf("\n");
  }
  return (0);
}

Measured memory_bytes: 600
#include <stdio.h>
#define NUM 100


int main(void){
	char color[NUM][1];
	int i;
	int n;

	scanf("%d", &n);

	for (i = 0 ;i < n;i++) {
		scanf("%s", color[i]);
	}
	
	for (i = 0;i < n;i++) {
		if (color[i][0] == 'Y')
			break;
	}


	if (i == n)
		printf("Three\n");
	else
		printf("Four\n");

	return 0;
}

Measured memory_bytes: 128
def knapsack_val(W, items):
    '''
        W (int): the capacity of a knapsack
        items (list of tuples): i-th element is a tuple (weight, value)
    '''
    N = len(items)
    INF = 10**12
    MAX_V = sum([v for _, v in items])
    # dp[n][v] = the minimum weight when the total value is v and only items 1, 2, ..., n are used.
    dp = [[INF for j in range(MAX_V+1)] for i in range(N+1)]
    dp[0][0] = 0
    for i in range(1, N+1):
        w, v = items[i-1]
        for j in range(MAX_V+1):
            if j - v >= 0:
                dp[i][j] = min(dp[i-1][j-v] + w, dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    for v in range(MAX_V, -1, -1):
        if dp[N][v] <= W:
            break
    return v

N, W = map(int, input().split())
items = []
for _ in range(N):
    v, w = map(int, input().split())
    items.append((w, v))
print(knapsack_val(W, items))


Measured memory_bytes: 14088
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  using ll = long long;
  ll a,b;
  cin>>a>>b;

  const Int LOG = 62;

  if(a==b) drop(1);
  ll m=0;
  while(1){
    m=0;
    for(Int k=0;k<LOG;k++)
      if((b>>k)&1) m=k;
    if((1LL<<m)<=a){
      a-=1LL<<m;
      b-=1LL<<m;
    }else{
      break;
    }
  }

  for(Int k=m-1;k>0;k--)
    if((b>>k)&1) b|=1LL<<(k-1);

  // [a, 2^m)
  ll ans=(1LL<<m)-a;

  ll c=(1LL<<m)|a;
  if(b<c){
    // [2^m, b]
    ans+=b-(1LL<<m)+1;
    // [c, 2^{m+1} )
    ans+=(2LL<<m)-c;
  }else{
    // [2^m, 2^{m+1} )
    ans+=1LL<<m;
  }

  // cout<<a<<" "<<b<<endl;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
<?php
/*dskhbfjkhs*/
$server = "php://stdin";
$handle = fopen($server, "r");
$n = trim(fgets($handle));
$n=explode(' ',$n);
$loop = 1;
$multi = 1;
$greater = max($n[0],$n[1]);
$less = min($n[0],$n[1]);
while($loop === 1) {
    if(($greater * $multi) % $less === 0) {
        $loop = 0;
        break;
    } else {
        $multi++;
    }
}
echo $greater * $multi;
?>

Measured memory_bytes: 4604
#include <stdio.h>

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

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
"""
"""
# 


def main():
    x, a, b = [int(x) for x in input().split(' ')]
    dist_A = abs(x - a)
    dist_B = abs(x - b)
    if dist_A > dist_B:
        print('B')
    else:
        print('A')


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int i=1; 
        Scanner sc = new Scanner(System.in);        
        while(true){            
            int a = sc.nextInt();
            if(a == 0) break;
            System.out.println("Case "+i+": "+a);          
            i++;
        } 
        sc.close();
    }
}


Measured memory_bytes: 41544
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()){cout << vec[i] << " ";} print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

void solve(){
	
	ll N, K, ans, mod, cnt, nx, loop_cnt;
	cin >> N >> K;
	vl A(N);
	rep(i, N) cin >> A[i];
	rep(i, N) A[i] -= 1;
	
	vl visited(N, -1);
	vl v(0);
	cnt = 0;
	nx = 0;
	while(visited[nx] < 0){
		v.push_back(nx);
		visited[nx] = cnt;
		nx = A[nx];
		cnt += 1;
	}
	if(cnt > K) ans = v[K];
	else{
		loop_cnt = cnt - visited[nx];
		mod = (K - cnt) % loop_cnt;
		ans = v[visited[nx] + mod];
	}
	print(ans + 1);
	
}	

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


Measured memory_bytes: 8428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << a << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,q,t,l,r,pos;string s;char c;cin>>n>>s>>q;
  ll len=s.length();
  vector<set<ll>> alp(26);
  lvector ans;
  rep(i,len) alp[s[i]-'a'].insert(i);
  rep(i,q) {
    cin>>t;
    if(t==1) {
      cin>>pos>>c;pos--;
      alp[s[pos]-'a'].erase(pos);
      s[pos]=c;
      alp[c-'a'].insert(pos);
    }
    else {
      cin>>l>>r;l--,r--;
      ll ans_=0;
      rep(a,26) {
        auto itr=alp[a].lower_bound(l);
        if(itr!=alp[a].end()&&*itr<=r) ans_++;
      }
      ans.emplace_back(ans_);
    }
  }
  for(ll e:ans) print(e);
  return 0;
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

const int MAX_N = 105;
int n;
ll arr[MAX_N];

int main() { FAST
    cin >> n;
    int cnt = 0;
    M00(i, n) cin >> arr[i];
    M00(a, n) {
        MOO(b, a+1, n) {
            MOO(c, b+1, n) {
                if(arr[a] == arr[b] || arr[a] == arr[c] || arr[b] == arr[c]) continue;
                if(arr[a] + arr[b] <= arr[c]) continue;
                if(arr[a] + arr[c] <= arr[b]) continue;
                if(arr[b] + arr[c] <= arr[a]) continue;
                cnt++;
            }
        }
    }
    finish(cnt);
}



Measured memory_bytes: 3636
N, M = list(map(int, input().split()))
edge = [[0] * N for i in range(N)] # 辺を行列で表す
for i in range(M):
    a, b = list(map(int, input().split()))
    edge[a-1][b-1] = 1
    edge[b-1][a-1] = 1

def dfs(v, n, visited):
    all_visited = True

    for i in range(N):
        if visited[i] == False:
            all_visited = False

    if all_visited == True:
        return 1

    ret = 0

    for i in range(N):
        if edge[v][i] == 0: # 繋がってない
            continue
        if visited[i]: # 訪問済み
            continue

        visited[i] = True
        ret += dfs(i, N, visited)
        visited[i] = False

    return ret

# 訪問したかどうかのフラグ（最初はFalse）
visited = [False] * N

visited[0] = True
re = dfs(0, N, visited)
print(re)

Measured memory_bytes: 3188
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $s = $sc->next();



} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $s = 'erasedreamdreamer';



}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

$pieces = array('dream','dreamer','erase','eraser');

$ng_count = 0;
$ans = 'YES';
while (strlen($s) > 0) {
  foreach ($pieces as $piece) {
    if (substr($s, -strlen($piece)) == $piece) {
      $s = substr($s, 0, strlen($s) - strlen($piece));
      $ng_count = 0;
    } else {
      $ng_count++;
      if ($ng_count == 10) { $ans = 'NO'; break 2; }
    }
  }
}




//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


Measured memory_bytes: 3980
import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val an = Array.fill(N)(sc.nextInt)
  val idxs = Array.range(1, N + 1)
  val map: mutable.Map[Int, Int] = mutable.Map()
  var cnt = 0

  for (i <- idxs) {
    if (an(i - 1) == i) {
      if (i < N) {
        val t = an(i - 1)
        an(i - 1) = an(i)
        an(i) = t
        cnt = cnt + 1
      } else {
        cnt = cnt + 1
      }
    }
  }

  println(cnt)

}


Measured memory_bytes: 53984
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=300010;

ll calc(ll x){
	return x*x*x*x*x;
}

int main(){
	ll x;
	cin>>x;
	for(ll a=-1000;a<1001;a++){
		ll target=x-a*a*a*a*a;
		ll left=-1000, right=1000, middle=(left+right)/2;
		while(left!=middle && right!=middle){
			middle=(left+right)/2;
			if(calc(middle)<target){
				left=middle;
				middle=(right+left)/2;
			}else{
				right=middle;
				middle=(right+left)/2;
			}
		}
		if(calc(right)==target){
			cout<<a<<" "<<-right<<endl;
			return 0;
		}
		if(calc(middle)==target){
			cout<<a<<" "<<-middle<<endl;
			return 0;
		}
		if(calc(left)==target){
			cout<<a<<" "<<-left<<endl;
			return 0;
		}
	}
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int A, B; cin >> A >> B;
    string S; cin >> S;
    string ans = "Yes";
    if(S.size() != A + B + 1) ans = "No";
    else {
        for(int i = 0; i < S.size(); i++) {
            if(i != A && S[i] == '-') {
                ans = "No";
                break;
            }
            else if (i == A && S[i] != '-') {
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
func main() {
    let inputs = readLine()!.split(separator: " ")
    let N = Int(inputs[0])!
    let K = Int(inputs[1])!
    var nums = Array(repeating: 0, count: N)
    for _ in 0..<K {
        let _ = readLine()!
        let A = readLine()!.split(separator: " ").map { Int($0)! }
        for a in A {
            nums[a - 1] += 1
        }
    }
    let output = nums.filter { $0 == 0 }.count
    print(output)
}

main()

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

int card[255][14] = {{0}};

int main(void){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        char c; //文字コードは0~255
        int num;
        cin >> c >> num;
        card[(int)c][num] = 1; //発見
    }
    //Sを探す
    for(int i = 1; i <= 13; i++) {
        if(card[(int)'S'][i] == 0) { 
            cout << "S " << i << endl;
        }
    }
    //Hを探す
    for(int i = 1; i <= 13; i++) {
        if(card[(int)'H'][i] == 0) { 
            cout << "H " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++) {
        if(card[(int)'C'][i] == 0) { 
            cout << "C " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++) {
        if(card[(int)'D'][i] == 0) { 
            cout << "D " << i << endl;
        }
    }
    
}


Measured memory_bytes: 3096
l = [0,0,0,0,0]
for i in range(5):
    l[i] = int(input())
k = int(input())
for i in range(5):
    for j in range(i,5):
        if abs(l[i] - l[j]) > k:
            print(":(")
            exit()

print("Yay!")

Measured memory_bytes: 3060
#include<stdio.h>
#define N 200

int appear(int map[N*2][N*2],int vector){
  int i,j;

  if(vector==0){
    for(i=0;i<N*2;i++)
      for(j=0;j<N*2;j++)
        if(map[i][j])
          return i;
  } else if(vector==1){
    for(i=N*2-1;i>=0;i--)
      for(j=0;j<N*2;j++)
        if(map[i][j])
          return i;
  } else if(vector==2){
    for(j=0;j<N*2;j++)
      for(i=0;i<N*2;i++)
        if(map[i][j])
          return j;
  } else if(vector==3){
    for(j=N*2-1;j>=0;j--)
      for(i=0;i<N*2;i++)
        if(map[i][j])
          return j;
  }
  return 0;
}

int main(void){
  int i,j;
  int n;
  int box[N][2],pos[N][2];
  int map[N*2][N*2];
  int curX,curY;

  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;

    for(i=0;i<n-1;i++)
      scanf("%d%d",&box[i][0],&box[i][1]);

    for(i=0;i<N*2;i++)
      for(j=0;j<N*2;j++)
        map[i][j]=0;

    pos[0][0]=N;
    pos[0][1]=N;
    map[pos[0][0]][pos[0][1]]=1;

    for(i=1;i<n;i++){
      pos[i][0]=pos[box[i-1][0]][0];
      pos[i][1]=pos[box[i-1][0]][1];

      if(box[i-1][1]==0){
        pos[i][1]--;
      } else if(box[i-1][1]==1){
        pos[i][0]++;
      } else if(box[i-1][1]==2){
        pos[i][1]++;
      } else if(box[i-1][1]==3){
        pos[i][0]--;
      }

      map[pos[i][0]][pos[i][1]]=i+1;
    }

    printf("%d ",(appear(map,2)>=appear(map,3))?
        appear(map,2)-appear(map,3)+1:appear(map,3)-appear(map,2)+1);

    printf("%d\n",(appear(map,0)>=appear(map,1))?
        appear(map,0)-appear(map,1)+1:appear(map,1)-appear(map,0)+1);
  }

  return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long f[1000005][2];
int main()
{
	char ss[100005];
	cin >> ss+1;
	f[0][1]=1;
	f[0][0]=0;
	int n=strlen(ss+1);
	for(int i=1;ss[i];i++)
	{
		f[i][0]=(f[i-1][0]*3)%mod;
		if(ss[i]=='1')
		{
			f[i][1]=(f[i-1][1]*2)%mod;
			f[i][0]+=f[i-1][1];
			f[i][0]=(f[i][0])%mod;
		}
		else
		{
			f[i][1]=f[i-1][1];
		}
	}
	printf("%lld\n",(f[n][1]+f[n][0])%mod);
}


Measured memory_bytes: 5404
class String
    def affine_one (alpha, beta)
        raise 'exception' unless self.size == 1
        return self if self == ' '
        [(((self.bytes.to_a[0]-97) * alpha + beta) % 26) + 97].pack("C")
    end
    def affine (alpha, beta)
        self.scan(/./).map{|x| x.affine_one alpha,beta}.join
    end
    def deaffine_one (alpha, beta)
        raise 'exception' unless self.size == 1
        return self if self == ' '
        [[*'a'..'z'].join.affine(alpha,beta).index(self) + 97].pack("C")
            
        #[26.lcm((self.bytes.to_a[0] - 97) - beta)  / alpha + 97].pack("C")
    end
    def deaffine (alpha, beta)
        self.scan(/./).map{|x| x.deaffine_one alpha,beta}.join
    end
end

n = gets.to_i
n.times do
    str = gets.chomp

    alpha = 1; beta = nil; passed = false
    loop do
        (alpha += 2; redo)if alpha == 13

        (0..25).each do |beta|
            passed = true if str.include?('that'.affine(alpha, beta))
            passed = true if str.include?('this'.affine(alpha, beta))
            puts str.deaffine(alpha, beta) if passed
            break if passed
        end
        break if passed
        alpha += 2
    end

end

Measured memory_bytes: 6176
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e5+10;
void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=0; i<=n; i++)		
		ans+=(n-i)*(i+1);
	for(ll i=1;i<=n-1;i++)
	{
		ll l,r;
		cin>>l>>r;
		if(l>r)
			swap(l,r);
		ans-=l*(n-r+1);
	}
	cout<<ans<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 3624
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int cnt = 0;
        int placeNum = String.valueOf(N).length();
        for (int i = 1; i < placeNum; i++) {
            if (i % 2 == 1) cnt += 9 * Math.pow(10, i - 1);
        }

        if (placeNum % 2 == 1) cnt += N - Math.pow(10, placeNum - 1) + 1;

        System.out.println(cnt);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007

int main(){
	int N; cin>>N;
	vl A(N); rp(i,0,N) cin>>A[i];
	ll ans = 0;
	rp(i, 0, 60){
		ll z=0,o=0; rp(j,0,N) if(A[j]>>i&1) o++; else z++;
		ans = (ans+(z * o % MOD) * ((1LL << i) % MOD)) %MOD;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main{
 	public static void main(String[] args){
     	Scanner sc = new Scanner(System.in);
      	char[] s = sc.next().toCharArray();
      	for(int i = 1; i < s.length; i++){
         	 if(s[i] == s[i-1]){
              	System.out.println("Bad");
               	return;
             }
        }
        System.out.println("Good");
    }
}

Measured memory_bytes: 21588
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if dp[step] > v:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()


Measured memory_bytes: 20616
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
#include<cctype>
#include<unordered_map>
#include<complex>
#pragma warning(disable:4996)
using namespace std;

#define debug(i) cout<<"<debug> "<<#i<<" "<<i<<" <\\debug>"<<endl
#define mfor(i,a,b) for(int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(int i=(a);i>=(b);i--)
#define lll __int128
#define Re register
#define mem(a,b) memset(a,(b),sizeof(a))
#define Design ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
typedef pair<int, int> intpair;
typedef pair<long long int, long long int> llpair;
typedef long long int ll;
const double pi = acos(-1);
const double eps = 1e-5;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 2000010;
ll fac[maxn];
ll inv[maxn];

long long fpow(long long a, long long n, long long mod)
{
    if (n == 0)        return 1;
    else if (n & 1) return a * fpow(a, n - 1, mod) % mod;
    else
    {
        long long num = fpow(a, n / 2, mod) % mod;
        return num * num % mod;
    }
}

void getfacinv(int n, ll mod)
{//初始化fac和inv数组，获取1!-n!和相应的逆元
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
    inv[n] = fpow(fac[n], mod - 2, mod);
    for (int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1LL) % mod;
}

ll com(ll a, ll b, ll mod)
{
    //计算组合数
    if (a < b) return 0;
    return fac[a] * fpow(fac[b], mod - 2, mod) % mod * fpow(fac[a - b], mod - 2, mod) % mod;
}

const ll mod = 1e9 + 7;

ll decm(ll a, ll b)
{
    return ((a - b) % mod + mod) % mod;
}

int main()
{
	Design;
    getfacinv(1e6, mod);
    ll s;
    cin >> s;
    ll ans = 0;
    mfor(i, 1, s / 3)
    {
        ans += com(i + s - i * 3 - 1, s - i * 3, mod);
        ans %= mod;
    }
    cout << ans;
}

Measured memory_bytes: 19248
#include <bits/stdc++.h>
using namespace std;
const long long INF=2e9;
int main() {
    int n;
    cin >> n;
    vector<array<long long,2>> d={{-INF,INF},{-INF,INF}};
    for ( int i=0; i<n; i++ ) {
        long long x,y;
        cin >> x >> y;
        for ( int j=0; j<2; j++ ) {
            long long v=x+y;
            d[j][0]=max(d[j][0],v);
            d[j][1]=min(d[j][1],v);
            y*=-1;
        }
    }
    cout << max(d[0][0]-d[0][1], d[1][0]-d[1][1]);
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	ll n, i, tmp;
	cin >> n;
	unordered_map<ll, ll> mp, patterns;
	vector<ll> a(n);
	vector<ll> answer(n);
	
	ll pattern = 0;

	for (i = 0; i < n; i++) {
		cin >> tmp;
		a[i] = tmp;
		if (mp.find(tmp) == mp.end()) 
			mp[tmp] = 1;
		else
			mp[tmp]++;
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		patterns[itr->first] = itr->second * (itr->second - 1) / 2;
		pattern += patterns[itr->first];
	}

	for (i = 0; i < n; i++) {
		tmp = pattern - patterns[a[i]];
		tmp += (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2;
		answer[i] = tmp;
	}

	for (i = 0; i < n; i++)
		cout << answer[i] << endl;
			

	return 0;
}


Measured memory_bytes: 17608
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
	int sum = 0;
    for(int i = 0 ; i < M ; i++){
      sum += sc.nextInt();
    }
      if(N < sum)
        System.out.println(-1);
      else 
        System.out.println(N - sum);
        
	
	}
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()


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

  int N;
  cin>>N;
  // now,back,back2,back3
  using vec1=vector<int>;
  using vec2=vector<vec1>;
  using vec3=vector<vec2>;
  using vec4=vector<vec3>;
  vec4 dp(N+1,vec3(5,vec2(5,vec1(5,0))));
  // AGC
  // ACG
  // GAC
  // A.GC
  // AG.C
  // 1->A 2->G 3->C 4->T
#define A 1
#define G 2
#define C 3
#define T 4
  dp[0][0][0][0]=1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<5;j++){
      for(int k=0;k<5;k++){
        for(int l=0;l<5;l++){
          for(int x=1;x<5;x++){
            if(x==C&&j==G&&k==A){}
            else if(x==G&&j==C&&k==A){}
            else if(x==C&&j==A&&k==G){}
            else if(x==C&&j==G&&l==A){}
            else if(x==C&&k==G&&l==A){}
            else dp[i][x][j][k]+=dp[i-1][j][k][l]%MOD;
            dp[i][x][j][k]%=MOD;
          }
        }
      }
    }
  }

  ll ans=0;
  for(int j=0;j<5;j++){
    for(int k=0;k<5;k++){
      for(int l=0;l<5;l++){
        ans+=dp[N][j][k][l]%MOD;
        ans%=MOD;
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
double a,b,c;
int v;
scanf("%lf",&a);
scanf("%lf",&b);
c=(a+b)/2;
v=c*10;
if(v%10>0){
printf("%d\n",(int)c+1);
}else{
printf("%d\n",(int)c);}
return 0;

}

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

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    
    int N;
    cin >> N;
    bool good = true;
    for (int i =0 ; i < N; i++)
    {
        int x; cin >> x;
        if (x % 2 == 0 && (x % 3 != 0 && x % 5 != 0))
            good = false;
    }
    if (good)
        cout << "APPROVED\n";
    else
        cout << "DENIED\n";
}

Measured memory_bytes: 256
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,f[100005];
vector<int> v[100005];
int get(int x){
    for(int i=18;i>=0;--i)if(x&(1<<i)) return i;
    return -1;
}
void solve(int x,int y){
    int o=-1;
    for(int i=0;i<v[x].size();++i){
        if(v[x][i]==y) continue;
        solve(v[x][i],x);
        o=max(o,get(f[x]&f[v[x][i]]));
        f[x]|=f[v[x][i]];
    }
    for(int i=0;i<=18;++i){
        if(i<=o||(f[x]&(1<<i)))f[x]=(f[x]|(1<<i))^(1<<i);
        else f[x]|=(1<<i),i=19;
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].pb(y),v[y].pb(x);
    }
    solve(1,0);
    printf("%d\n",get(f[1]));
    //system("pause");
    return 0;
}


Measured memory_bytes: 11776
// AOJ 2234 Usagitobi
// 2018.2.11 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef long long Int;

Int dd[10000]; int sz;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

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

Int lcm(int a, int b) {	return a/gcd(a, b)*(Int)b; }

int extended_gcd(int a, int b, int *x, int *y) { int d;
	if (b == 0) { *x = 1; *y = 0; return a; }
	d = extended_gcd(b, a%b, y, x), *y -= a / b * (*x); return d;
}

int inverse(int a, int M) {	int x, y;
    extended_gcd(a, M, &x, &y); return (x + M) % M; }

int cmp(Int *a, Int *b) {
	if (*a == *b) return 0;	if (*a < *b) return -1;	return 1;
}

int main()
{
	int m, n, a, b, c, d;
	int i, s, g, ga, gb;
	Int u, v, mn, p, q;

	m = in(), n = in(), a = in(), b = in(), c = in(), d = in();

	sz = 0; mn = (Int)m*n;
	s = (int)sqrt((double)mn);
	if ((Int)s*s == mn) dd[sz++] = s; 
	for (i = 1; i < s; i++) {
		if (!(mn % i)) dd[sz++] = i, dd[sz++] = mn/i;
	}
	qsort(dd, sz, sizeof(Int), cmp);

	ga = gcd(m, a), gb = gcd(n, b);
	u = lcm(m/ga, n/gb);
	for (i = 0; i < sz; i++) {
		v = dd[i];
		if (v*c % ga || v*d % gb) continue;

		p = (v*c/ga) * inverse(a/ga, m/ga);
		q = (v*d/gb) * inverse(b/gb, n/gb);

		g = gcd(m/ga, n/gb);
		if (p%g == q%g) { printf("%lld\n", u*v-1); break; }
	}
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#define rep(i,n) for(int i = 0; i <n; ++i)
using namespace std;
typedef long long ll;


int main() {

	int n,k;
	cin>>n>>k;
	vector<int> p(n+10,100000);
	for (int i = 1; i <= n; ++i)
	{
		cin>>p[i];
	}

	sort(p.begin(),p.end());
	
	int sum=0;
	
	for (int i = 0; i <=k-1; ++i)
	{
		sum+=p[i];

	}
	cout<<sum<<endl;

return 0;
}



Measured memory_bytes: 3556
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
AB = np.array([lr() for _ in range(N)], dtype=np.int64)
A = AB[:, 0]
B = AB[:, 1]
answer = 0

def F(x):
    global answer
    #bitごとで全てxに含まれる
    index = np.where((A|x) <= x)[0]
    if index is not None:
        if np.sum(B[index]) > answer:
            answer = B[index].sum()

cur = 0
F(K)
for i in range(K.bit_length()-1, -1, -1):
    if (((1 << i) & K) >> i) & 1:
        F(cur + ((1<<i) - 1))
        cur += (1<<i)

print(answer)
# 06

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

int a[303030];
int st[303030];
int del[303030];
deque<int> Q;
void check(int nxt, int now)
{
	if(st[now] + (!del[now]) < st[nxt])
	{
		st[nxt] = st[now] + (!del[now]);
		if(del[nxt])
			Q.push_front(nxt);
		else
			Q.push_back(nxt);
	}
} 
int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 0; i < N * N; i++)
	{
		scanf("%d", &a[i]);
		a[i]--;
		st[i] = min(min(i/N, N - 1 - i/N), min(i%N, N - 1 - i%N));
	}
	int ans = 0;
	for(int i = 0; i < N * N; i++)
	{
		ans += st[a[i]];
		del[a[i]] = 1;
		Q.push_back(a[i]);
		while(!Q.empty())
		{
			int now = Q.front();
			Q.pop_front();
			int nxt = -1;
			if(now % N > 0)
			{
				nxt = now - 1;
				check(nxt, now);
			}
			if(now % N < N - 1)
			{
				nxt = now + 1;
				check(nxt, now); 
			}
			if(now / N > 0)
			{
				nxt = now - N;
				check(nxt, now); 
			}
			if(now / N < N - 1)
			{
				nxt = now + N;
				check(nxt, now);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6836