akhauriyash/Code-Regression huggingface dataset:
/* ex 7_3
   nnasy */

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

int main(void){
    //宣言と入力
    int row, col;
    char **grid;
    int *judge_row, *judge_col;
    scanf("%d %d", &row, &col);

    //二次元配列領域および一次元配列領域の動的確保
    grid = (char**)calloc(row, sizeof(char*));
    if (grid == NULL){
        exit(1);
    }
    for (int i=0; i<row; i++){
        grid[i] = (char*)calloc(col, sizeof(char));
        if (grid[i] == NULL){
            exit(1);
        }
    }
    judge_row = (int*)calloc(row, sizeof(int));
    judge_col = (int*)calloc(col, sizeof(int));
    if ((judge_row == NULL) || (judge_col == NULL)){
        exit(1);
    }


    //マス目の記号を入力
    for (int i=0; i<row; i++){
        for (int j=0; j<col; j++){
            scanf(" %c", &grid[i][j]);
        }
    }

    //取り除く行および列を調べる
    for (int i=0; i<row; i++){
        for (int j=0; j<col; j++){
            if (grid[i][j] == '#'){
                judge_row[i]=1;
                judge_col[j]=1;
            }
        }
    }

    //各Judgeを用いて出力
    for (int i=0; i<row; i++){
        if (judge_row[i] == 1){
            for (int j=0; j<col; j++){
                if (judge_col[j] == 1){
                    printf("%c", grid[i][j]);
                }
            }
            printf("\n");
        }
    }

    //確保した配列の解放
    for (int i=0; i<row; i++){
        free(grid[i]);
    }
    free(grid);
    free(judge_row);
    free(judge_col);

    return 0;
}

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

double ts(double x1,double x2,double x3,double y1,double y2,double y3){
	return fabs(((x1*y2+x2*y3+x3*y1)-(x3*y2+x2*y1+x1*y3))/2);
}


int main(){
	
	double x1,x2,x3;
	double	y1,y2,y3;
	double xp,yp;
	
	while(cin>>x1){
		cin>>y1>>x2>>y2>>x3>>y3>>xp>>yp;
		
		double S,s1,s2,s3;
		S=ts(x1,x2,x3,y1,y2,y3);
		s1=ts(xp,x2,x3,yp,y2,y3);
		s2=ts(x1,xp,x3,y1,yp,y3);
		s3=ts(x1,x2,xp,y1,y2,yp);
		if(s1+s2+s3==S)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
		
	}
	
}

Measured memory_bytes: 1216
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var n = t.ParseIntList(t.ReadInput());
            var A = t.ParseIntList(t.ReadInput());
            
            Console.WriteLine(Math.Ceiling((double)(n[0] - 1) / (n[1] - 1)));
        }



        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ParseIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }


        public List<double> ParseDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ParseLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

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


int main() {
int n,m;
cin >> n >>m;
int a[50],b[50],c[50],d[50];

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

for(int i = 0;i < m;i++){
	cin >> c[i]>>d[i];
}


int dist;
vector<long long >min(50,1000000000);
int ans[50];
for(int i = 0;i < n;i++){
	for(int j = 0;j < m;j++){
      dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dist < min[i]){
      	min[i] = dist;
      	ans[i] = j;
      }
	}
}


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

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 55

int N;
vector<int> V;
bool check[NUM];

bool recursive(int);


bool dfs(int water_index,int current_index,int water_rest){
	if(water_rest == 0)return recursive(water_index+1);
	if(current_index == N)return false;

	if(check[current_index] == false && V[current_index] <= water_rest){
		check[current_index] = true;
		if(dfs(water_index,current_index+1,water_rest-V[current_index]))return true;
		check[current_index] = false;
	}
	return dfs(water_index,current_index+1,water_rest);
}

bool recursive(int index){

	if(index == N)return true;

	if(!check[index])return false;

	return dfs(index,index,V[index]) || recursive(index+1);
}

void func(){

	V.clear();

	int tmp;

	for(int loop = 0; loop < N; loop++){

		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	if(N == 1){
		printf("YES\n");
		return;
	}

	sort(V.rbegin(),V.rend());

	check[0] = true;
	for(int i = 1; i < N; i++){

		check[i] = false;
	}

	if(recursive(0)){

		printf("YES\n");
	}else{

		printf("NO\n");
	}
}


int main(){

	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



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

int main(){
	int d;
	int t;
	int s;

	cin >> d >> t >> s;

	if ((d+s-1)/s <= t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3584
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N, K = geta(int)
    h = geta(int)

    INF = 1 << 60
    dp = [INF]*N
    dp[0], dp[1] = 0, abs(h[0] - h[1])

    for i in range(2, N):
        lb = max(0, i-K)
        dp[i] = min((dp[j] + abs(h[i]-h[j]) for j in range(lb,i)))

    print(dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 53216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int w[100005];
vector<int> ans(100005);
vector<vector<int> > to,cost;

int main(){
    int n;
    cin >> n;
    to.resize(n);
    cost.resize(n);
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w; u--; v--;
        to[u].push_back(v); cost[u].push_back(w);
        to[v].push_back(u); cost[v].push_back(w);
    }

    vector<int> ans(n,-1);
    queue<int> que;
    ans[0] = 0;
    que.push(0);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int i=0;i<to[v].size();i++){
            int u = to[v][i];
            int w = cost[v][i];
            if(ans[u]!=-1) continue;
            ans[u] = (ans[v]+w)%2;
            que.push(u);
        }
    }

    rep(i,n) cout << ans[i] << endl;
}

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

int main()
{
	string g;
	while (cin >> g, g != "#") {
		int y, m, d;
		cin >> y >> m >> d;
		if (y > 31 || (y == 31 && m >= 5)) {
			g = "?";
			y -= 30;
		}
		cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
	}
	return 0;
}



Measured memory_bytes: 3156
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

    long t0, t1, t2, sum, cost[100'000][2] = {};

    cin >> t2;
    cost[0][0] = abs(t2);
    sum = cost[0][0];
    t0 = 0;
    t1 = t2;
    for (int n = 1; n < N; n++) {
        cin >> t2;
        cost[n][0] = abs(t2 - t1);
        cost[n][1] = abs(t2 - t0);
        sum += cost[n][0];

        t0 = t1;
        t1 = t2;
    }
    sum += abs(t1);

    for (int n = 0; n < N - 1; n++) {
        cout << sum - cost[n][0] - cost[n + 1][0] + cost[n + 1][1] << endl;
    }
    cout << sum - cost[N - 1][0] - abs(t1) + abs(t0) << endl;

    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<ll> A;

set<pair<ll,int>> se[(1<<18)];
pair<int,int> mat[(1<<18)];
ll ans[(1<<18)];

int main(){
  cin>>N;
  M=(1<<N);
  A.resize(M);
  for(int i=0;i<M;i++) cin>>A[i];

  for(int i=1;i<M;i++){
    se[i].insert(mkp(-A[0],0));
    se[i].insert(mkp(-A[i],i));
  }

  for(int i=1;i<M;i++){
    for(int j=0;j<20;j++){
      if(i&(1<<j)){
        int a=mat[i^(1<<j)].first;
        int b=mat[i^(1<<j)].second;
        se[i].insert(mkp(-A[a],a));
        se[i].insert(mkp(-A[b],b));
      }
    }

    auto itr=se[i].begin();
    int a=(*itr).second;
    itr++;
    int b=(*itr).second;

    mat[i]=mkp(a,b);
    ans[i]=A[a]+A[b];
  }

  for(int i=1;i<M;i++) ans[i]=max(ans[i],ans[i-1]);
  for(int i=1;i<M;i++) cout<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 332672
from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1

counth = deque(counth)
countw = deque(countw)

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
lenh = len(index_h)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
    lenw = len(index_w)
    if lenh*lenw > M:
      print(maxh + maxw)
      exit()    

ans = maxh + maxw - 1

bomb.sort()
bomb = deque(bomb)
kouho = []
for i in range(lenh):
  h = index_h.pop()
  for j in range(lenw):
    w = index_w[j]
    kouho.append(h+ H*w)
kouho.sort()
kouho = deque(kouho)
B = bomb.popleft()
K = kouho.popleft()
while True:
  if B > K:
    ans += 1
    break
  elif B == K:
    if len(kouho) == 0:
      break
    else:
      K = kouho.popleft()
  else:
    if len(bomb) == 0:
      ans += 1
      break
    else:
      B = bomb.popleft()
print(ans)



Measured memory_bytes: 155380
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[][] way= new int[n][3];

		for(int i =0;i<3*n;i++){
			int b=i%3;
			int a=(i-b)/3;
			int m = sc.nextInt();
			way[a][b]= m;
		}

		boolean koike = true;
		for(int i = 0;i<n-1;i++){
			koike &= judge(way[i][0],way[i][1],way[i][2],way[i+1][0],way[i+1][1],way[i+1][2]);
		}
		koike &= judge(0,0,0,way[0][0],way[0][1],way[0][2]);
		if(koike){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	private static boolean judge(int a,int b, int c, int d, int e, int f){
		int t = d-a;
		int distance = Math.abs(e-b)+Math.abs(f-c);
		return t>=distance && (t-distance)%2==0;
	}
}


Measured memory_bytes: 94496
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <vector>
#include <cstdio>
#define  MAXN 110
using namespace std;
typedef long long LL;
vector <int> x, y;
int l[MAXN], t[MAXN], r[MAXN], b[MAXN]; 
LL map[110][110];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
void dfs (int yy,int xx,LL cc)
{
     if (map[yy][xx] != cc) return; 
     map[yy][xx] = -1;
     for (int i=0;i<4;++i)
     {
         int xxx = xx+dx[i];
         int yyy = yy+dy[i];
         if (0<=xxx&&xxx<x.size()&&0<=yyy&&yyy<y.size())    
            dfs (yyy,xxx,cc);
     }    
}
int main(void)
{
    int n, ans;
    while ( scanf("%d",&n)==1 && n )
    {
          x.clear();
          y.clear();
          x.push_back(-1);
          y.push_back(-1);
          for (int i=0;i<n;++i)
          {
              scanf ("%d%d%d%d",l+i,t+i,r+i,b+i);    
              x.push_back(l[i]);
              x.push_back(r[i]);
              y.push_back(t[i]);
              y.push_back(b[i]);              
          }          
          sort (x.begin(),x.end());          
          x.erase(unique(x.begin(),x.end()),x.end());          
          sort (y.begin(),y.end());
          y.erase(unique(y.begin(),y.end()),y.end());
          memset (map,0,sizeof(map));
          for (int i=0;i<n;++i)
          {
              l[i] = lower_bound(x.begin(),x.end(),l[i]) - x.begin();    
              r[i] = lower_bound(x.begin(),x.end(),r[i]) - x.begin();    
              t[i] = lower_bound(y.begin(),y.end(),t[i]) - y.begin();    
              b[i] = lower_bound(y.begin(),y.end(),b[i]) - y.begin();    
              for (int j=b[i];j<t[i];++j)
              for (int k=l[i];k<r[i];++k) map[j][k] |= (1LL<<i);
          }
          ans = 0;
          for (int i=0;i<y.size();++i)
          for (int j=0;j<x.size();++j)
              if (map[i][j] >= 0) 
              {
                 dfs(i,j,map[i][j]); 
                 ans++;            
              }
          printf ("%d\n",ans);    
    }
    return 0;    
}

Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;
double condition = 0.0;

void func()
{
	int64_t N, K;
	cin >> N >> K;

	int64_t amari = N % K;

	if (abs(amari - K) < amari)
		cout << abs(amari - K) << endl;
	else
		cout << amari << endl;
	return;
}

int main() {
//while(1)
	func();
	return 0;
}


Measured memory_bytes: 3172
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

int main(){
//int W,H,x,y,r;
    int i=1, x;
    cin>>x;
    while(x!=0){
       
    if(x!=0)
    cout<<"Case "<<i<<": "<<x<<"\n";    
    i++;
    cin>>x;
    }
  
}


Measured memory_bytes: 3008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = br.readLine()) != null && !line.isEmpty()) {
            System.out.println(line.toUpperCase());
        }
    }
}

Measured memory_bytes: 24192
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 998244353;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();

        double Arad  = H + (double)M/60;
        double Brad = (double)M;

        double Ax = A * Math.cos(Math.toRadians(90 - Arad*30));
        double Ay = A * Math.sin(Math.toRadians(90 - Arad*30));
        double Bx = B * Math.cos(Math.toRadians(90 - Brad*6));
        double By = B * Math.sin(Math.toRadians(90 - Brad*6));
        
        System.out.println(Math.sqrt((Bx -Ax) * (Bx -Ax) + (By -Ay) * (By -Ay)));

    }

}









Measured memory_bytes: 35952
let n = Scanf.scanf " %d" @@ (+) 0
let ps = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ans = ref 0
let _ =
  for i = 0 to n - 3 do
    if (ps.(i) < ps.(i + 1) && ps.(i + 1) < ps.(i + 2)) || (ps.(i + 2) < ps.(i + 1) && ps.(i + 1) < ps.(i)) then incr ans done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int a[300000];
int b[300000];
map<int, int> nums;
int ans;
signed main(){
  int n,k;
  cin >> n >> k;
  REP(i,n){
    cin >> a[i];
    a[i]--;
    a[i] %= k;
    b[i+1] = b[i]+a[i];
    b[i+1] %= k;
  }
  REP(i,n+1){
    //cout << b[i] << endl;
  }
  for (int i = 0; i < n+1; ++i){
    nums[b[i]]++;
    if(i>=k){
      nums[b[i-k]] --;
    }
    ans += nums[b[i]]-1;
  }
/*   int res = 0;
  for (auto it : nums) {
    int num = it.second; // it.first が it.second 個ある
    res += num * (num - 1) / 2;
  } */
  cout << ans << endl;



  return 0;
}


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

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

int f(int x){
  int res=0;
  while(x%2==0){
    x/=2;
    res++;
  }
  return res;
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n){cin >> a[i]; a[i]/=2;}
  
  int t=f(a[0]);
  rep(i,n){
    if(f(a[i])!=t){
      cout << 0 << "\n";
      return 0;
    }
    a[i] >>=t;
  }
  m>>=t;
  
  ll l=1;
  rep(i,n){
    l=lcm(l,a [i]);
      if(l>m){
        cout << 0 << "\n";
        return 0;
      }
  }
  m/=l;
  int ans =(m+1)/2;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3744
import collections


Item = collections.namedtuple("Item", ("weight", "value"))


def main():
    N, W = [int(i) for i in input().split()]
    items = [Item(int(i), int(j))for (i, j) in [input().split() for _ in range(N)]]
    # 選択肢をn番目の品物まで、重さを最大wとしたときの価値の最大値
    dp = [[0] * (W + 1) for _ in range(N + 1)]

    # n番目の品物まで含む
    for n in range(1, N + 1):
        # 重さの最大値がw
        for w in range(W + 1):
            # n番目の品物
            item = items[n - 1]
            # 買う（＝買える）
            if w - item.weight >= 0:
                dp[n][w] = max(dp[n][w], dp[n - 1][w - item.weight] + item.value)
            # 買わない（＝買えない）場合も行う
            dp[n][w] = max(dp[n][w], dp[n - 1][w])

    ans = dp[N][W]
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 118640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    if(k>((n-1)*(n-2))/2)
    {
        cout<<-1<<endl;
        return 0;
    }
    vector<pair<int,int>> v; 
    for(int i=2;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            v.pb({i,j});
        }
    }
    int rem=((n-1)*(n-2))/2-k;
    int m=(n-1)+rem;
    cout<<m<<endl;
    for(int i=2;i<=n;i++)
    {
        cout<<1<<" "<<i<<endl;
    }
    for(int i=0;i<rem;i++)
    {
        cout<<v[i].fi<<" "<<v[i].se<<endl;
    }
    cout<<endl;
}
 

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFind uf = new UnionFind(n);
        
        int[][] xy = new int[m][2];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            xy[i][0] = x;
            xy[i][1] = y;
        }
        
        long[] answer = new long[m];
        answer[m - 1] = (long)n * (n - 1) / 2;
        
        for (int i = m - 1; i > 0 ; i--) {
            int x = xy[i][0];
            int y = xy[i][1];
            if (uf.same(x, y)) {
                answer[i - 1] = answer[i];
                continue;
            }
            
            int rx = uf.root(x);
            int ry = uf.root(y);
            answer[i - 1] = answer[i] - uf.size[rx] * uf.size[ry];
            uf.unite(x, y);
        }
        
        for (long a : answer) {
            System.out.println(a);
        }
    }
}

class UnionFind {
    int[] par;  // 自身の親
    int[] size; // 自身の属するグループの要素数
    int connectedComponent;

    UnionFind(int n) {
        par = new int[n];
        size = new int[n];
        Arrays.fill(size, 1);
        connectedComponent = n;
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
        // 1-2-4の場合、4の親=2を4の根=1に繋ぎ変えた上で親を返す
        // ↑根まで辿る深さを減らす為
        // return a = b;とは、aにbを代入し、aを返すという意味
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            par[ry] = rx;
            connectedComponent--;
            int resize = size[rx] + size[ry];
            size[rx] = resize;
            size[ry] = resize;
        }
    }

    boolean same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    void printPar() {
        System.out.println(Arrays.toString(par));
    }
}

Measured memory_bytes: 99636
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}


int main() {
    ll n;
    cin >> n;
    ll a, s[n+1];
    ll i;
    
    for(i=0; i<=n; i++)
        s[i]=0;
    for(i=1; i<=n; i++) {
        cin >> a;
        s[i]=s[i-1]+a;
    }
    ll ans=INF, ans1, ans2, ans3, ans4;
    ll l=1, r=3;
    for(i=2; i<=n-2; i++) {
        while(l<i && abs(s[l]-s[0]-(s[i]-s[l]))>=abs(s[l+1]-s[0]-(s[i]-s[l+1])))
            l++;
        while(r<n && abs(s[r]-s[i]-(s[n]-s[r]))>=abs(s[r+1]-s[i]-(s[n]-s[r+1])))
            r++;
        
        ans1=s[l]-s[0];
        ans2=s[i]-s[l];
        ans3=s[r]-s[i];
        ans4=s[n]-s[r];

        ans=min(ans, max(ans1, max(ans2, max(ans3, ans4)))-min(ans1, min(ans2, min(ans3, ans4))));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;//998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  vec a(100);
  a[0]=2;
  a[1]=1;

  for(ll i=0;i<90;i++){
    a[i+2]=a[i]+a[i+1];
  }

  cout << a[n] << endl;

  return 0;
}

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


int main() {
	double R, G;

	//int R, G;

	cin >> R >> G;

	//double answer = static_cast<double> 2 * G - R

	cout << 2 * G - R << endl;
	
}

Measured memory_bytes: 256
def main():
    N = int(input() )
    a = []
    a = [int(num) for num in input().split() ]
    
    a.sort(reverse = True )
#    print(a)
#    print(a[0::2 ] )
#    print(a[1::2 ] )
    
    score_A = sum(a[0::2 ] )
    score_B = sum(a[1::2 ] )
    
    print(score_A - score_B)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

void init()
{
}

ll p(ll a, int b)
{
	ll ans = 1;
	rep(i, b) ans *= a;
	return ans;
}

void solve()
{
	ll n;
	cin >> n;

	const ll MOD = 26;

	int keta = 0;
	while (true)
	{
		ll v = p(MOD, keta);
		if (v > n)
		{
			break;
		}
		n -= v;
		keta++;
	}

	string ans = "";
	rep(i, keta)
	{
		ll mod = n % MOD;
		n /= MOD;
		string t = "";
		t += ('a' + mod);
		ans = t + ans;
	}
	cout << ans << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

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

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}
int main() {
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < h; i++) {
		cout << a.at(i) << endl << a.at(i) << endl;
	}
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

int n;
int query(int pos) {
    printf("%d\n", pos);
    fflush(stdout);

    static char op[25];
    scanf("%s", op);

    if(op[0] == 'V') exit(0);
    if(op[0] == 'F') return 0;
    if(op[0] == 'M') return 1;
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);

    int t0 = query(0);
    int l = 0, r = n - 1;

    while(l <= r) {
        int m = (l + r) >> 1;
        if(((m & 1) ^ query(m)) == t0) l = m + 1; else r = m - 1; 
    }

    return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int N; cin >> N;
    map<string,ll> mp;
    for(int i = 0; i < N; ++i){
        string S; cin >> S;
        sort(ALL(S));
        mp[S]++;
    }
    ll ans = 0;
    for(auto& e:mp){
        ll f = e.second;
        ans += f*(f-1)/2;
    }
    cout << ans << endl;


    return 0;
}


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

int hukasa(int,int);

typedef struct node{
  int pa;
  int le;
  int ri;
}TREE;

TREE tree[100000];
int n,depth[100000];

int main(){
  int i,j,node,child,number,sub,root,numchild;
  scanf("%d",&n);
  if(n>100000) exit(2);
  for(i=0;i<n;i++) {
    tree[i].pa=tree[i].le=tree[i].ri=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&node,&child);
    for(j=0;j<child;j++){
      scanf("%d",&number);
      tree[number].pa=node;
      if(j==0) tree[node].le=number;
      else tree[sub].ri=number;
      sub=number;
    }
  }
  for(i=0;i<n;i++){
    if(tree[i].pa==-1) root=i;
  }

  hukasa(root,0);
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,tree[i].pa,depth[i]);
    if(tree[i].pa == -1) printf("root, [");
    else if(tree[i].le != -1)printf("internal node, [");
    else printf("leaf, [");
    
    numchild=tree[i].le;
    for(j=0;numchild != -1;j++){
      if(j>0)printf(", ");
      printf("%d",numchild);
      numchild=tree[numchild].ri;
    }
    printf("]\n");
  }
  return 0;
}

int hukasa(int u,int p){
  depth[u]=p;
  if(tree[u].ri != -1) hukasa(tree[u].ri,p);
  if(tree[u].le != -1) hukasa(tree[u].le,p+1);
}



Measured memory_bytes: 6536
S=list(input())

year=int(S[0])*1000+int(S[1])*100+int(S[2])*10+int(S[3])
month=int(S[5])*10+int(S[6])

if year<2019:
    ans='Heisei'
elif year>2019:
    ans='TBD'
else:
    if month<=4:
        ans='Heisei'
    else:
        ans='TBD'

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
}

/**
1 bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2   flag = 1 // 逆の隣接要素が存在する
3   while flag
4     flag = 0
5     for j が N-1 から 1 まで
6       if A[j] < A[j-1]
7         A[j] と A[j-1] を交換
8         flag = 1

入力例 1
5
5 3 2 4 1
出力例 1
1 2 3 4 5
8
 */


Measured memory_bytes: 26224
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var H, W int
var ch, cw int
var dh, dw int
var S []string
var u [][]int

const inf = int(1e9)

type next struct {
	x, y int
}

func bsf(s []next, c int) []next {
	q := s
	nq := make([]next, 0)
	for len(q) != 0 {
		cx := q[0].x
		cy := q[0].y
		q = q[1:]
		for dy := -2; dy <= 2; dy++ {
			for dx := -2; dx <= 2; dx++ {
				if dx == 0 && dy == 0 {
					continue
				}
				x := cx + dx
				y := cy + dy
				if x < 0 || x >= W || y < 0 || y >= H {
					continue
				}
				if S[y][x] == '#' {
					continue
				}
				if u[y][x] > c {
					if dx == 0 && abs(dy) == 1 || dy == 0 && abs(dx) == 1 {
						u[y][x] = c
						q = append(q, next{x, y})
					} else {
						u[y][x] = c + 1
						nq = append(nq, next{x, y})
					}
				}
			}
		}
	}
	return nq
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	H, W = getInt(), getInt()
	ch, cw = getInt()-1, getInt()-1
	dh, dw = getInt()-1, getInt()-1
	S = make([]string, H)
	u = make([][]int, H)
	for i := 0; i < H; i++ {
		S[i] = getString()
		u[i] = make([]int, W)
		for j := 0; j < W; j++ {
			u[i][j] = inf
		}
	}

	u[ch][cw] = 0
	n := make([]next, 0)
	n = append(n, next{cw, ch})
	for i := 0; len(n) != 0; i++ {
		n = bsf(n, i)
		// for i := 0; i < H; i++ {
		// 	out(u[i])
		// }
		// out("----------------")
	}
	if u[dh][dw] == inf {
		out(-1)
		return
	}
	out(u[dh][dw])
}


Measured memory_bytes: 36508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep_r(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define resize(x, n) x.resize(n)
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MAX = 100000;
struct edge {
    ll from, to, weight;
    edge(ll f, ll t, ll w) : from(f), to(t), weight(w) { }
};
vector<vector<edge>> edges;
vector<vector<ll>> graph;
vector<bool> visited;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll n, m, r, answer;
ll a, b, c, d;

ll gcd(ll a, ll b) { // aとbの最大公約数（ユークリッドの互除法）
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { // aとbの最小公倍数
    ll c = gcd(a, b);
    return a * b / c;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    a--;
    ll x = b - (b / c) - (b / d) + (b / lcm(c, d));
    ll y = a - (a / c) - (a / d) + (a / lcm(c, d));
    printf("%lld\n", x-y);
}

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

const int N = 1e5 + 5;
vector< vector<int> > g (N);

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int time, reward;
    cin >> time >> reward;
    g[time].emplace_back(reward);
  }
  long long tot = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < (int) g[i].size(); j++) {
      pq.push(g[i][j]);
    }
    if (!pq.empty()) {
      tot += pq.top();
      pq.pop();
    }
  }
  cout << tot << '\n';
  return 0;
}

Measured memory_bytes: 5632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Hello
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
        ulong n = nk[0], k = nk[1];

        var pair = new KeyValuePair<int, int>[n];
        for (int i = 0; i < pair.Length; i++)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = ab[0], b = ab[1];
            pair[i] = new KeyValuePair<int, int>(a, b);
        }
        var sortPair = pair.OrderBy(e => e.Key);


        ulong sum = 0;
        int ans = -1;
        
        foreach (var _pair in sortPair)
        {
            sum += (ulong)_pair.Value;
            if (sum >= k)
            {
                ans = _pair.Key;
                break;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 19016
// Example program
#include <iostream>
using namespace std;

struct seg {
  int m, n; int s[262143]; int cc = 0;
  void initialize(int mm) {
      m = mm, n = 1;
      while(n < m) n<<=1;
      int n2=2*n-1;
      fill(s, s+n2, (1LL<<31)-1);
  }
  void add(int ii, int x) {
      int id = n-1+ii;
      s[id] = x;
      while(id > 0) {
        id = (id - 1) / 2;
        s[id] = min(s[2 * id + 1], s[2 * id + 2]);
      }
  }
  int sum(int a, int b, int k, int l, int r) {
      if (l == -1) l=0, r=n;
      //if (k >= n*2-1) return puts("bd") * 0;
      //cout << "(" << a << ", " << b << ", " << k << ", " << l << ", " << r << ")" <<  endl;
      if (b <= l || a >= r) return (1LL<<31)-1;
      if (a <= l && r <= b) return s[k];
      else {
          return min(sum(a, b, 2*k+1, l, (l+r)/2), sum(a, b, 2*k+2, (l+r)/2, r));
      }
  }
};

int main() {
    int n, q; cin >> n >> q;
    seg ss; ss.initialize(n);
    
    for(int i=0; i<q; i++) {
      int e, f, g;
      cin >> e >> f >> g;
      if (e == 1) {
          cout << ss.sum(f, g+1, 0, -1, -1) << endl;
      } else {
          ss.add(f, g);
      }
    }
}


Measured memory_bytes: 4100
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(M)]
ans = [True] * N
for A, B in AB:
    a = A - 1
    b = B - 1
    if H[a] >= H[b]:
        ans[b] = False
    if H[a] <= H[b]:
        ans[a] = False
print(len([i for i in ans if i]))



Measured memory_bytes: 27800
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n,m;
  std::cin >> n >> m;

  vt<int> a(n), b(n), c(m), d(m);
  rep(i,n)
    std::cin >> a[i] >> b[i];
  rep(i,m)
    std::cin >> c[i] >> d[i];

  rep(i,n){
    int num, ma = 1e9;
    rep(j,m){
      int di = abs(a[i]-c[j])+ abs(b[i]-d[j]);
      if(di < ma) {
        ma = di;
        num = j+1;
      }
    }
    std::cout << num << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
r, c = map(int, input().split())
goukei = [0]*c
for i in range(r):
    tmp = list(map(int, input().split()))
    for j in range(c):
        goukei[j] += tmp[j]
    print(' '.join(map(str, tmp)) + ' ' + str(sum(tmp)))
print(' '.join(map(str, goukei)) + ' ' + str(sum(goukei)))



Measured memory_bytes: 5612
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
result = sum(b)
for i in range(1,n):
    if a[i-1]+1 == a[i]:
        result += c[a[i-1]-1]
print(result)

Measured memory_bytes: 3064
class UnionFind

  def initialize(n)
    @parents = Array.new(n, -1) # if negative value means size
  end

  def unite(a, b)
    a = root(a)
    b = root(b)

    return false if a == b

    a, b = b, a if -@parents[a] < -@parents[b]
    @parents[a] += @parents[b] # if negative value means size
    @parents[b] = a
    true
  end

  def root(a)
    @parents[a] < 0 ? a : (@parents[a] = root(@parents[a]))
  end

  def same?(a, b)
    root(a) == root(b)
  end

  def size(a)
    -@parents[root(a)]
  end
end

n, m = gets.to_s.split.map{|t|t.to_i}
bridges = Array.new(m){ gets.to_s.split.map{ |t| t.to_i - 1 } }

uft = UnionFind.new(n)

ans = [n * (n-1) / 2]
bridges.reverse_each do |a, b|
  s = uft.size(a)
  t = uft.size(b)
  ans.unshift (ans[0] - (uft.unite(a, b) ? s * t : 0))
end

puts ans.drop(1)

Measured memory_bytes: 12488
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,l,r;
    cin>>n;
    if(n)
        cout<<0<<'\n';
    else
        cout<<1<<'\n';
}








Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
  int ans=0;
  int n,d;
  cin >> n;
  int i,j,k;
  for(i=0;i<n;i++){
    cin >> d;
    k=1;
    for(j=2;j*j<=d;j++){
      if(d%j==0){
	k=0;
	break;
      }
    }
    ans+=k;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

#define N 10000

static int k_operafan[ N + 1 ];
static int p[ N + 1 ] = { 1, 1, 0 };
static int pn;

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( i = 2; i * i <= N; ++i )
  {
    if ( p[ i ] ) continue ;

    for ( j = i * i; j <= N; j += i )
    {
      p[ j ] = 1;
    }
  }
  for ( i = 2; i <= N; ++i )
  {
    if ( p[ i ] ) continue ;

    p[ pn++ ] = i;
  }
  for ( i = 0; i < pn; ++i )
  {
    int s = 0;

    for ( j = i; j < pn; ++j )
    {
      s += p[ j ];
      if ( s > N ) break ;

      ++k_operafan[ s ];
    }
  }

  for ( ; ; )
  {
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    printf ( "%d\n", k_operafan[ n ] );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int* func_mallocation_(  // 配列の動的メモリ確保をおこなう関数
    const int N          // 配列の要素数
) {
  int* data = (int*)malloc(N * sizeof(int));  // ???
  if (data == NULL) { // メモリ確保に失敗した際のエラー処理
    printf("Can not allocate memory. 'data' is NULL.\n");
    exit(EXIT_FAILURE);
  }
  return data;  // 確保した配列のポインタを戻り値として返す
}
int main(){
    int N;
    int cnt=0;
    scanf("%d",&N);
    int* array = func_mallocation_(N);
    for (int i = 0; i < N; i++)
        scanf("%d", &(array[i]));  // STDINから配列要素を受け取る
    
    for(int j=0; j<N;j++){
        if((j+1)%2==1 && array[j]%2==1){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    free(array);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

const Int MAX = 333;
using BS = bitset<MAX*2>;
using mat = vector<BS>;
void gauss(mat &v){
  int n=v.size();
  for(Int i=0;i<n;i++){
    for(Int k=i;k<n;k++){
      if(v[k][i]){
	swap(v[i],v[k]);
	break;
      }
    }
    for(Int k=0;k<n;k++)
      if(i!=k&&v[k][i]) v[k]^=v[i];
  }
}

int mrank(mat v,int m){
  int n=v.size();
  int r=0,c=0;
  //for(int i=0;i<n;i++) cout<<v[i]<<endl;cout<<endl;
  for(int i=0;i<n;i++){
    int s=-1;
    while(c<m){
      for(int j=i;j<n;j++){
	if(v[j][c]){
	  s=j;
	  break;
	}
      }
      if(~s) break;
      c++;
    }
    if(c>=m) break;
    
    swap(v[i],v[s]);
    for(int j=0;j<n;j++)
      if(i!=j&&v[j][c]) v[j]^=v[i];
    
    r++;c++;
  }
  //for(int i=0;i<n;i++) cout<<v[i]<<endl;cout<<endl;
  return r;
}

mat mul(const mat &a,const mat &b){
  int n=a.size();
  mat res(n,BS(0));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
	if(a[i][k]&b[k][j])
	  res[i][j].flip();
  return res;
}

mat mat_pow(mat v,int k){
  int n=v.size();
  mat res(n,BS(0));
  for(int i=0;i<n;i++)
    res[i][i]=1;
  while(k){
    if(k&1) res=mul(res,v);
    v=mul(v,v);
    k>>=1;
  }
  return res;
}

signed main(){
  int n;
  cin>>n;
  mat v(n,BS(0));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int k;
      cin>>k;
      v[i][j]=k;
    }
  }
  BS w;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    w[i]=k;
  }
  int t;
  cin>>t;
  v=mat_pow(v,t);

  int a=mrank(v,n);
  for(int i=0;i<n;i++) v[i][n]=w[i];
  int b=mrank(v,n+1);

  //cout<<n<<":"<<a<<" "<<b<<endl;

  if(a!=b){
    cout<<"none"<<endl;
    return 0;
  }

  if(a!=n){
    cout<<"ambiguous"<<endl;
    return 0;
  }

  auto pv=v;
  
  gauss(v);
  for(int i=0;i<n;i++) cout<<v[i][n]<<" \n"[i==n-1];
  
  return 0;
}



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

using namespace std;

char s[100005];
int lastr, lastl, pr[100005], ans[100005];

int main(void) {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'R') lastr = i;
    if (s[i] == 'L') pr[i] = lastr;
  }
  for (int i = n; i >= 1; --i) {
    if (s[i] == 'L') lastl = i;
    if (s[i] == 'R') pr[i] = lastl;
  }
  for (int i = 1; i <= n; ++i)
    if (s[i] == 'L') {
      if ((i - pr[i]) % 2 == 1)
        ++ans[pr[i] + 1];
      else
        ++ans[pr[i]];
    } else {
      if ((pr[i] - i) % 2 == 1)
        ++ans[pr[i] - 1];
      else
        ++ans[pr[i]];
    }
  for (int i = 1; i <= n; ++i)
    printf("%d%c", ans[i], " \n"[i == n]);
  return 0;
}


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

int main()
{
    int n, *a, count{};
    scanf("%d", &n);
    a = new int[n + 1];
    a[n] = 2000000000;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
    }
    std::sort(a, a + n);
    for (int i = 0; i < n; i++)
    {
        int tmp{};
        for (; i < n; i++)
        {
            tmp++;
            if (a[i] != a[i + 1]) break;
        }
        if (tmp < a[i]) count += tmp;
        else count += tmp - a[i];
    }
    printf("%d\n", count);

    delete[] a;

    return 0;
}

Measured memory_bytes: 640