akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

namespace {
    const int INPUT_NUM = 3;
}
int main() {
    std::vector<int> input;

    for(int i = 0; i < INPUT_NUM; ++i) {
        int temp;
        std::cin >> temp;
        input.push_back(temp);
    }
    std::sort(input.begin(), input.end());

    int answer = 0;

    for(int i = 1; i < INPUT_NUM; ++i) {
        answer += std::abs(input[i] - input[i-1]);
    }

    std::cout << answer;

    return 0;
}

Measured memory_bytes: 256
n = input()
A = map(int, raw_input().split())
C = [0]*((n+1)/2)
MOD = 10**9+7
for e in A:
    C[e/2] += 1
if n%2 == 1:
    if C[0] != 1 or any(C[i] != 2 for i in xrange(1, (n+1)/2)):
        print 0
        exit(0)
    print pow(2, (n-1)/2, MOD)
if n%2 == 0:
    if any(C[i] != 2 for i in xrange((n+1)/2)):
        print 0
        exit(0)
    print pow(2, n/2, MOD)




Measured memory_bytes: 11328
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main(){
    int N;
    cin >> N;
    map<ll, int> count;
    for(int i = 0; i < N; i++){
        ll A;
        cin >> A;
        count[A]++;
    }
    vector<pair<ll,int>> v;
    for(auto p : count){
        if(p.se >= 2){
            v.emplace_back(p.fi, p.se);
        }
    }
    sort(all(v), greater<>());
    ll S;
    if(v.size() == 1){
        if(v[0].se >= 4) S = v[0].fi * v[0].fi;
        else S = 0;
    }else if(v.empty()) S = 0;
    else{
        if(v[0].se >= 4) S = v[0].fi * v[0].fi;
        else S = v[0].fi * v[1].fi;
    }
    cout << S << endl;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
public class A{
    public static void Main(){
        int d,t,s;
        int[] dts=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        d=dts[0];
        t=dts[1];
        s=dts[2];
        if (d<=s*t){
        System.Console.WriteLine("Yes");
        }
        else{
        System.Console.WriteLine("No");
    }
        
    }
}


Measured memory_bytes: 28292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node{
    ll L,R,MaxNum;
    Node *Lc,*Rc;
    Node(ll L_,ll R_,ll N):L(L_),R(R_){
        if(L==R){
            MaxNum=N;
            Lc=Rc=0;
            return ;
        }
        MaxNum=0;
        Lc=new Node(L,L+R>>1,N);
        Rc=new Node(Lc->R+1,R,N);
    }
    inline void pushdown(){
        if(!MaxNum||!Lc) return ;
        if(!Lc->MaxNum) Lc->MaxNum=MaxNum;
        else Lc->MaxNum=min(Lc->MaxNum,MaxNum);
        if(!Rc->MaxNum) Rc->MaxNum=MaxNum;
        else Rc->MaxNum=min(Rc->MaxNum,MaxNum);
        MaxNum=0;
    }
    ll query(ll pos){
        if(L==R) return MaxNum;
        pushdown();
        if(pos<=Lc->R) return Lc->query(pos);
        return Rc->query(pos);
    }
    void update(ll Head,ll Tail,ll Val){
        if(L==Head&&Tail==R){
            if(!MaxNum) MaxNum=Val;
            else MaxNum=min(MaxNum,Val);
            return ;
        }
        pushdown();
        if(Lc->R>=Tail) Lc->update(Head,Tail,Val);
        else if(Rc->L<=Head) Rc->update(Head,Tail,Val);
        else Lc->update(Head,Lc->R,Val),Rc->update(Rc->L,Tail,Val);
    }
}*RSide,*USide;
ll N,Q,Num;
inline void work(){
    ll op,pos;
    cin>>op>>pos;
    if(op==1){
        ll Tmp=USide->query(pos);
        USide->update(pos,pos,1);
        RSide->update(1,Tmp-1,pos);
        if(Tmp>1) Num-=Tmp-2;
    }
    else{
        ll Tmp=RSide->query(pos);
        RSide->update(pos,pos,1);
        USide->update(1,Tmp-1,pos);
        if(Tmp>1) Num-=Tmp-2;
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>Q;
    Num=(N-2)*(N-2);
    RSide=new Node(1,N,N);
    USide=new Node(1,N,N);
    while(Q--) work();
    cout<<Num<<endl;
    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && b != c) cout << c << endl;
  else if(a != b && b == c) cout << a << endl;
  else cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def Z(S):
    res = [0]*len(S)
    res[0] = len(S)
    i = 1
    j = 0
    while i < len(S):
        while i+j < len(S) and S[j] == S[i+j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < len(S) and k+res[k] < j:
            res[i+k] = res[k]
            k += 1
        i += k
        j -= k
    return res

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

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

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)

        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

s = input()
t = input()

S = s*(len(t)//len(s)+2)
z = Z(t+'*'+S)
z = z[len(t)+1:]

u = UnionFind(len(s))

for i in range(len(s)):
    j = (i+len(t))%len(s)
    if z[i] == len(t) and z[j] == len(t):
        u.union(i,j)

d = defaultdict(list)
for i in range(len(s)):
    if z[i] == len(t):
        d[u.find(i)].append(i)

ans = 0
for k in d:
    loop = True
    if len(d[k])==1:
        loop = len(t)%len(s)==0
    else:
        for i in d[k]:
            j = (i+len(t)*(len(d[k])-1))%len(s)
            loop = z[j]==len(t) and loop
    if loop:
        ans = -1
        break
    ans = max(ans,len(d[k]))

print(ans)

Measured memory_bytes: 141740
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


n = int(input())
s = list(str(input()))

cnt = {}
for c in s:
  if c not in cnt:
    cnt[c] = 1
  else:
    cnt[c] += 1

ans = 1
for i in cnt.values():
  ans = ans*(i+1) % (10**9+7)

print(ans-1)

Measured memory_bytes: 49648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl;
#define all(v) v.begin(), v.end()


int main() {
  int N, K;
  cin >> N >> K;
  int A[N+1]; ll ans = 0;
  A[0] = 0;
  rep1(i,N) {
    cin >> A[i];
    A[i] += A[i-1];
    A[i]--;
    A[i] %= K;
  }
  map<int, int> m;
  rep(i,min(K, N+1)) {
    m[A[i]]++;
  }
  rep(i,N) {
    m[A[i]]--;
    ans += m[A[i]];
    if (i+K<=N)
      m[A[i+K]]++;
  }
  print(ans);
  return 0;
}


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

typedef long long  LL;
int n,ans1,ans2;
LL a[100010];
vector <LL> ans,V;
map <vector <LL> ,int> M;

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		{
			scanf("%lld",&a[i]),ans.clear(),V.clear();
			for (int j=2; j<=a[i]&&j<=3000; j++)
				while (a[i]%j==0)  ans.push_back(j),a[i]/=j;
			if (a[i]!=1)
				if (LL(sqrt(a[i]))*LL(sqrt(a[i]))==a[i])
					ans.push_back(LL(sqrt(a[i]))),ans.push_back(LL(sqrt(a[i])));
				else  ans.push_back(a[i]);
			for (int j=0,s; j<ans.size(); )
				{
					a[0]=ans[j];
					for (s=0; j<ans.size()&&ans[j]==a[0]; j++,s++);
					if (s%3)  V.push_back(a[0]),V.push_back(s%3);
				}
			if (V.size())  M[V]++;  else  ans1=1;
		}
	for (map <vector <LL> ,int> ::iterator it=M.begin(); it!=M.end(); it++)
		{
			V=(*it).first;
			for (int j=1; j<V.size(); j+=2)  V[j]=3-V[j];
			if (M.find(V)!=M.end())  ans2+=max(M[V],(*it).second);
			else  ans1+=(*it).second;
		}
	printf("%d",ans1+ans2/2);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 15360
N = int(input())
Input = input().split()

Inputint = [int(i) for i in Input]

new = []
COUNTER = 1
for i in Inputint:
    if COUNTER == 1:
        if i == 1:
            new.append(i)
            COUNTER += 1
    else:
        if i == new[-1]+1:
            new.append(i)
        else:
            continue

if not new:
    print(-1)
else:
    print(N-len(new))

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> arr(n);
    std::array<int, 100001> even{};
    std::array<int, 100001> odd{};
    for (int i = 0; i < n / 2; ++i) {
        std::cin >> arr.at(i) >> arr.at(i + 1);
        ++even.at(arr.at(i));
        ++odd.at(arr.at(i + 1));
    }
    std::pair<int, int> even_first, even_second, odd_first, odd_second;
    even_first.second = even_second.second = odd_first.second = odd_second.second = -1;
    for (int i = 0; i < 100001; ++i) {
        if (even.at(i) >= even_first.second) {
            even_second.first = even_first.first;
            even_second.second = even_first.second;
            even_first.first = i;
            even_first.second = even.at(i);
        } else if (even.at(i) >= even_second.second) {
            even_second.first = i;
            even_second.second = even.at(i);
        }
        if (odd.at(i) >= odd_first.second) {
            odd_second.first = odd_first.first;
            odd_second.second = odd_first.second;
            odd_first.first = i;
            odd_first.second = odd.at(i);
        } else if (odd.at(i) >= odd_second.second) {
            odd_second.first = i;
            odd_second.second = odd.at(i);
        }
    }
    if (even_first.first == odd_first.first) {
        std::cout << n - std::max(even_first.second + odd_second.second, even_second.second + odd_first.second) << std::endl;
    } else {
        std::cout << n - even_first.second - odd_first.second << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>

int main()
{
    double result[100];
    int count = 0;
    while (1)
    {
        int x, h;
        scanf("%d %d", &x, &h);
        if (x == h && x == 0)
        {
            break;
        }
        double yoko = 0.5 * x;
        double tri = pow(pow(yoko, 2) + pow(h, 2), 0.5);
        tri *= x * 0.5;
        result[count++] = pow(x, 2) + tri * 4;
    }
    int n;
    for (n = 0; n < count; n++)
    {
        printf("%f\n", result[n]);
    }
    return 0;
}


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

int main() {
  int N, M, city;
  
  cin >> N >> M;
  vector<int> A(M * 2);
  vector<int> C(N);

  for(int i = 0; i < A.size(); i++){
    cin >> city;
    A.at(i) = city;
  }

  for(int i = 1; i <= N; i++){
    int counter = 0;
    for(int j = 0; j < A.size(); j++){
      if(i == A.at(j)){
        counter++;
      }
    }
    cout << counter << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int d = in.nextInt(), n = in.nextInt();
        if(d == 0) {
            System.out.println(n == 100 ? 101 : n);
        }else if (d == 1) {
            System.out.println(n * (n == 100 ? 101 : 100));
        }else {
            System.out.println(n * (n == 100 ? 10100 : 10000));
        }
    }
}

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

bool comp(vector<int>& a, vector<int>& b){
    return a[0] > b[0];
}


int main(void){
    int n, m, a;
    while(1){
        cin >> n >> m >> a;
        if(n == 0) break;

        vector<vector<int> > table(m, vector<int> (3, 0));
        for(int i = 0; i < m; i++){
            cin >> table[i][0] >> table[i][1] >> table[i][2];
        }

        //?????????????????????
        sort(table.begin(), table.end(), comp);

        /*cout << endl;
        for(int i = 0; i < m; i++){
            cout << table[i][0] << " " << table[i][1] << " " << table[i][2] << endl;
        }*/

        for(int i = 0; i < m; i++){
            if(a == table[i][1]) a = table[i][2];
            else if(a == table[i][2]) a = table[i][1];
            //cout << i << " " << a << endl;;
        }
        cout << a << endl;

    }

    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n;
  cin >> n;
  string a,b,c;
  cin >> a >> b >> c;
  int ans  = 0;
  
  for(int i = 0; i < n; i++){
    if(a[i] == b[i] && b[i] == c[i]){
      
    } else if((a[i] != b[i] && b[i] == c[i]) || (a[i] == b[i] && b[i] != c[i]) || (a[i] == c[i] && b[i] != c[i])){
      ans++;
    } else {
      ans += 2;
    }
  }
  cout << ans <<  endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, sum = 0, cnt = 0; cin >> n;
    vi a(n);
    rep(i, n){
        cin >> a[i];
        if(a[i]<0) cnt++;
        a[i] = abs(a[i]);
        sum += a[i];
    }
    sort(all(a));
    if(cnt%2 != 0) sum -= 2*a[0];
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const long long inf = 1e18+7;
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  vector<long long int> vect(n);
  for(int i=0;i<n;i++) cin>>vect[i];
  vector<vector<long long int>> dp(n,vector<long long int>(n));//dp[i][j]->mininum cost to combine given interval in a single vertex
  for(int l=n-1;l>=0;l--){
    for(int r=l;r<n;r++){
        if(r==l) dp[l][r]=0;
        else{
            dp[l][r]=inf;
        long long int sum=0;
        for(int i=l;i<=r;i++) sum+=vect[i];
        for(int i=l;i<=r-1;i++) dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+sum);
        }
      }
    }
  cout<<dp[0][n-1];
  return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		long h = fs.nextLong();
		long w = fs.nextLong();
		
		if(h == 1 || w == 1) {
			System.out.println(1);
			return;
		}
		
		long ans = 0;
		
		for(long i = 0; i <= w - 1; i = i+2) {
			long restW = w - i;
			ans += Math.min(restW, h);
		}
		
		for(long i = 2; i <= h - 1; i = i+2) {
			long restH = h - i;
			ans += Math.min(restH, w);
		}
		
		System.out.println(ans);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W, H;
  cin >> H >> W;
  
//  vector<string> data(H); 
  vector<vector<char>> data(H, vector<char>(W));
  
  vector<bool> flagW(W,false);
  vector<bool> flagH(H,false);
  
  for(int j=0; j<H; j++)
  {
    string a;
    cin >> a;
      
    for(int i=0; i<W; i++)
    {
      data[j][i] = a[i];
 	}
  }
   
  // check w
  for(int j=0; j<H; j++)
  {
    for(int i=0; i<W; i++)
    {
      if(data[j][i]=='#') flagH[j] = true;
 	}
  }
  
  // check h
  for(int i=0; i<W; i++)
  {
    for(int j=0; j<H; j++)
    {
      if(data[j][i]=='#') flagW[i] = true;
 	}
  }
  
  for(int j=0; j<H; j++)
  {
    if(!flagH[j]) continue;
    
    for(int i=0; i<W; i++)
    {
      if(!flagW[i]) continue;
      cout << data[j][i];
 	}
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){int i,p,q,N,M,Q,a[501][501]={};scanf("%d %d %d",&N,&M,&Q);for(i=M;i--;){scanf("%d %d",&p,&q);a[p][q]++;}for(p=1;p<=N;p++)for(q=1;q<=N;q++)a[p][q]+=a[p][q-1];for(p=1;p<=N;p++)for(q=1;q<=N;q++)a[p][q]+=a[p-1][q];for(i=Q;i--;scanf("%d %d",&p,&q)+printf("%d\n",a[q][q]-a[--p][q]-a[q][p]+a[p][p]));return 0;}

Measured memory_bytes: 1792
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int n,S;
  while(cin >> n >> S && n + S > 0){
    vector<int> mages(n);

    for(int i = 0;i < n; ++i){
      cin >> mages[i];
    }
    sort(mages.begin(), mages.end());


    int ans = 0;

    for(int i = n-1;0 <= i; --i){
      int need_pow = S - mages[i];
      int index = upper_bound(mages.begin(), mages.end(), need_pow) - mages.begin();
      if(index <= i) ans -= 1;
      ans += n - index;
      
    }


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

Measured memory_bytes: 1260
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
8
insert 30
insert 88
insert 12
insert 1
insert 20
insert 17
insert 25
print

output: in_order + pre_order
1 12 17 20 25 30 88
30 12 1 20 17 25 88

"""

import sys


class Node(object):
    def __init__(self, data):
        self.data = data
        self.left, self.right = None, None

    def insert(self, data):
        """
        insert data according to BST rules
        """
        if data < self.data:
            if self.left is None:
                self.left = Node(data)
            else:
                self.left.insert(data)
        else:
            if self.right is None:
                self.right = Node(data)
            else:
                self.right.insert(data)

        return None


def pre_order(node):
    if node is not None:
        print('', node.data, end='')
        pre_order(node.left)
        pre_order(node.right)
    return None


def in_order(node):
    if node is not None:
        in_order(node.left)
        print('', node.data, end='')
        in_order(node.right)
    return None


def action(command, content):
    if command.startswith('in'):
        tree_root.insert(int(content))

    # print tree walk
    else:
        in_order(tree_root)
        print('')
        pre_order(tree_root)
        print('')

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    command_list = list(map(lambda x: x.split(), _input[1:]))
    # assert len(command_list) == array_length
    # print(array_length, *command_list)

    flag, tree_root = False, None
    for each in command_list:
        command, content = each[0], each[-1]
        if (not flag) and command.startswith('in'):
            tree_root = Node(data=int(content))
            flag = True
            continue
        action(command, content)

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

int main() {
  int W,H,N;
  cin>>W>>H>>N;
  
  // W×H要素の２次元配列
  int A[W][H]={0};
 
  // 黒くなったら、A=1
  for(int i=0;i<N;++i){
    int x,y,a;
    cin>>x>>y>>a;
    
    if(a==1){
      for(int j=0;j<x;++j){
        for(int k=0;k<H;++k){
          A[j][k]=1;
        }
      }
    }
    
    if(a==2){
      for(int j=x;j<W;++j){
        for(int k=0;k<H;++k){
          A[j][k]=1;
        }
      }
    }
    
    if(a==3){
      for(int j=0;j<W;++j){
        for(int k=0;k<y;++k){
          A[j][k]=1;
        }
      }
    }
    
    if(a==4){
      for(int j=0;j<W;++j){
        for(int k=y;k<H;++k){
          A[j][k]=1;
        }
      }
    }
    
  }
  
  // 白い部分（A=0）の個数の計算
  int ans=0;
  for(int i=0;i<W;++i){
    for(int j=0;j<H;++j){
      if(A[i][j]==0)
        ++ans;
    }
  }
  
  cout<<ans<<endl;
}


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

int n,m,a,b;

int main() {
    scanf("%d%d%d%d", &n, &m, &a, &b);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            printf("%d", (i<b)^(j<a));
        }
        puts("");
    }


}

Measured memory_bytes: 1280
N, = gets.split
D = gets.split.map(&:to_i)

digits = ([*0..9]-D).sort
nz = digits[0]!=0 ? digits[0] : digits[1]

borrow = N.size-2-(N.each_char.reverse_each.with_index.inject(nil){|borrow, ci|
	n, i = ci[0].ord-'0'.ord, ci[1]
	m = digits.find{|d| borrow==i-1 ? n<d : n<=d }
	next m.nil? ? i : borrow
}||-2)
over = borrow==-1
p N.each_char.with_index.inject(borrow==-1?nz:0){|a,ci|
	n, i = ci[0].ord-'0'.ord, ci[1]
	m = over ? digits[0] : digits.find{|d| borrow == i ? n<d : n<=d }
	over ||= n<m
	next a*10 + m
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;

    set<int>st ={a, b, c};
    if(st.size() == 2){
        cnt = 1;
    }
    // if(a == b){
    //     cnt++;
    // }
    // if(a == c){

    // }

    if(cnt == 1){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    // cout << 'cnt' << endl;
}


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


int A[100100];

int main(){
	int n,a,b;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		for(int i=a-1;i<b;i++){
			A[i]++;
		}
	}
	
	int cnt=0;
	for(int i=0;i<100001;i++){
		if(A[i]) cnt++;
	}
	
	cout << cnt << endl;
	return 0;
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    ll divisor = K; 
    ll count = 1;
    while (N / divisor != 0) {
        divisor *= K;
        count ++;
    }

    cout << count << endl;
    return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
edges = [[] for _ in range(n)]
dp = [10**10]*n
for _ in range(n-1):
    u,v = LI()
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

ans = [None]*n
ans[0] = 1
dp[0] = a[0]
def dfs(k, p, dp):
    flag = False
    for v in edges[k]:
        if v != p:
            l = bl(dp, a[v])
            if dp[l] > a[v]:
                idx = l
                tmp = dp[l]
                dp[l] = a[v]
                flag = True
                if tmp == 10**10:
                    ans[v] = ans[k] + 1
                else:
                    ans[v] = ans[k]
            else:
                ans[v] = ans[k]
            dfs(v, k, dp)
            if flag:
                dp[idx] = tmp
                flag = False
    return 
dfs(0, -1, dp)
for i in ans:
    print(i)




Measured memory_bytes: 550456
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

const int N = 1001000;

int n, fa[N], ans[N], prt[N], x, y, a[N];
vector<int> g[N]; 

void Dfs(int x, int f) {
	fa[x] = f;
	ans[x] = 0;
	for(int i = 0; i < g[x].size(); i++) {
		int v = g[x][i];
		if(v == f) continue;
		Dfs(v, x);
		if(!ans[v] && a[x] > a[v]) ans[x] = 1;
	}
}

void Upd(int x) {
	prt[x] = ans[x];
	for(int i = 0; i < g[x].size(); i++) {
		int v = g[x][i];
		if(v == fa[x]) continue;
		int tmp = ans[v];
		if(!ans[x] && a[v] > a[x]) ans[v] = 1;
//		printf("%d: %d\n", v, ans[v]);
		Upd(v);
		ans[v] = tmp;
	}
}

void Read(int &x) {
	char ch = getchar();
	x = 0;
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}

int main() {
//	freopen("C.in", "r", stdin);
//	freopen("C.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		Read(a[i]);
	for(int i = 1; i < n; i++) {
		Read(x);
		Read(y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	Dfs(1, 0);
	Upd(1);
	for(int i = 1; i <= n; i++)
		if(prt[i]) printf("%d ", i);
	return 0;
}

Measured memory_bytes: 31232
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
using namespace std;

#define INF 0x3f3f3f3f
#define eps 1e-8

typedef long long ll;
const int MAXN = 2010;

int cost1[MAXN], cost2[MAXN];
int dp[MAXN];

int main() {
	string str1, str2;
	int cnt = 0;
	cin >> str1 >> str2;
	for (int i=0; i<str1.length(); i++) {
		if (str1[i] != str2[i])
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3856
# -*- coding: utf-8 -*-
N, M = map(int, raw_input().split())
a = []
b = []
for _ in range(M):
    _a, _b = map(int, raw_input().split())
    a.append(_a)
    b.append(_b)

ans = [0] * N
for i in range(0, N):
    ans[i] = a.count(i + 1) + b.count(i + 1)
    print ans[i]


Measured memory_bytes: 2568
import collections

def main():
    n, k = map(int, input().split())
    a = [int(i) - 1 for i in input().split()]
    ans = solve(n, k, a)
    print(ans)


def solve(n, k, a):
    arrived = [-1 for i in range(n)]
    path = collections.deque()

    cnt = 0
    pos = 0
    path.append(pos)
    arrived[pos] = cnt

    while True:
        cnt += 1
        pos = a[pos]
        if arrived[pos] != -1:
            break
        arrived[pos] = cnt
        path.append(pos)
        if cnt == k:
            return pos + 1

    while True:
        if path[0] == pos:
            break
        path.popleft()

    #print(f'{path}')
    #print(f'{arrived[pos]}')

    path = list(path)
    k -= arrived[pos]

    ans = path[k % len(path)]

    return ans + 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 97628
<?php
// Your code here!
    fscanf(STDIN,"%d %d %d",$A,$B,$C);
    // echo $A.$B.$C;
    
    for($i=0;$i<$A;$i++){
        $input_line1[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
    }
    
    for($i=0;$i<$B;$i++){
        $input_line2[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
    }
    
    $ans = "";
    foreach($input_line1 as $num_array1){
        $E=[];
        for($j=0;$j<$C;$j++){
            $D_ij =0;
            for($k=0;$k<$B;$k++)$D_ij+= $num_array1[$k]*$input_line2[$k][$j];
            $E[] = $D_ij;
        }
        $ans .= implode(' ',$E)."\n"; 
    }
    
    
    print $ans;

?>


Measured memory_bytes: 12392
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string str;
    cin>>str;
    ll year,month,a,b;
    a=(str[0]-'0')*10+(str[1]-'0');
    b=(str[2]-'0')*10+(str[3]-'0');
    if(a==0 && b==0)
        cout<<"NA"<<endl;
    else if(a==0 && b!=0){
        if(b<=12)
            cout<<"YYMM"<<endl;
        else
            cout<<"NA"<<endl;
    }
    else if(a!=0 && b==0){
        if(a<=12)
            cout<<"MMYY"<<endl;
        else
            cout<<"NA"<<endl;
    }
    else{
        if(a<=12 && b<=12)
            cout<<"AMBIGUOUS"<<endl;
        else if(a>12 && b<=12)
            cout<<"YYMM"<<endl;
        else if(b>12 && a<=12)
            cout<<"MMYY"<<endl;
        else
            cout<<"NA"<<endl;
    }
    return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

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

bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int fiv(int n){
  if(n==0){
    return 0;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}
int main(){
  string s;
  cin>>s;
  deque<char> dq(0);
  rep(i,s.size()){
    dq.push_back(s[i]);
  }
  
  int q ;
  cin>> q;
  vector<tuple<int, int ,char>> sousa(0);
  rep(i,q){
    int res;
    cin >> res;
    if(res==1){
      tuple<int,int,char> kari = make_tuple(res,0,0);
      sousa.push_back(kari);
    }
    else if(res ==2){
      int ress;
      char mozi;
      cin>>ress>>mozi;
      tuple<int ,int,char> kaari =make_tuple(res,ress,mozi);      
      sousa.push_back(kaari);
    }
  }
  int numre=0;
  
  for(int i=0;i<q;i++){
    if(get<0>(sousa[i])==1){
      numre ++;
    }
    else{
      if(get<1>(sousa[i])==1 && numre %2==0){
        dq.push_front(get<2>(sousa[i]));
      }
      
      else if(get<1>(sousa[i])==1 && numre %2==1){
        dq.push_back(get<2>(sousa[i]));
      }
      else if(get<1>(sousa[i]) ==2 && numre %2 ==0){
        dq.push_back(get<2>(sousa[i]));
      }
      else if(get<1>(sousa[i]) ==2 &&numre%2 ==1){
        dq.push_front(get<2>(sousa[i]));
      }
    }
  }
  if(numre %2 ==1){
    reverse(dq.begin(),dq.end());
  }
  rep(i,dq.size()){
    cout<<dq[i];
  }
  
}





Measured memory_bytes: 4992
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

string c = "RGBY";

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  vector<string> mp(h);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      mp[i].push_back(c[((i + j) / d) % 2 + (((i - j + 2000) / d) % 2) * 2]);
    }
  for (int i = 0; i < h; i++)
    cout << mp[i] << endl;
  return 0;
}


Measured memory_bytes: 768
def main():
    s = input()
    t = input()

    n = len(s)
    ds,dt = {},{}

    for i in range(n):
        if s[i] in ds:
            if ds[s[i]] != t[i]:
                return 'No'
        else:
            ds[s[i]] = t[i]

        if t[i] in dt:
            if dt[t[i]] != s[i]:
                return 'No'
        else:
            dt[t[i]] = s[i]

    return 'Yes'

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3632
# https://atcoder.jp/contests/abc154/tasks/abc154_a


def main():
    s, t = input().split(" ")
    a, b = map(int, input().split(" "))
    u = input()
    if u == s:
        a -= 1
    elif u == t:
        b -= 1
    print("%d %d" % (a, b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int count = 0;
        for(int i = 0; i < num; i++){
            int sta = sc.nextInt();
            int end = sc.nextInt();
            count += end - sta + 1;
        }
        System.out.print(count);
	}
}

Measured memory_bytes: 25960
#include <stdio.h>
int main () {
  int n;
  int i;
  char s[10000];

  for (i = 0; i < 10000; i++) {
    s[i] = '\0';
  }

  scanf ("%d", &n);
  scanf ("%s", s);

  for (i = 0; s[i] != '\0'; i++) {
    s[i] += n;
    if (s[i] > 90) s[i] = s[i] - 26;
  }

  for (i = 0; s[i] != '\0'; i++) {
    printf ("%c", s[i]);
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    map<int,int> am;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        am[A[i]]++;
    }
    vector<int> a;
    for(auto&& i : am){
        a.pb(i.se);
    }
    SORT(a);
    int ans = 0;
    int n = a.size();
    for (int i = 0; i < n - K; i++) {
        ans += a[i];
    }
    pr(ans);
}

Measured memory_bytes: 11516
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		Point[] p=new Point[n];
		for(int i = 0; i<n; i++){
			long x = sc.nextLong();
			long y = sc.nextLong();
			p[i]=new Point(x,y);
		}
		long ans=Long.MAX_VALUE;
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				for(int k = 0; k<n; k++){
					for(int l = 0; l<n; l++){
						int count=0;
						for(int u=0; u<n; u++){
							if(p[u].x<=p[i].x && p[u].x>=p[j].x && p[u].y<=p[k].y && p[u].y>=p[l].y){
								count++;
							}
						}
						if(count>=t){
							ans=Math.min(ans,(p[i].x-p[j].x)*(p[k].y-p[l].y));
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
	static class Point{
		long x;
		long y;
		public Point(long x,long y){
			this.x=x;
			this.y=y;
		}
	}
}


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

using ll = int64_t;

constexpr ll COM_MAX = (ll)1e5;
constexpr long long MOD = (1e9+7);
vector<ll> fac(COM_MAX),finv(COM_MAX),inv(COM_MAX);
// 前処理
void comb_init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<COM_MAX;++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
// 二項係数計算
ll comb(ll n,ll k){
  if(n<k)return 0;
  if(n<0||k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
// 重複組み合わせ
ll nHk(ll n,ll k){
  return comb(n+k-1,n-1);
}

template<ll MOD=ll(1e9+7)>
ll mod_pow(ll n,ll p){
  ll ans=1LL;
  while(p){
    if(p&1)ans*=n;
    n*=n;
    p>>=1;
    ans%=MOD;
    n%=MOD;
  }
  return ans;
}

signed main(){

  comb_init();
  ll n,k;
  cin>>n>>k;
  cout<<comb(n+k-1,n)<<endl;

}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int h,w,n;
    cin >>h >>w >>n;

    vector<pi> v(n);
    //既に見終わった
    set<pi> s;
    //黒い位置
    set<pi> black;
    rep(i,n)
    {
        int a,b;
        scanf(" %d %d", &a, &b);
        v[i]=pi(a,b);
        black.insert(v[i]);
    }

    #define IN(x,y) (1<=x && x<=w-2 && 1<=y && y<=h-2)
    ll ans[10]={0};

    rep(i,n)
    {
        for(int dy=-2; dy<=0; ++dy)for(int dx=-2; dx<=0; ++dx)
        {
            int sy=v[i].fi+dy, sx=v[i].se+dx;
            if(IN(sx,sy))
            {
                if(s.find(pi(sy,sx)) == s.end())
                {
                    s.insert(pi(sy,sx));
                    int ct=0;
                    rep(j,3)rep(k,3)
                    {
                        if(black.find(pi(sy+j,sx+k)) != black.end()) ++ct;
                    }

                    // printf("(%d,%d) = %d\n",sx,sy,ct );
                    ++ans[ct];
                }
            }
        }
    }

    ll nonzero=0;
    for(int i=1; i<=9; ++i) nonzero+=ans[i];
    ans[0]=(ll)(h-2)*(w-2)-nonzero;

    rep(i,10) cout << ans[i] << endl;
    return 0;
}


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

using namespace std;

bool compare(string S1, string S2)
{
	if (S1.size() != S2.size()) { return S1.size() > S2.size(); }

	return S1 > S2;
}

int main()
{
	int H, W; char c[70];

	while (true)
	{
		scanf("%d", &W);
		scanf("%d", &H);

		if (H == 0 && W == 0) { break; }

		vector<string> R;

		for (int i = 0; i < H; i++)
		{
			scanf("%s", c);

			R.push_back(c);
		}

		vector<vector<string> > dp(H, vector<string>(W, ""));

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (isdigit(R[i][j]))
				{
					if (R[i][j] != '0')
					{
						dp[i][j] = R[i][j];
					}

					if (i != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]) && dp[i - 1][j] != "")
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
					}

					if (j != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]) && dp[i][j - 1] != "")
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
					}
				}
			}
		}

		string ret = "";

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (compare(dp[i][j], ret))
				{
					ret = dp[i][j];
				}
			}
		}

		printf("%s\n", ret.c_str());
	}

	return 0;
}

Measured memory_bytes: 3324
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val xList = readLine()!!.split(" ").map { it.toInt() }
    val ans = xList.map { Math.min(it, Math.abs(k-it)) }.sum()*2
    println(ans)
}

Measured memory_bytes: 36008
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
  
struct Edge{
    int a,b,d;
    bool operator < (const Edge a)const{
        return d < a.d;
    }
};
  
int par[100],rank_[100];
void init(int n){ for(int i = 0; i < n; i++) par[i] = i, rank_[i] = 1;}
int find(int x){  if(par[x] == x) return x;return par[x] = find(par[x]);}
bool unite(int _a,int _b){
    int a = find(_a), b = find(_b);
    if(a == b) return false;
    if(rank_[a]>rank_[b]) par[b] = a;
    else{par[a] = b;if(rank_[a]==rank_[b]) rank_[b]++;}
    return true;
}
  
int main(){
    int N,M;
    while(cin >> N , N){
        init( N );
        cin >> M;
        Edge e[10000];
        for(int i = 0;i < M; i++) scanf("%d,%d,%d",&e[i].a,&e[i].b,&e[i].d);
        sort(e,e+M);
        int ans = 0;
        for(int i = 0; i < M; i++){
            if(unite(e[i].a, e[i].b)) ans += e[i].d/100-1;
            
        }
        printf("%d\n" ,ans);
    }
}

Measured memory_bytes: 1312
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  while(cin>>a>>b>>c,a){
    int p[a];
    for(int i=0;i<a;++i) cin>>p[i];
    int x=0, y;
    for(int i=b-1;i<c;++i)
      if(p[i]-p[i+1]>=x) x=p[i]-p[i+1], y=i;
    cout<<y+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long

int a,b,c;
vector<int> v;
signed main() {
	cin >> a >> b >> c;

	int temp = b / a;
	if (temp < c) {
		cout << temp << endl;
	}
	else {
		cout << c << endl;
	}

	
}



Measured memory_bytes: 256
#include<stdio.h>

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

        int A[n][m], B[m][l];
        for(int i=0; i<n; i++){
                for(int j=0; j<m; j++){
                        scanf("%d", &A[i][j]);
                }
        }
        for(int i=0; i<m; i++){
                for(int j=0; j<l; j++){
                        scanf("%d", &B[i][j]);
                }
        }

        for(int i=0; i<n; i++){
                for(int j=0; j<l; j++){
                        long sm = 0;
                        for(int k=0; k<m; k++) sm += A[i][k]*B[k][j];
                        printf("%ld", sm);
                        if(j==l-1) putchar('\n');
                        else putchar(' ');
                }
        }
        return 0;
}


Measured memory_bytes: 2120
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

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

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, M, X int

func main() {
	sc.Split(bufio.ScanWords)
	//X: 最初のマス
	N, M, X = nextInt(), nextInt(), nextInt()

	ans := make([]int, 2)
	for i := 0; i < M; i++ {
		tmp := nextInt()
		if X < tmp {
			ans[1]++
		} else {
			ans[0]++
		}
	}

	fmt.Println(minInt(ans[0], ans[1]))
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll x;
    cin >> x;

    if(x < 1200) {
        out("ABC");
    }
    else {
        out("ARC");
    }

    re0;
}

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

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

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

    ll X, K, D; cin >> X >> K >> D;

    if(X < 0) X *= -1;

    ll rem = K;

    if(rem < X/D){
        cout << X-rem*D << endl;
        return 0;
    }

    rem -= X/D;
    X = X-D*(X/D);

    //cout << rem << " " << X << endl;

    if(rem%2 == 1){
        cout << abs(X-D) << endl;
    }else{
        cout << X << endl;
    }

    return 0;

}

Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

ll DP[100010];

ll W[110], V[110];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, w, v = 0;
    cin >> N >> w;
    for (int i = 0;i < N;i++) cin >> W[i] >> V[i];
    for (int i = 0;i < N;i++) v += V[i];
    memset(DP, 0x7f, sizeof(DP));
    DP[0] = 0;
    int sol = 0;
    for (int i = 0;i < N;i++) {
        for (int j = v;j >= 0;j--) {
            if (j >= V[i] && DP[j - V[i]] + W[i] <= w) {
                DP[j] = min(DP[j], DP[j - V[i]] + W[i]);
                sol = max(sol, j);
            }
        }
    }
    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
char map[500];
int lt,d,n,i;
int main(){
	scanf("%d%s",&n,map+1);
	d=0;lt=0;
	for(int i=1;i<=n;i++){
		if(map[i]=='(')
			d++;
		if(map[i]==')'){
			if(d) d--;
			else lt++;
		}
	}
	for(int i=0;i<lt;i++)
		printf("(");
	printf("%s",map+1);
	for(int i=0;i<d;i++)
		printf(")");
	return 0;
} 

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,a,b,c,d;
    t = 1;
    while(t--) {
     cin >> a >> b >> c >> d;
     cout << min(a, b) + min(c, d) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque
N,M = map(int,input().split())
cnct = [[] for i in range(N+1)]
for _ in range(M):
  A,B = map(int,input().split())
  cnct[A].append(B)
  cnct[B].append(A)
Q = deque()
Q.append(1)
ans = [0]*(N+1)
vstd = [0]*(N+1)
while Q:
  temp = Q.popleft()
  for a in cnct[temp]:
    if vstd[a] == 0:
      ans[a] = temp
      vstd[a] = 1
      Q.append(a)
print('Yes')
for a in ans[2:]:
  print(a)

Measured memory_bytes: 35492