akhauriyash/Code-Regression huggingface dataset:
tl = [0] * 3
n, tl[0], tl[1], tl[2] = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))
ans = -1
arr = None
for mask in range(1 << (2 * n)):
	grp = [[], [], []]
	for i in range(n):
		ty = (mask >> (i * 2)) & 3
		if ty > 0:
			grp[ty - 1].append(l[i])
	res = 0
	for i in range(3):
		res += abs(sum(grp[i]) - tl[i]) + 10 * (len(grp[i]) - 1)
		if len(grp[i]) == 0:
			res = ans
			break
	if ans == -1 or res < ans:
		ans = res
		arr = grp
print(ans)

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

using namespace std;

const int maxn=2e5+5;
int n;
long long k;
long long a[maxn], f[maxn];
bool cmp(int x, int y){
    return x>y;
}
bool check(long long t){
    long long tmp=0;
    for(int i=0;i<n;i++){
        tmp += max(0LL, a[i] - t / f[i]);
    }
//    printf("%lld %lldss\n",t,tmp);
    return tmp <= k;
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",a+i);
    }
    for(int i=0;i<n;i++){
        scanf("%lld",f+i);
    }
    sort(f,f+n,cmp);
    sort(a,a+n);
    long long l=0, r = 1LL*a[n-1]*f[0], ans;
    while(l<=r){
        long long mid=(l+r)>>1;
        if(check(mid)){
            ans = mid;
            r = mid - 1;
        }
        else{
            l = mid + 1;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
  int A,B,K;
  string ans = "IMPOSSIBLE";

  cin >> A >> B;

  K = (A + B) / 2;
  if (abs(A - K) == abs(B - K)) {
    cout << K << endl;
  }
  else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <cmath>

using namespace std;

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

typedef long long ll;
typedef unsigned int uint;
typedef long double ld;

const int INT_INF=1e9;
const ll LONG_INF=1e18;
const double pi = acos(-1);
const int MAXN = 1e6;
const int MAXM = 1e6;

void solve() {
    string s, t;
    cin >> s >> t;
    int ans = t.length();
    for (int i = 0; i + t.length() <= s.length(); ++i) {
        int cur = 0;
        for (int j = 0; j < t.length(); ++j) {
            if (t[j] != s[i + j]) {
                ++cur;
            }
        }
        ans = min(ans, cur);
    }
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(9);
#ifdef LOCAL
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    solve();

#ifdef LOCAL
    cout << "Time:\n";
    cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << '\n';
#endif

}


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

int main(){
    int m,f,b;
    cin >> m >> f >> b;

    if((m+f)<b){
        cout << "NA" << endl;
    }

    else if(m>=b){
        cout << '0' << endl;
    }

    else{
        cout << b-m << endl;
    }
    

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  char A[4]={'A','T','C','G'};
  int ans=0;
  int temp=0;
  for(auto c:S){
    if(find(A,A+4,c)!=A+4)temp++;
    else temp=0;
    ans=max(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    int x = a+b;
    int y = a-b;
    int z = a*b;

    int max = x;

    if (max < y)
        max = y;
    if (max < z)
        max = z;

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)


int main()
{
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << W * H / 2. << " " << (2 * x == W && 2 * y == H )<< endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.NoSuchElementException;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner();
		int N=sc.nextInt();
		String[] S=new String[N];
		HashMap<String,Integer> map=new HashMap<String, Integer>();
		int sz=0;
		for(int i=0;i<N;++i) {
			S[i]=sc.next();
			if(map.containsKey(S[i])) {
				map.put(S[i], map.get(S[i])+1);
				sz=Math.max(map.get(S[i]), sz);
			}else {
				map.put(S[i], 1);
				sz=Math.max(sz,1);
			}
		}
		ArrayList<String> list=new ArrayList<String>();
		for(Entry<String, Integer> a:map.entrySet()) {
			if(a.getValue()==sz) {
				list.add(a.getKey());
			}
		}
		Collections.sort(list);
		for(String s:list) {
			System.out.println(s);
		}
		
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

class Scanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 72736
#include <stdio.h>

int main() {

  int i, n, d[10001], max = -1000000, min = 1000000;
  long long s = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++) {
    scanf("%d", &d[i]);
    s = s + d[i];
    if ( d[i] < min )
      min = d[i];
    if ( d[i] > max)
      max = d[i];
  }
  printf("%d %d %lld\n", min, max, s);

  return 0;

}

Measured memory_bytes: 640
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方
# これもなかなか早い
# ヒープは追加も要素の取り出しもO(log n)で住むので、
# 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが
# not in があるのでO(n K log n)では？
# pythonのヒープは使い方に癖があるのでこの機会に習得しよう
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

heap = []  # ヒープといっても順序を工夫したただのリスト

from queue import PriorityQueue
heap = PriorityQueue()
heap.put((-(A[0] + B[0] + C[0]), 0, 0, 0))

considerd = set()

ans = []
for k_th in range(1, K+1):
    heap_max, i, j, k = heap.get()
    # print(heap_max)
    ans.append(-heap_max)
    for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
        i_new, j_new, k_new = i + di, j + dj, k + dk
        if i_new >= X or j_new >= Y or k_new >= Z:
            continue
        if (i_new, j_new, k_new) in considerd:
            continue
        considerd.add((i_new, j_new, k_new))
        heap.put((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new))


print(*ans, sep='\n')


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

int main(){
	
	int n,a;
	int S[10];
	char s[10];
	
	cin>>n;
	while(n!=0){
		cin>>s;
		for(int i=0;i<8;i++)
			S[i]=s[i]-'0';
		
		int max=0,min=0;
		sort(S,S+8);
		for(int i=0;i<8;i++){
			if(S[7-i]==0){
				if(max!=0)
					max=max*10;
			}
			else
				max=max*10+S[7-i];
			if(S[i]==0){
				if(min!=0)
					min=min*10;
			}
			else min=min*10+S[i];
			}
		cout<<max-min<<endl;
		n--;
	}
		

}

Measured memory_bytes: 1180
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    int n,k;
    long double win_p = 0;
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        int e = 0;
        while(i*pow(2.0,e) < k){
            e++;
        }
        win_p += (1.0/n) * pow((1.0/2),e);
    }
    cout << std::setprecision(12) << win_p << endl;
}

Measured memory_bytes: 256
fun main() {
    val _n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt)
    val res:Int = a.foldIndexed(0, {index,acc,v -> if(index%2==0 && v%2==1) acc+1 else acc})
    println(res)
}


Measured memory_bytes: 36428
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const double pi=acos(-1);

int main(){
  rep(i,MOD){
    string s;
    cin >> s;
    if(s=="-")return 0;
    int m;
    cin >> m;
    rep(i,m){
      int h;
      cin >> h;
      string t=s.substr(0,h);
      string u=s.substr(h,s.size()-h);
      s="";
      s+=u;
      s+=t;
    }
    cout << s << endl;     
  }
  
}



Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if (a % 2 == 1 && b % 2 == 1) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		}
	}
}


Measured memory_bytes: 21844
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int T, N;
    bool input() {
        scanf("%d %d\n", &T, &N);
        return (T != 0 && N != 0);
    }
    void solve() {
        string S = N.to!string;
        int X = cast(int)(S.length);
        int Ans = -1;
        int[] Pat;
        bool Reject;
        void dfs(int index, int[] r) {
            if (index == X) {
                //writeln(r);
                int x = r.reduce!"a + b";
                if (x > T) return;
                if (x > Ans) {
                    Ans = x;
                    Pat = r;
                    Reject = false;
                } else if (x == Ans) {
                    Reject = true;
                }
            }
            for (int i = index + 1; i <= X; i++) {
                string s = S[index .. i];
                //if (s.length > 1 && s[0] == '0') continue;
                dfs(i, r ~ s.to!int);
            }
        }
        dfs(0, []);
        if (Reject) {
            writeln("rejected");
        } else if (Ans < 0) {
            writeln("error");
        } else {
            writefln("%d %(%s %)", Ans, Pat);
        }
    }
    while (input) solve;
}

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

int main(){
  int n; cin >>n; int cnt=1;
  vector<int>v(n);
  for(int i=0; i<n; i++) cin >>v[i];
  int a=v[0];
  for(int i=1; i<n; i++)
  {if(v[i]<a){cnt++; a=v[i];}}
  cout <<cnt;
return 0;}

Measured memory_bytes: 1024
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	string a;
	int n;
	int ans = 0;

	cin >> n;
	cin >> a;

	rep(i, 0, n) {
		int cb[26] = { 0 }, cc[26] = { 0 };
		int can = 0;
		rep(j, 0, i) {
			cb[(int)a[j]-97]++;
		}
		rep(j, i, n) {
			cc[(int)a[j] - 97]++;
		}
		rep(i, 0, 26) {
			if (cb[i] >= 1 && cc[i] >= 1) {
				can++;
			}
		}
		ans = max(can, ans);
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int m, n;
int hon[100];

int f(int w) {
	int honIdx = 0;
	for (int i = 0; i < m; i++) {
		int curW = w;
		while (hon[honIdx] <= curW) {
			curW -= hon[honIdx];
			honIdx++;
			if (honIdx == n) return 1;
		}
	}
	return 0;
}

int binsearch_lower_bound() {
  int low = 1; // 範囲の下限
  int high = 1500000 + 1; // 範囲の上限。解はあれば [low, high] の中に存在する
  while (low < high) {
    int mid = (low + high) / 2;  // 中心点（この実装ではオーバーフローしうるので注意）
    int midval = f(mid);  // 中心での値
    
    // 解の範囲を狭める
    if (midval < 1) low = mid + 1;
    else high = mid;
  }
  return low;
}

int main() {
	while(cin >> m >> n, m || n) {
		for (int i = 0; i < n; i++) {
			cin >> hon[i];
		}
		cout << binsearch_lower_bound() << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9+7;
LL const MaxSize = 3e5 + 5;
//LL const MOD = 998244353;

/*

#https://atcoder.jp/contests/abc147/tasks/abc147_d
#Xor Sum 4
"""
iterate over bits
1. calculate how many bits we have on that position
2. for each 1, we need to add num 0s * num 1s * 2s
3. sum them up

1. python version gets TLE due to the IO
2. in c++ version, all needs to be LL
 */


LL N, a[MaxSize];

int main() {
        ios_base::sync_with_stdio(false);
        //freopen("/Users/georgeli/A_1.in", "r", stdin);

        cin >> N;

        LP(i, 0, N){
        	cin >> a[i];
        }

        LL ans = 0;
        int maxS = 61;
        LL base = 1L;
        LP(shift, 0, maxS){ //instead of spending time calculating tight boudary, relax it a bit
            LL n1 = 0;
            LP(i, 0, N){
                if (a[i] >> shift & 1) //this is what got me: I didn't use & 1, for reason unknown the result is in correct
                    n1 += 1;
            }


            //cout << "n1: " << n1 << endl;
            LL part = n1 * (N - n1);
            //cout << shift << " " << part << " " << ans << endl;
            part %= MOD;
            part *= base;
            part %= MOD;
            ans += part;
            ans %= MOD;
            base *= 2L;
            base %= MOD;//!!!! this is what got me!, shift doesn't work this way
        }

        cout << ans;
        return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

// 比較関数
bool my_compare(pair<ll, int> a, pair<ll, int> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
        // return a.first < b.first; // 昇順
        return a.first > b.first; // 降順
    }
}

int main() {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<pair<ll, int>> score(A + B + C);
    rep(i, 0, A)
    {
        cin >> score[i].first;
        score[i].second = 0; // 0 = red
    } 
    rep(i, A, A + B)
    {
        cin >> score[i].first;
        score[i].second = 1; // 1 = green
    } 
    rep(i, A + B, A + B + C)
    {
        cin >> score[i].first;
        score[i].second = 2; // 2 = colorless
    } 
        
    sort(score.begin(), score.end(), my_compare);

    int cnt = 0;
    ll ans = 0;
    int cnt0 = 0; // num of red apple
    int cnt1 = 0; // num of green apple
    int idx = 0;

    while (cnt < X + Y)
    {
        if (cnt0 == X && score[idx].second == 0)
        {
            idx++;
            continue;
        }
        else if (cnt1 == Y && score[idx].second == 1)
        {
            idx++;
            continue;
        }
        ans += score[idx].first;
        if (score[idx].second == 0) cnt0++;
        else if (score[idx].second == 1) cnt1++;
        cnt++;
        idx++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 4992
#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>;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int ans = x;
  rep(i, n) {
    if (s[i] == 'I') ans = max(ans, ++x);
    else ans = max(ans, --x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int findNextBottom(vector<int> prices, int start) {
    int bottom = -1;
    if (start == 0) {
        bottom = 0;
    }
    for (int i = start + 1; i < prices.size(); i++) {
        if (bottom < 0) {
            if (prices[start] > prices[i]) {
                bottom = i;
                continue;
            } else if (prices[start] == prices[i]) {
                continue;
            } else {
                return -1;
            }
        } else {
            if (prices[bottom] > prices[i]) {
                bottom = i;
                continue;
            } else if (prices[bottom] == prices[i]) {
                continue;
            } else {
                return bottom;
            }
        }
    }
    return bottom;
}

int findNextPeak(vector<int> prices, int start) {
    int peak = -1;
    for (int i = start + 1; i < prices.size(); i++) {
        if (peak < 0) {
            if (prices[start] < prices[i]) {
                peak = i;
                continue;
            } else if (prices[start] == prices[i]) {
                continue;
            } else {
                return -1;
            }
        } else {
            if (prices[peak] < prices[i]) {
                peak = i;
                continue;
            } else if (prices[peak] == prices[i]) {
                continue;
            } else {
                return peak;
            }
        }
    }
    return peak;
}

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

    vector<int> a(n);

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

    long long money = 1000LL;
    long long stock = 0;
    int date = 0;

    while (date < n) {
        int nextBottom = findNextBottom(a, date);
        if (nextBottom < 0) {
            break;
        }
        int nextPeak = findNextPeak(a, nextBottom);
        if (nextPeak < 0) {
            break;
        }
        // 直近の谷日が見つかれば、買う
        long long buy = money / a[nextBottom];
        money = money - buy * a[nextBottom];
        stock = stock + buy;
        // 直近の山頂日が見つかれば、売る
        money = money + stock * a[nextPeak];
        stock = 0;
        // 最終締め日に更新
        date = nextPeak;
    }

    cout << money << endl;

    return 0;
}


Measured memory_bytes: 3564
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
left, right = 0, 0
for i in range(X-1, -1, -1):
    if i in A:
        left += 1
for i in range(X+1, N+1):
    if i in A:
        right += 1
print(min(left, right))


Measured memory_bytes: 61876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n;cin >> n;
    vi a(n);
    rep(i,n-1){
        int b;cin >> b;
        --b;
        a[b]++;
    }

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

Measured memory_bytes: 3984
N=int(input())
A=[]
B=[]
for _ in range(N):
  a, b=map(int, input().split())
  tmpa=a%b
  A.append(tmpa)
  B.append(b)
ans=0
for i in range(N-1, -1, -1):
  tmp=B[i]-(A[i]+ans)%B[i]
  if tmp==B[i]:
    tmp=0
  ans+=tmp
print(ans)
  


Measured memory_bytes: 16840
#include<stdio.h>
int main(void){
	int a,b,c,max,min;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a>b){
		max=a;
		min=b;
	}else{
		max=b;
		min=a;
	}if(c>max){
		max=c;
	}else if(c<min){
		min=c;
	}
	printf("%d",max-min);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	rep(i, n - 1) {
		if (a[i] + a[i + 1] > x) {
			ans += (a[i] + a[i + 1] - x);
			a[i + 1] = max(0, a[i + 1] - (a[i] + a[i + 1] - x));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3720
import java.util.Scanner;

/**
 *
 * @author Owner
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        char[] c=sc.nextLine().toCharArray();
        boolean f[]=new boolean[26];
        boolean flg=false;
        
        for(int i=0;i<f.length;i++){
            f[i]=false;
        }
        for(int i=0;i<c.length;i++){
            f[c[i]-'a']=true;
        }
        for(int i=0;i<f.length&&flg==false;i++){
            if(f[i]==false){
                System.out.println((char)(i+'a'));
                flg=true;
            }
        }
        if(flg==false){
            System.out.println("None");
        }
        
    }
    
}

Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 112345;
int v[44];
int main() {
    int n, m, k;
    m = 0;
    int ans = 0;
    for (int i = 0; i<5; ++i) {
        scanf("%d", v+i);
        if (v[i]%10 && (v[i]%10 <= m%10 || m == 0)) m = v[i];
        ans += (v[i]+9)/10*10;
    }
    printf("%d\n", ans - (m+9)/10*10 + m);
}


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

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

	ll l,r;
	


	cin >> l >> r;
	
	int ans=2019;
	
	int diff=r-l;
	if(diff>=2019){
		cout << 0 << endl;
		return 0;
	}
	diff=diff%2019;
	
	
	l=l%2019;
	r=l+diff;
	
	
	
	//int m=2019; //min
	
	for(int i=l;i<r;i++){
		for(int j=i+1;j<=r;j++){
			ans=min((i*j)%2019,ans);
		}
	}
	
	
	
	cout << ans << "\n";
	
	return 0;
}


//vector<int> a(n);  sort(a.begin(),a.end());
//cout << "test" << "\n";


//g++ -o a a.cpp


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int s;
  int cnt =1;

  cin >> s;

  vector<int> a(s*1000, 0);
  a[0] = 0;
  a[s]++;

  while(a[s] <= 1){
    if(s % 2 == 0){
      s = s/2;
    }else{
      s = 3*s + 1;
    }
    a[s]++;
    cnt ++;

  }

  cout << cnt << endl;
}


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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif


const LL mod = 998244353;

LL esp(LL x, LL e) {
    if (e == 0) return 1;
    if (e%2 == 1) return (x * esp(x, e-1)) % mod;
    return esp((x*x)%mod, e/2);
}

// Computes the inverse of n modulo m.
// Precondition: n, m > 0 and gcd(n, m) == 1.
// The returned value is always > 0.
// ACHTUNG: It must hold max(m, n) <= 2**31 to avoid integer overflow.
ULL Inverse(ULL n, ULL m) {
    if (n == 1) return 1;
    LL y = Inverse(m % n, n);
    return m - ((m * y - 1) / n) % m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    LL N, M, K;
    cin >> N >> M >> K;
    if (N == 1) {
        cout << M << "\n";
        return 0;
    }
    if (M == 1) {
        if (K == N-1) cout << 1 << "\n";
        else cout << 0 << "\n";
        return 0;
    }

    LL prod = (M * esp(M-1, N-1)) % mod;
    LL res = prod;
    LL binom = 1;
    LL invM1 = Inverse(M-1, mod);
    
    for (int i = 1; i <= K; i++) {
        prod = (prod * invM1) % mod;
        binom = (binom*(N-i)) % mod;
        binom = (binom * Inverse(i, mod)) % mod;
        res += (prod * binom) % mod;
        res %= mod;
    }
    cout << res << "\n";
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int MAX = 110;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

// 構造体
struct Edge {
  int to; // 辺が繋がっている先の頂点
  int cost; // 辺の重み
};

struct Graph {
  int V, E; // 頂点数、辺数
  vector<Edge> graph[MAX]; // グラフ
};

// グローバル変数
Graph g;
int dist[MAX]; // ある頂点から別の頂点までの最短距離
int tmp[MAX];
bool used[MAX][MAX];

// ダイクストラ法で始点から全頂点への最短距離を求める
void dijkstra(int v) {
  dist[v] = 0;
  priority_queue<P, vector<P>, greater<P> > pque;
  P cur = P(0, v);
  pque.push(cur);

  while (!pque.empty()) {
    cur = pque.top(); // O(1) ← この操作はN回行われる
    pque.pop(); // O(logN) ← この操作はN回行われる
    int from = cur.second;
    int d = cur.first;
    for (int i = 0; i < g.graph[from].size(); i++) {
      Edge e = g.graph[from][i];
      if (dist[e.to] > d + e.cost) {
        dist[e.to] = d + e.cost;
        pque.push(P(dist[e.to], e.to)); // O(1) ←　この操作は2M回行われる
      }
    }
  }
}

void bfs(int v) {
  queue<int> que;
  int cur = v;
  que.push(cur);

  while (!que.empty()) {
    cur = que.front();
    que.pop();
    for (int i = 0; i < g.graph[cur].size(); i++) {
      Edge e = g.graph[cur][i];
      if (tmp[cur] + e.cost == dist[e.to]) {
        tmp[e.to] = tmp[cur] + e.cost;
        used[cur][e.to] = true;
        que.push(e.to);
      }
    }
  }
}

int main() {
  // 入力
  cin >> g.V >> g.E;
  int a[g.E], b[g.E], c;
  Edge e;
  for (int i = 0; i < g.E; i++) {
    cin >> a[i] >> b[i] >> c;
    a[i]--; b[i]--;
    e.cost = c;
    e.to = b[i];
    g.graph[a[i]].push_back(e);
    e.to = a[i];
    g.graph[b[i]].push_back(e);
  }

  for (int i = 0; i < g.V; i++) {
    fill(dist, dist + MAX, INF);
    dijkstra(i);
    fill(tmp, tmp + MAX, 0);
    bfs(i);
  }

  int ans = 0;
  for (int i = 0; i < g.E; i++) {
    if (!used[a[i]][b[i]] && !used[b[i]][a[i]]) ans++;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Main {
	/**
	 * Main method.
	 */
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
	    BufferedReader in = new BufferedReader(reader);
	    
	    long n = Long.parseLong(in.readLine());
	    
	    long tmp = 1;
        long answer = n;

        while (n != 0)  {
            long cur = (n - 1) * tmp + (tmp - 1);

            if (digitsSum(cur) > digitsSum(answer) || (digitsSum(cur) == digitsSum(answer) && cur > answer)) {
            	answer = cur;
            }
            
            n /= 10;
            tmp *= 10;
        }

	    System.out.println(digitsSum(answer));
 
	}
	
	static long digitsSum(long n) {
		long sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}

Measured memory_bytes: 22996
n =  gets.chomp.to_i
alist = []
maxa = 1
seca = 1
n.times do |ni|
  alist[ni] = gets.chomp.to_i
  if seca <= alist[ni]
    seca = alist[ni]
  end
  if maxa <= seca
    newmax = seca
    seca = maxa
    maxa = newmax
  end
end
alist.each do |ai|
  if ai == maxa
    puts seca
  else
    puts maxa
  end
end


Measured memory_bytes: 4808
#include<bits/stdc++.h>
using namespace std;
#define ll             long long
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define m(arr,n,type)  type *arr=new type[n];
#define pii             pair<int,int>
#define mod             1000000007

int32_t main()
{

    int a,b,i,s1,s2;
    cin>>a>>b;
    s1=0;
    s2=0;
    for(i=a-1;i>0;i--){
        s1=s1+i;
    }
    for(i=b-1;i>0;i--){
        s2=s2+i;
    }
    cout<<s1+s2;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

const int MAX=510000;

vll fac(MAX);
vll finv(MAX);
vll inv(MAX);

void combinit(ll m){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    rep2(i,2,MAX){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}

ll combi(ll n,ll k,ll m=inf){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}

int main(){
    combinit(inf);
    int n,k;cin>>n>>k;
    vll a(n);rep(i,n)cin>>a[i];
    sort(all(a));
    ll ans=(ll)0;ll tmp;
    rep(i,n){
        if(i<=n-k){
            tmp=combi(n-1-(ll)i,k-1)*a[i];
            tmp%=inf;
            ans-=tmp;
        }
        if(k-1<=i){
            tmp=combi((ll)i,k-1)*a[i];
            tmp%=inf;
            ans+=tmp;
        }
        ans%=inf;
        if(ans<0)ans+=inf;
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int A[2][200], B[2][200];

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

    int N;
    std::cin >> N;

    for(int i=0;i<2;++i){
        for(int j=0;j<N;++j){
            std::cin >> A[i][j];
        }
    }

    B[0][0] = A[0][0];
    for(int i=1;i<N;++i){
        B[0][i] = B[0][i-1] + A[0][i];
    }

    for(int i=0;i<N;++i){
        B[1][i] = B[0][i] + A[1][i];
        if(i - 1 >= 0){
            B[1][i] = max(B[1][i], B[1][i-1] + A[1][i]);
        }
    }

    // for(int i=0;i<2;++i){
    //     for(int j=0;j<N;++j){
    //         std::cout << B[i][j] << " \n"[j+1 == N];
    //     }
    // }
    
    std::cout << B[1][N-1] << std::endl;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int N, K;
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll sum[N+1];
    sum[0] = 0;
    for (int i = 1; i <= N; i++) {
        sum[i] = sum[i-1] + a[i-1];
    }

    vector<ll> B;

    for (int l = 1; l <= N; l++) {
        for (int r = l; r <= N; r++) {
            ll b = sum[r] - sum[l-1];
            B.emplace_back(b);
        }
    }


    for (int shift = 60; shift >= 0; shift--) {
        vector<ll> one;
        vector<ll> zero;


        for (int i = 0; i < B.size(); i++) {
            if ((B[i] >> shift) & 1 == 1) {
                one.push_back(B[i]);
            } else {
                zero.push_back(B[i]);
            }
        }

        if (one.size() >= K) {
            B = one;
        }
    }

    ll ret = ~((ll) 0);
    for (int i = 0; i < B.size(); i++) {
        ret &= B[i];
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 13660
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  int ans = N / (A + B) * A;
  if (N % (A + B) >= A)
    ans += A;
  else
    ans += N % (A + B);
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			int n = s.nextInt();
			int[] v = new int[n];
			int[] c = new int[n];
			for (int i = 0; i < n; i++) {
				v[i] = s.nextInt();
			}
			for (int i = 0; i < n; i++) {
				c[i] = s.nextInt();
			}
			int result = 0;
			for (int i = 0; i < n; i++) {
				int d = v[i] - c[i];
				if (d > 0) {
					result += d;
				}
			}
			System.out.println(result);
		}
	}

}

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

int main() {
	int n,a[100];
	cin >> n;
	for (int i = 0; i <= n-1; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i <= n-1; i++){
		int v = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		for(int k = 0; k <= n-1; k++){
			cout << a[k];
			if(k < n-1){
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

void riftshuffle(int n,int dt[]){//??????????????£?????????
	int alt[2*n+1];
	rep(i,2*n+1){
		if(n!=0){
			if(i%2){//?\???°????????????
				alt[i]=dt[i/2+1];
			}else{//??¶??°????????????
				alt[i]=dt[i/2+n];
			}
		}
	}
	rep(i,2*n+1){
		if(i!=0){
			dt[i]=alt[i];
		}
	}
}

void cutshuffle(int k,int n,int dt[]){//?????????
	queue<int> que;
	loop(i,k+1,2*n+1)que.push(dt[i]);
	loop(i,1,k+1)que.push(dt[i]);
	for(int i=1;!que.empty();i++){
		dt[i]=que.front();
		que.pop();
	}
}

int main(){
	int n,m,k;
	cin>>n>>m;
	int data[2*n+1];
	rep(i,2*n+1){
		if(i!=0)data[i]=i;
	}
	data[0]=-1;
	rep(i,m){
		cin>>k;
		if(k==0)riftshuffle(n,data);
		else cutshuffle(k,n,data);
	}
	rep(i,2*n+1){
		if(i!=0)cout<<data[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
function Main(input) {
  input = input.split(" ");
  
  const N = parseInt(input[0], 10);
  const X = parseInt(input[1], 10);
  const T = parseInt(input[2], 10);
  
  var laps = N % X ? Math.floor(N / X) + 1 : Math.floor(N / X);
  var time = laps * T;
  
  console.log("%d", time);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

#define MX 1000005
#define F first
#define S second
#define br '\n'

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

vector<ll> prime;
vector<bool> mark(MX);

void sieve()
{
    prime.push_back(2);
    int lim = sqrt(MX+.1);
    for(int i=3; i<MX; i+=2)
    {
        if(!mark[i])
        {
            prime.push_back(i);
            if(i <= lim)
            {
                for(int j=i*i; j<MX; j+=2*i)
                    mark[j] = true;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    // freopen("input.txt", "r", stdin);

    sieve();

    ll N;
    while(cin >> N)
    {
        int moves = 0;
        for(int i=0; i<prime.size() && prime[i]<=N; i++)
        {
            int cnt = 0;
            while(N % prime[i] == 0)
            {
                cnt++;
                N /= prime[i];
            }
            for(int i=1; i<=cnt; i++)
            {
                cnt -= i;
                moves++;
            }
        }
        if(N > 1)
            moves++;
        cout << moves << br;
    }

    return 0;
}


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

#define FOR(i,a) for(int i=0;i<a;i++)

int main(){
	int a[16];
	int shogen[16][16];
	FOR(i,16){FOR(j,16){shogen[i][j]=-1;}}
	int ans=0;
	int n;cin>>n;
	FOR(i,n){
		cin>>a[i];
		FOR(j,a[i]){
			int x;cin>>x;
			cin>>shogen[i][x-1];
		}
	}
	int maxx=1<<n;
	FOR(now,maxx){
		int tf[16];
		bool OK=true;
		FOR(j,16){
				if(now&(1<<j)){
					tf[j]=1;
				}
				else{tf[j]=0;}
		}
		FOR(j,n){
			if(now & (1<<j)){
				FOR(t,n){
					if(shogen[j][t]!=-1){
						if(tf[t]!=shogen[j][t]){
							OK=false;
						}
					}
				}
			}
		}
		if(OK==true){
			//cout<<"OK"<<bitset<16>(now)<<endl;
			int temp=0;
			FOR(j,n){
				if(now&(1<<j)){
					temp++;
				}
			}
			ans=max(ans,temp);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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


int main(){
    int n; cin >> n;
    int a;
    map<int,int> m;
    rep(i,n){
        cin >> a;
        m[a] = i;
    }
    rep(i,n){
        cout << m[i+1]+1 << " ";
    }
}

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

int G[100][100];
int x[100];

int main(){
  int n,i;
  int a,k;
  int j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&k);
    for(j=0;j<k;j++){
      scanf("%d",&x[j]);
      G[a-1][x[j]-1]=1;
    }
  }
 
  
  for(i=0;i<n;i++){  
    for(j=0;j<n;j++){
      
      printf("%d",G[i][j]);
      if(j!=n-1)printf(" ");
      else printf("\n");
    }
  }
  return 0;}


      



Measured memory_bytes: 2088
using System;
using System.Collections.Generic;
using System.Linq;
public class Pg
{
    static void Main()
    {
        var ck = new Checker();
        var rd = new Reader();
        foreach (var v in rd.Read().ToList())
        {
            Console.WriteLine(ck.GetParenth(v) ? "yes" : "no");
        }
    }
}
class Checker
{
    internal bool GetParenth(string s)
    {
        var par = new Stack<char>();
        for (int i = 0; i < s.Length; ++i)
        {
            if (s[i] == '(' || s[i] == '[')
            {
                par.Push(s[i]);
            }
            else if (s[i] == ')' || s[i] == ']')
            {
                try
                {
                    var c = par.Pop();
                    if ((c != '(' && s[i] == ')') || (c != '[' && s[i] == ']'))
                        return false;
                }
                catch
                {
                    return false;
                }
            }
        }
        return par.Count == 0;
    }
}
class Reader
{
    internal IEnumerable<string> Read()
    {
        string n;
        while ((n = Console.ReadLine()) != ".")
        {
            yield return n;
        }
    }
    internal IEnumerable<int> ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse);
    }
}



Measured memory_bytes: 16612
def check():
    S = [s for s in input()]
    T = [t for t in input()]
    S.sort()
    S = ''.join(S)
    T.sort(reverse=True)
    T = ''.join(T)
    if S<T:
        return True
    return False
if check():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n=int(input())
a=[int(i) for i in input().split()]

import collections
 
c=collections.Counter(a)
l=c.most_common()

from operator import itemgetter

l.sort(key=itemgetter(0))   
    

ans=0
for i in range(len(l)-2):
    if int(l[i][0])+1==int(l[i+1][0]) and int(l[i+1][0])+1==int(l[i+2][0]):
        ans=max(ans,l[i][1]+l[i+1][1]+l[i+2][1])
    elif int(l[i][0]+1)==int(l[i+1][0]):
        ans=max(ans,l[i][1]+l[i+1][1])
    else:
        ans=max(ans,l[i][1])

if len(l)==1:
    ans=l[0][1]

if len(l)==2:
    if int(l[1][0])-int(l[0][0])<=2:
        ans=l[0][1]+l[1][1]
    else:
        ans=max(ans,l[0][1],l[1][1])
        
print(ans)






Measured memory_bytes: 15968
#include<iostream>
using namespace std;
int main(){

	int a,b,c;
	int i=0;
	
	cin>>a>>b>>c;
	
	for(int x=a;b>=x;x++){
		if(c%x==0){
			i++;
		}
	}
	cout<<i<<endl;
		
	return 0;
}

Measured memory_bytes: 1160
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let N = S.len();
    let ans = if (0..(N + 1)).any(|i|
        (i..(N + 1)).any(|j| format!("{}{}",
            S[..i].iter().map(|&c| c).collect::<String>(),
            S[j..].iter().map(|&c| c).collect::<String>(),
        ) == "keyence"
    )) { "YES" } else { "NO" };

    println!("{}", ans);
}

Measured memory_bytes: 4352
def resolve():
    n = int(input())
    res = [0]*n
    for i in range(n):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            res[i] = 1
    OK = False
    for i in range(2, n):
        if res[i]== 1 and res[i-1] == 1 and res[i-2] == 1:
            OK = True
    if OK:
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 62520
program prob5
    implicit none
    integer(8)::K,T,i,j,s,ans
    integer,allocatable::a(:)
    read(*,*) K,T
    allocate(a(T))
    read(*,*) a
    s = sum(a)
    ans = 0
    do i = 1, T
        if(a(i) >= (s+1)/2) then
            ans = a(i) - (s-a(i)) -1
        end if
    end do

    write(*,*) ans
 
    stop
end program

Measured memory_bytes: 2760