akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();	//1が書かれたカードの枚数
		int B = in.nextInt();	//0が書かれたカードの枚数
		int C = in.nextInt();	//-1が書かれたカードの枚数
		int K = in.nextInt();	//取る枚数
		int max = 0;			//最大値
 
		if(K<=A){			//取る枚数がA以下ならば
			max += K;
		}else{
          	max += A;
			K-=A;
          	if((K-B) >= 0){			//取る枚数がB以上ならば
				K-=B;
                if(K > 0){				//取る枚数が1以上ならば
					max -= K;
				}
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 35772
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  cin >> N;

  using P = tuple<string, int, int>;
  vector<P> r;
  rep(i, N) {
    string s;
    int p;
    cin >> s >> p;
    r.push_back(P(s, -p, i + 1));
  }
  sort(r.begin(), r.end());

  rep(i, N) {
    int j;
    tie(ignore, ignore, j) = r[i];
    cout << j << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  int N;
  cin >> N;
  if (N < 3) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> L(N);
  rep(i, N) {
    cin >> L[i];
  }

  int ans = 0;
  for (int i = 0; i < N - 2; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      for (int k = j + 1; k < N; ++k) {
        if (L[i] == L[j] || L[i] == L[k] || L[j] == L[k]) continue;
        if (L[i] + L[j] > L[k] &&
            L[j] + L[k] > L[i] &&
            L[k] + L[i] > L[j]) {
          ans++;
        }
      }
    }
  }

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

Measured memory_bytes: 3628
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int[] one = new int[K];
        int[] zero = new int[K];
        for (int i = 1; i < K; i++) {
            one[i] = (i + 1) % K;
            zero[i] = (i * 10) % K;
        }
        Deque<Integer> que = new ArrayDeque<>();
        int[] min = new int[K];
        for (int i = 0; i < K; i++) {
            min[i] = Integer.MAX_VALUE;
        }
        que.addLast(1);
        min[1] = 1;
        while (!que.isEmpty()) {
            int cur = que.pollFirst();
            if (min[cur] + 1 < min[one[cur]]) {
                que.addLast(one[cur]);
                min[one[cur]] = min[cur] + 1;
            }
            if (min[cur] < min[zero[cur]]) {
                que.addFirst(zero[cur]);
                min[zero[cur]] = min[cur];
            }
        }
        System.out.println(min[0]);
    }
}


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

int main(){
    string s;
    cin>>s;
    //s+=" ";
    int flag=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1] ){
            flag=1;break;
        }
    }
    if(flag) puts("Yes");
    else puts("No");
    return 0;
}



Measured memory_bytes: 256
n=input()
S=[]
min_len=50
for i in range(n):
	x=list(raw_input())
	d={}
	for j in x:
		if not j in d:
			d[j]=1
		else:
			d[j]+=1
	S.append(d)

#print S

l=S[0]

l2={}
min_cnt=50
for i in l.keys():
	for j in S:
		#print i,j,l2
		if i not in j:
			if i in l2:
				l2[i]=-1
		else:
			if i not in l2:
				l2[i]=j[i]
			else:
				if l2[i]!=-1:
					l2[i]=min(l2[i],j[i])		

ans=""
if len(l2.keys())==0:
	pass

else:
	for i in sorted(l2.keys()):
		for j in range(l2[i]):
			ans+=i
print ans
	



Measured memory_bytes: 2820
N,W=map(int,input().split())
w=[]
v=[]
jmax=100010
nmax=110
 
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
    
DP= [[0]*jmax for i in range(nmax)]
 
 
def chmax(a,b):
    if a>b:
        return a
    else:
        return b
 
 
for i in range(N):
    for j in range(jmax):
        if  j-w[i]>=0:
            DP[i+1][j]=chmax(DP[i][j],DP[i][j-w[i]]+v[i])
        else:
            DP[i+1][j]=DP[i][j]
 
            
print(DP[N][W])

Measured memory_bytes: 154056
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;

    for (int i=(s.length()-1);i>=1;i--){
	for (int j=0;j<i;j++){
	    if (s[j] > s[j+1]){
		char tmp=s[j];
		s[j]=s[j+1];
		s[j+1]=tmp;
	    }
	}
    }

    for (int i=(t.length()-1);i>=1;i--){
	for (int j=0;j<i;j++){
	    if (t[j] < t[j+1]){
		char tmp=t[j];
		t[j]=t[j+1];
		t[j+1]=tmp;
	    }
	}
    }

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

    return 0;
}

Measured memory_bytes: 256
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  const solve = memoization(function(i, m) {
    if (m == 0) return true;
    if (i >= n1) return false;
    return solve(i + 1, m) || solve(i + 1, m - arr1[i]);
  });

  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();

function memoization(f) {
  var cache = {};
  function innerFunc(...param) {
    let c = cache[param];
    // console.log(cache);
    if (typeof c !== 'undefined') {return c;}
    return cache[param] = f(...param);
  }
  return innerFunc;
}



Measured memory_bytes: 24396
//#pragma GCC optimize(2)
//#pragma G++ optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

const int maxn=100000+10;
struct node{
    int key;
    int id;
};
node a[maxn];
int n;
bool comp(node _a,node _b){
    return _a.key<_b.key;
}
int getint(){
    int x=0,s=1; char ch=' ';
    while(ch<'0' || ch>'9'){ ch=getchar(); if(ch=='-') s=-1;}
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar();}
    return x*s;
}
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    cin>>n;
    for (int i=1; i<=n; i++){
        int x; cin>>a[i].key;
        a[i].id=i;
    }
    sort(a+1,a+1+n,comp);
    for (int i=1; i<=n; i++){
        cout<<a[i].id<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1536
// AOJ 2816: Alphabet Block
// 2017.10.6 bal4u@uu

#include <stdio.h>

char s[1002];
int f['z'+1];

int main()
{
	int i, k;
	char *p;

	scanf("%s", s);
	p = s; while (*p) f[*p++]++;
	for (k = 0, i = 'a'; i <= 'z'; i++) if (f[i] & 1) k++;
	printf("%d\n", k / 2);
	return 0;
}

Measured memory_bytes: 1772
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var arr=(Arr.shift()).split(" ").map(Number);
   var cnt=0;
   while(true){
      var flag=arr.every(function(v,i){return (i+1==v);});
      if(flag)break;
      var L=arr.length;
      arr=arr.map(function(v){return v-1;});
      arr=arr.filter(function(v){return (v!=0);});
      arr.push(L);
      cnt++;
      if(cnt==10000){cnt=-1;break;}
   }
   console.log(cnt);
}

Measured memory_bytes: 48984
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;
const int mod=1e9+7;
const int N=1e6+5;
const int MAXN=1e5+5;
char a[5][5];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int i=sqrt(n);
        printf("%d\n",i*i);
    }
    return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    s, w = mi()
    print('unsafe') if w >= s else print('safe')

if __name__ == "__main__":
    main()

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
signed main(){
int a;
  cin>>a;
  if(a<10){
cout<<a<<"\n";
  }else if(a>=10 && a<100){
cout<<"9\n";
  }else if(a>=100 && a<1000){
	cout<<a-90<<"\n";
  }else if(a>=1000 && a<10000){
cout<<909<<"\n";
  }else if(a>=10000 && a<100000){
cout<<a-9090<<"\n";
  }else if(a==100000){
    cout<<"90909\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<a[n-1];
}


Measured memory_bytes: 256
n = int(input())
satis = []
for i in range(n):
    satis.append([int(j) for j in input().split()])
"""
dp[i][j] = 幸福度
i : 何日目終了時点(0~n)
j : 直前に選んだもの(0 : A,1 : B,2 : C)
"""
#print(satis)
dp = [[-1] * 3 for i in range(n+1)]
#print(dp)
for j in range(3):
    dp[0][j] = 0
#print(dp)
#i日目
for when in range(1,n+1):
    #選択肢
    for yesterday in range(3):
        if when != 1:
            for today in range(3):
                if today != yesterday:
                    dp[when][today] = max(dp[when][today], dp[when-1][yesterday] + satis[when-1][today])
        else:
            dp[when][yesterday] = satis[when-1][yesterday]

print(max(dp[n]))


Measured memory_bytes: 74072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Collection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; i++) arr[i] = in.nextInt();
            ArrayList<Integer> res = new ArrayList<>();
            if (n % 2 == 0) {
                for (int i = n; i >= 2; i -= 2) res.add(arr[i]);
                for (int i = 1; i <= n - 1; i += 2) res.add(arr[i]);
            } else {
                for (int i = n; i >= 1; i -= 2) res.add(arr[i]);
                for (int i = 2; i <= n - 1; i += 2) res.add(arr[i]);
            }
            out.println(StringUtils.join(res));
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class StringUtils {
        public static <E> String join(Collection<E> collection, String delim) {
            StringBuilder sb = new StringBuilder();
            for (E o : collection) {
                sb.append(o);
                sb.append(delim);
            }
            return sb.toString().trim();
        }

        public static <E> String join(Collection<E> collection) {
            return join(collection, " ");
        }

    }
}



Measured memory_bytes: 71696
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

long long calc(int a, int b, int c, int d){
	long long r = 1024 * a + b;
	r = 1024 * r + c;
	return 1024 * r + d;
}

long long pack(int a, int b, int c, int d){
	return min(min(calc(a, b, c, d), calc(b, c, d, a)), min(calc(c, d, a, b), calc(d, a, b, c)));
}

int getR(long long key){
	int c[4];
	for(int i=0;i<4;i++){
		c[i] = key%1024;
		key /= 1024;
	}
	if(c[0] == c[1] && c[1] == c[2] && c[2] == c[3]) return 4;
	if(c[0] == c[2] && c[1] == c[3]) return 2;
	return 1;
}

long long pow(int a, int p){
	long long r = 1;
	for(int i=0;i<p;i++) r *= a;
	return r;
}

long long fact(int f){
	long long r = 1;
	for(int i=2;i<=f;i++) r *= i;
	return r;
}

int main(){
	int N;
	static int c[400][4];
	static long long comb[400][401];
	comb[1][0] = comb[1][1] = 1;
	for(int i=2;i<=400;i++){
		comb[i][0] = 1;
		for(int j=1;j<i;j++) comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
		comb[i][i] = 1;
	}
	while(cin >> N && N){
		map<long long, int> num;
		long long res = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<4;j++) cin >> c[i][j];
			for(int j=0;j<i;j++){
				const int* back = c[j];
				for(int k=0;k<4;k++){
					long long key[4];
					key[0] = pack(back[(k+1)%4], back[(k+0)%4], c[i][1], c[i][0]);
					key[1] = pack(back[(k+0)%4], back[(k+3)%4], c[i][2], c[i][1]);
					key[2] = pack(back[(k+3)%4], back[(k+2)%4], c[i][3], c[i][2]);
					key[3] = pack(back[(k+2)%4], back[(k+1)%4], c[i][0], c[i][3]);
					sort(key, key+4);
					long long backKey = pack(back[0], back[1], back[2], back[3]);
					long long add = 1;
					for(int l=0;l<4;){
						int cnt = 1;
						for(int m=l+1;m<4 && key[l]==key[m];m++) ++cnt;
						int sel = 0;
						if(num.count(key[l])) sel = num[key[l]];
						if(key[l] == backKey) --sel;
						if(sel < cnt){
							add = 0;
							break;
						}
						add *= comb[sel][cnt] * pow(getR(key[l]), cnt) * fact(cnt);
						l += cnt;
					}
					res += add;
				}
			}
			long long k = pack(c[i][0], c[i][1], c[i][2], c[i][3]);
			if(num.count(k)) ++num[k];
			else num[k] = 1;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;cin>>s;
	vector<int> lr;
	for(int i=1;i<s.size()+1;++i)
	{
		int l=1;
		while(s[i]==s[i-1])
		{
			l++;
			i++;
		}
		lr.push_back(l);
		//if(l!=1)i--;
	}

	for(int i=0;i<lr.size();i+=2)
	{
		for(int j=0;j<lr[i]-1;++j)cout<<0<<" ";
		int num=lr[i]/2+lr[i+1]/2;
		cout<<num+lr[i]%2<<" ";
		cout<<num+lr[i+1]%2<<" ";
		for(int j=0;j<lr[i+1]-1;++j)cout<<0<<" ";
	}
	cout<<endl;
/*
	for(int i=0;i<lr.size();++i)
	{
		cout<<lr[i]<<endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 1144
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)
#print(a)

for _ in range(m):
 tmp_min = heapq.heappop(a)
 heapq.heappush(a,(-1)*(-tmp_min//2))

print(-sum(a))










Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int size = s.size();
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i = 0; i < size; i++) {
		if (s[i] == 'S') {
			cnt1++;
		} else {
			if (cnt1) {
				cnt1--;
			} else {
				cnt2++;
			}
		}
	}
	cout << cnt1 + cnt2 << endl;
	return 0;
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

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

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    class P
    {
        public int index;
        public P parent;
        public P sib;
        public List<P> child;
        public int height;
        public P(int index)
        {
            this.index = index;
            child = new List<P>();
        }
        public override string ToString()
        {
            var state = "";
            if (parent.index == -1) state = "root";
            else if (child.Count(pp=>pp.index!=-1) == 0) state = "leaf";
            else state = "internal node";
            var depth = 0;
            var p = parent;
            while (p.index != -1)
            {
                depth++;
                p = p.parent;
            }

            return $"node {index}: parent = {parent.index}, sibling = {sib.index}, degree = {child.Count(pp=>pp.index!=-1)}, depth = {depth}, height = {height}, {state}";
        }
    }
    private static int SetHeight(P[] ps,int index)
    {
        var hs = new[] { 0, 0 };
        for (var i = 0; i < 2; i++)
            if (ps[index].child[i].index != -1)
                hs[i] = SetHeight(ps, ps[index].child[i].index)+1;
        return ps[index].height = hs.Max();
    }
    private static readonly P NIL = new P(-1);
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ps = new P[num];
        for (var i = 0; i < num; i++)
        {
            ps[i] = new P(i);
            ps[i].parent = NIL;
            ps[i].sib = NIL;
        }
        for (var i = 0; i < num; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            for (var j = 1; j <= 2; j++)
                if (input[j] != -1)
                {
                    ps[input[j]].parent = ps[input[0]];
                    ps[input[0]].child.Add(ps[input[j]]);
                }
                else
                    ps[input[0]].child.Add(NIL);
            if (input[1] != -1 && input[2] != -1)
            {
                ps[input[1]].sib = ps[input[2]];
                ps[input[2]].sib = ps[input[1]];
            }
        }
        for (var i = 0; i < num; i++)
            if (ps[i].parent.index == -1) SetHeight(ps, i);
        WriteLine(string.Join("\n", ps.Select(p => p.ToString())));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 16608
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=1;
    int max=-1;
    double a,b,n;
    cin >> a >> b >> n;
    long long dif;
    dif=b-1;
    if(n<b-1)
        dif=n;
        max=floor(a*dif/b)-a*floor(dif/b);
    cout << max;
    return 0;
}

Measured memory_bytes: 3720
#!/usr/bin/env python3
import sys
from itertools import accumulate

try:
    from math import gcd
except Exception:
    from fractions import gcd

def solve(N: int, A: "List[int]"):
    gcds0 = list(accumulate(A, gcd))
    gcds1 = list(accumulate(A[::-1], gcd))[::-1]

    ret = 0
    for i in range(N):
        if i == 0:
            ret = max(ret, gcds1[i+1])
        if i == (N-1):
            ret = max(ret, gcds0[i-1])
        else:
            ret = max(ret, gcd(gcds0[i-1], gcds1[i+1]))
    print(ret)

# 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
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	cout << pow(n, 2);
	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  constexpr int N = 50;

  int64 k;
  cin >> k;
  vector<int64> xs(N, N - 1);
  for (int i = 0; i < N; i++) {
    xs[i] += k / N;
  }
  int64 r = k % N;
  for (int i = 0; i < N - r; i++) {
    xs[i] -= r;
  }
  for (int i = N - r; i < N; i++) {
    xs[i] += N;
    xs[i] -= r - 1;
  }

  cout << N << endl;
  for (int64 x : xs) {
    cout << x << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  long n = s.length();
  long i;
  vector<int>ndigit(n+1,0);
  vector<int>ndigit2(n+1,0);
  for(i=0;i<n;i++){
    ndigit[i] = (int)(s[n-1-i]-'0');
    ndigit2[i] = ndigit[i];
  }
  for(i=0;i<n;i++){
    while(ndigit[i]>=10){
      ndigit[i]-=10;
      ndigit[i+1]++;
    }
    if(ndigit[i]>5){
      ndigit[i]=0;
      ndigit[i+1]++;
    }else if(ndigit[i]==5){
      if(i<n-1 && ndigit[i+1]>=5){
        ndigit[i] = 0;
        ndigit[i+1]++;
      }
    }
  }
  long ans = 0;
  for(i=0;i<=n;i++){
    ans += ndigit[i];
  }
  for(i=0;i<n;i++){
    if(ndigit[i]>=ndigit2[i])ans += ndigit[i]-ndigit2[i];
    else{
      ndigit[i]+=10;
      ndigit[i+1]--;
      ans += ndigit[i]-ndigit2[i];
    }
  }
  cout << ans << endl;

}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll GCD(ll x,ll y){
    if(x%y==0)return y;
    return GCD(y,x%y);
}
ll LCM(int a, int b){
    return a*b/GCD(a,b);
}

int main(void){
    ll a,b;cin>>a>>b;
    ll g=gcd(a,b);
    ll ans=1;
    for(ll i=2;i*i<=g;i++){
        if(g%i==0){
            ans++;
            while(g%i==0)g/=i;
        }
    }
    if(g>1)ans++;
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 3620
Option Strict On
Imports System.Console
Imports System.Collections.Generic

Module Program
    Sub Main()
        Dim s As String = NextString()
        Dim ans As New List(Of String)

        For Each v As Char In s
            If v = "B"c Then
                If ans.Count <> 0 Then
                    ans.RemoveAt(ans.Count - 1)
                End If
            Else
                ans.Add(v)
            End If
        Next

        WriteLine(String.Join("", ans))
    End Sub

    Function NextString() As String
        Dim result As New List(Of String)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return String.Join("", result)
    End Function

End Module


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

using namespace std;

int main()
{
  int64_t n, k;
  cin >> n >> k;
  int64_t ans = 0;
  int64_t h = 0;
  for(int64_t i = 0;
      i < n;
      ++i)
    {
      cin >> h;
      if(h >= k)
        {
          ++ans;
        }
    }

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


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<string.h>

int main(void){
  int A;
  int B;

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

  if(B%A==0){
    printf("%d\n",A+B);
  }else{
    printf("%d\n",B-A);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int s=1,x=0;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		x=x+a;
		if(x<=k)
		{
			s++;
		}
		else
		{
			break;
		}
	 }
	cout<<s<<endl;
	return 0; 
}

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

using namespace std;

#define TARGET 753

int main()
{
	string S, subS;
	int len;
	int tmp;
	int diff,  diff_min = 1000;

	cin >> S;

	len = S.length();

	for (int i = 0; i < len - 2; i++) {
		subS = S.substr(i, 3);
		tmp = stoi(subS);
		diff = abs(tmp - TARGET);

		if (diff < diff_min) {
			diff_min = diff;
		}
	}

	cout << diff_min << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k,s,i,j;
const int maxn=1e9;
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for (i=1;i<=k;i++)
	printf("%d ",s);
	if (s!=maxn)
	{
	for (i=k+1;i<=n;i++)
	printf("%d ",maxn);
    } else
    for (i=k+1;i<=n;i++)
    printf("1 ");
}

Measured memory_bytes: 1280
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_vec();
    let mut res = a[0];

    for e in a {
      res = gcd(res, e);
    }
    println!("{}", res);
}

fn gcd(a: i64, b: i64) -> i64 {
  if a < 0 {
    gcd(-a, b);
  }

  if b < 0 {
    gcd(a, -b);
  }

  if b > a {
    gcd(b, a);
  }

  if a % b == 0 {
    return b;
  }

  let r:i64 = a % b;

  return gcd(b, r);
}


Measured memory_bytes: 8444
N = int(input())
Plan = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    c1,s1,f1 = Plan[i]
    time = s1+c1
    for j in range(i+1,N-1):
        c,s,f = Plan[j]
        if time <= s:
            time = s
        elif (time-s)%f != 0:
            time += f-(time-s)%f
        time += c
    print(time)
print(0)

Measured memory_bytes: 73888
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if((1<n&&a<=b)||(n&&a==b))
    {
    	cout<<(b-a)*(n-2)+1<<endl;
	}
    else
    {
    	cout<<0<<endl;
	}
    return 0;
}

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

int main()
{
	int a = 0, b = 0, n = 0, ans = 0;

	cin >> a >> b;

	n = a * b;

	if ((n % 2) == 0)
		ans = 0;
	else
		ans = 1;

	if(ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int N = 300010;
int a[N], t[N], c[N];

int main()
{
    register int n;
    scanf("%d", &n);
    for (register int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        a[x]++;
    }
    for (register int i = 1; i <= n; ++i) {
        t[a[i]]++;
    }
    for (register int i = 1; i <= n; ++i) {
        c[i] = c[i - 1] + t[i] * i;
        t[i] += t[i - 1];
    }
    register int ans = n;
    for (register int i = 1; i <= n; ++i) {
        while(((t[n] - t[ans]) * ans + c[ans]) / i < ans) {
            --ans;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4352
from collections import deque

H, W = map(int, input().split())

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p-W)
    if h != H-1:
        q_list.append(p+W)
    if w != 0:
        q_list.append(p-1)
    if w != W-1:
        q_list.append(p+1)
    return q_list


queue = deque(black_cells)
d = [10000]*(H*W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 1000010

int dp[MAX_N];
int X;

// 現在の値が cur のとき、 X 円にできるなら 1, そうでないなら 0 を返す
int dfs(int cur) {
    if(cur == X) { return 1; }
    if(cur > X) { return 0; }

    int& ret = dp[cur];
    if(~ret) { return ret; }
    ret = 0;

    for(int i = 100; i <= 105; ++i) {
        if(dfs(cur + i) == 1) {
            ret = 1;
            return ret;
        }
    }
    return ret;
}

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

    cin >> X;
    MINUS(dp);
    printf("%lld\n", dfs(0));

    return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, d, ans = 0, a;
  scanf("%lld%lld%lld", &n, &d, &a);
  d *= 2;
  pair<ll, ll> m[n], p;
  ll sum[n + 1], now = 0;
  for(i = 0; i < n; ++i) scanf("%lld%lld", &m[i].first, &m[i].second), m[i].second = (m[i].second + a - 1) / a;
  sort(m, m + n);
  for(i = 0; i <= n; ++i) sum[i] = 0;
  for(i = 0; i < n; ++i) {
    now += sum[i];
    if(m[i].second > now) {
      ans += m[i].second - now;
      p = make_pair(m[i].first + d, 1e9);
      sum[upper_bound(m, m + n, p) - m] -= m[i].second - now;
      now = m[i].second;
    }
  }
  printf("%lld", ans);
  return 0;
}

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

//thanks to pyf ...
//thanks to qhl ...

const int N = 1e5 + 8;

int a[N*2];

int main()
{
	int n;
	while(cin >> n)
	{
		for(int i = 0 ;i<n;i++)
		{
			cin >> a[i];
		}
		deque<int>q;
		for(int i = 0;i<n;i++)
		{
			if(i % 2 != n % 2)
			{
				q.push_front(a[i]);
			}
			else
			{
				q.push_back(a[i]);
			}
		}
		deque<int> :: iterator it;
		int cnt = 0 ;
		for(it = q.begin();it!=q.end();it++)
		{
			if(cnt++)
				cout << " " ;
			cout << *it;	
		}
		cout << endl;
	}
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

double temperature(int T, int x) {
    return (double)T - (double)x * 0.006;
}

int main() {
    fastIO;
    int n, t, a;
    cin >> n >> t >> a;

    vector<int> H(n);
    rep(i, n) cin >> H.at(i);

    int pos = 0;
    double temp = 10000000.0;

    rep(i, n) {
        double diff = abs(temperature(t, H.at(i)) - (double)a);
        if (diff < temp) {
            temp = diff;
            pos = i;
        }
    }

    cout << pos + 1 << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main()
{   long long s;
    scanf("%lld",&s);
    long long x,y;
    if(s%1000000000==0){
        printf("0 0 1000000000 1 0 %lld",s/1000000000);
    }else{
        y=s/1000000000+1;
        x=y*1000000000-s;
        printf("0 0 1000000000 1 %lld %lld",x,y);
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string w;
    cin >> w;
    vector<int> cnt(26, 0);
    for(int i = 0; i < w.length(); i++){
        cnt[w[i]-'a']++;
    }

    bool F = true;
    for(int i = 0; i < cnt.size(); i++){
        if(cnt[i] % 2 == 1){
            F = false;
            break;
        }
    }

    if(F == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

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

#define max 3

//qsort(d, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}

int main()
{
    int p[max];
    
    scanf("%d %d %d", &p[0], &p[1], &p[2]);
    
    qsort(p, 3, sizeof(int), up_comp);
    
    printf("%d", p[0]+p[1]);
    
    return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	string S;
	cin >> N >> S;

	int ans = 1;
	REP(i, S.size() - 1) {
		if (S[i] != S[i + 1])ans++;
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<map>

using namespace std;

int main() {
  map<int, int> num;

  int n = 0;
  while(cin >> n){
    //if(n == -1) break;
    num[n]++;
  }

  int max = 0;
  int max_i = 0;
  map<int, int>::iterator it = num.begin();
  for(; it != num.end(); it++) {
    if(it->second > max_i) {
      max = it->first;
      max_i = it->second;
    }
  }

  for(it = num.begin(); it != num.end(); it++) {
    if(max_i == it->second) {
      cout << it->first << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int s; cin >> s;
    set<int> a;
    while(1)
    {
        if (a.count(s))
        {
            break;
        }
        a.insert(s);
        if (s % 2 == 1) s = 3 * s + 1;
        else s = s / 2;
    }
    cout << a.size() + 1 << endl;
}

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

a=[]
for i in range(1,10):
    a.append(i)
while True:
    if k<=len(a):
        print(a[k-1])
        break
    
    k-=len(a)
    old=[]
    old,a=a,old
    for x in old:
        for i in range(-1,2):
            d=x%10+i
            if d<0 or d>9:
                continue
            nx=x*10+d
            a.append(nx)
  

Measured memory_bytes: 11080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#define eps 1e-10
#define double long double
using namespace std;
struct point{
	double x,y;
	void read(){scanf("%Lf%Lf",&x,&y);}
	void write(){printf("%.10Lf %.10Lf\n",x,y);}
	point(double X=0.0,double Y=0.0):x(X),y(Y){}
	point operator +(const point a)const{return point(x+a.x,y+a.y);}
	point operator -(const point a)const{return point(x-a.x,y-a.y);}
	point operator *(double a)const{return point(x*a,y*a);}
	point operator /(double a)const{return point(x/a,y/a);}
	bool operator ==(const point a)const{return abs(x-a.x)<=eps && abs(y-a.y)<=eps;}
};
double dis(point a,point b=point(0,0)){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
double cross3(point o,point a,point b){return cross(a-o,b-o);}
bool jiao(point a,point b,point c,point d)
{
	if(min(a.x,b.x)>max(c.x,d.x) || min(a.y,b.y)>max(c.y,d.y)) return false;
	if(min(c.x,d.x)>max(a.x,b.x) || min(c.y,d.y)>max(a.y,b.y)) return false;
	if(cross3(a,b,c)*cross3(a,b,d)>0) return false;
	if(cross3(c,d,a)*cross3(c,d,b)>0) return false;
	return true;
}
short int on_line(point o,point a,point b)//oa->ob 0:D 1:U 2:O
{
	if(dot(a-o,b-o)<-eps) return 0;
	return 1+(dis(a-o)>=dis(b-o));
}
void make_rand(double &x){x=x+(1ll*rand()%10+1)/10.0*eps;}
struct Line{
	point a,b;
	void read(){a.read();b.read();}
	bool operator &&(const Line u){return jiao(a,b,u.a,u.b);}
	point operator &(const Line u)
	{
		if(a==u.a || a==u.b) return a;
		if(b==u.a || b==u.b) return b;
		double x1=a.x,x2=b.x,x3=u.a.x,x4=u.b.x;
		double y1=a.y,y2=b.y,y3=u.a.y,y4=u.b.y;
		if(x3==x4) return point(x3,(y2-y1)*x3/(x2-x1)+(y1*x2-x1*y2)/(x2-x1));
		if(x1==x2) return point(x1,(y4-y3)*x1/(x4-x3)+(y3*x4-x3*y4)/(x4-x3));
		make_rand(x2);
		double x=((y3*x4-y4*x3)*(x2-x1)-(y1*x2-y2*x1)*(x4-x3))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
		double y=(y2-y1)*x/(x2-x1)+(y1*x2-x1*y2)/(x2-x1);
		return point(x,y);
	}
};
point project(Line a,point p)
{
	point &p1=a.a,&p2=a.b;
	double len=dot(p2-p1,p-p1)/dis(p2-p1);
	return p1+(p2-p1)/dis(p2-p1)*len;
}
double dis(Line a,Line b)
{
	if(a && b) return 0;
	double ans=min(min(dis(a.a,b.a),dis(a.a,b.b)),min(dis(a.b,b.a),dis(a.b,b.b)));
	point res=project(a,b.a);
	if(on_line(a.a,a.b,res)==2) ans=min(ans,dis(res,b.a));
	res=project(a,b.b);
	if(on_line(a.a,a.b,res)==2) ans=min(ans,dis(res,b.b));
	res=project(b,a.a);
	if(on_line(b.a,b.b,res)==2) ans=min(ans,dis(res,a.a));
	res=project(b,a.b);
	if(on_line(b.a,b.b,res)==2) ans=min(ans,dis(res,a.b));
	return ans;
}
double area(point p[],int n)
{
	double ans=0;
	for(int i=2;i<=n;i++)
	ans+=cross3(p[1],p[i-1],p[i])/2;
	return abs(ans);
}
point p[110];
int main()
{
	int n;
	scanf("%d",&n);
	
	srand(n);
	for(int i=1;i<=n;i++) p[i].read();
	printf("%.1Lf\n",area(p,n));
	return 0;
}



Measured memory_bytes: 3240
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,k;
ll powll(ll base,ll power){
    ll ans = 1;
    while (power){
        if (power&1) ans = (base*ans)%mod;
        base = (base*base)%mod;
        power >>= 1;
    }
    return ans;
}
ll facts[400010],invs[400010];
int ncr(int a, int b) { return facts[a] * invs[b] % mod * invs[a-b] % mod; }

signed main(){
    n = 400000;
    ll f = 1;
    facts[0] = 1;
    FOR(i,1,n+1){
        f *= i;
        f %= mod;
        facts[i] = f;
    }
    ll inv = powll(f,mod-2);
    invs[n] = inv;
    REPNS(i,n){
        inv *= i;
        inv %= mod;
        invs[i-1] = inv;
    }

    
    cin >> n >> k;
    int ans = 0;
    REP(i,min(n,k+1)){
        ans = (ans + ncr(n,i) * ncr(n-1,i)) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<functional>
using namespace std;
vector<int>x[220000], V; int n, p[220000], q[220000], r[220000], u[220000];
int dfs(int pos) {
	vector<int>R(x[pos].size(), 0);
	for (int i = 0; i < x[pos].size(); i++) {
		if (q[x[pos][i]] == 2)continue;
		int s = dfs(x[pos][i]);
		if (s < x[pos].size())R[s] = 1;
	}
	for (int i = 0; i < x[pos].size(); i++) { if (R[i] == 0)return i; }
	return x[pos].size();
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		x[p[i]].push_back(i);
	}
	int cx = 1;
	while (true) {
		if (q[cx] == 2)break;
		q[cx]++; if (q[cx] == 2)V.push_back(cx);
		cx = p[cx];
	}
	for (int i = 0; i < V.size(); i++)r[i] = dfs(V[i]);
	u[0] = r[0];
	for (int i = 1; i < V.size(); i++) {
		if (r[i] == u[i - 1]) { u[i] = r[i] + 1; }
		else { u[i] = r[i]; }
	}
	bool OK = false;
	if (u[0] != u[V.size() - 1]) { OK = true; }
	u[0] = r[0] + 1;
	for (int i = 1; i < V.size(); i++) {
		if (r[i] == u[i - 1]) { u[i] = r[i] + 1; }
		else { u[i] = r[i]; }
	}
	if (u[0] == u[V.size() - 1] + 1) { OK = true; }
	if (OK == true)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 14452
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int x = (a + b) / 2;

		if ((a + b) % 2 == 0) {
			System.out.print(x);
		} else {
			System.out.print(x + 1);
		}
	}
}

Measured memory_bytes: 21716
using System;
//using System.Collections.Generic;
//using System.Collections;
using System.Linq;

namespace solution
{
  class Class1
  {
    static void Main()
    {
      var num = Console.ReadLine().Split().Select(long.Parse).ToArray();

      long x = num.Max();
      long y = num.Min();
      long sp = 0;

      while (x % y != 0)
      {
        sp = x % y;
        x = y;
        y = sp;
      }

      Console.WriteLine(y);
    }
  }
}








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

typedef struct str_pref pref_t; 
typedef struct str_pref {
    vector<int> city;
} pref_t;
int main(void) {
    int N,M,P,Y;
    ostringstream oss;

    cin >> N >> M;

    vector<pref_t> pref(N);
    vector<string> id(M);
    vector<tuple<int,int,int>> py(M);
    for(int i=0;i<M;i++) {
        cin >> P >> Y;
        py[i] = make_tuple(Y,P,i);
    }

    sort(py.begin(), py.end());
    for(int i=0;i<M;i++) {
        P = get<1>(py[i]);
        Y = get<0>(py[i]);
        oss.str("");        
        oss << setw(6) << setfill('0') << P;
        P--;
        oss << setw(6) << setfill('0') << (pref[P].city.size()+1);
        id[get<2>(py[i])] = oss.str();
        pref[P].city.push_back(i);
    }

    for(auto s:id) {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 13568
n,C[124][101],*p,a,b,c;D(i){int f[101]={0},T;memset(p=C,9,404);for(p[a]=0;T=a;)for(f[T]=1,a=i=0;i++<n;a=f[i]|p[i]>p[a]?a:i)c=p[T]+C[T][i],p[i]=p[i]<c?p[i]:c;printf("%d\n",p[b]>1e8?-1:p[b]);}main(k){for(;scanf("%d%d",&n,&k)*n;)for(memset(C,9,5e4);k--;a?scanf("%d%d%d",&a,&b,&c),C[a][b]=fmin(C[a][b],c),C[b][a]=fmin(C[b][a],c):D(scanf("%d%d",&a,&b)))scanf("%d",&a);}

Measured memory_bytes: 468