akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    list<int> L[100010];
    list<int>::iterator it;
    int n,q; cin >> n >> q;
    for(int i = 0; i < q; i++){
        int a; cin >> a;
        if (a == 0){
            int b,c; cin >> b >> c;
            L[b].push_back(c);
        } else if (a == 1){
            int b; cin >> b;
            for(it = L[b].begin(); it != L[b].end(); it++){
                if (it != L[b].begin()) cout << ' ';
                cout << *it;
            }
            cout << endl;
        } else {
            int b,c; cin >> b >> c;
            L[c].splice(L[c].end(),L[b]);
        }
    }
}


Measured memory_bytes: 20224
// finish date: 2018/01/14
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 1000000000

vector<vector<int>> b, c, field;


int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int factorial(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = ans * i;
    }
    return ans;
}


int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if(abs(A-B-1)&1) cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;

    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
    for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
    int64 N;
    cin >> N;
    if (N%2 == 0) {
        cout << 0.5 << endl;
    } else {
        cout << fixed << setprecision(10) << (double)((N+1)/2)/(double)N << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>

#define N_size 100000000000

using namespace std;

int main(){
    int N,maxa1=-1,maxa2 = -1,max1count=0;
    cin >> N;
    vector<int> a(N),copya(N);

    for(int i = 0;i < N;i++){
        cin >> a.at(i);
        copya.at(i) = a.at(i);
    }

    sort(copya.begin(),copya.end());
    reverse(copya.begin(),copya.end());

    for(int i = 0;i < N;i++){
        if(copya.at(i) > maxa1){
            maxa1 = copya.at(i);
            max1count++;
        }else if(copya.at(i) == maxa1){
            max1count++;
        }else if(copya.at(i) < maxa1 && copya.at(i) > maxa2){
            maxa2 = copya.at(i);
            break;
        }
        if(max1count >= 2){
            break;
        }
    }

    for(int i = 0;i < N;i++){
        if(max1count >= 2){
            cout << maxa1 << endl;;
        }else{
            if(maxa1 == a.at(i)){
                cout << maxa2 << endl;;
            }else{
                cout << maxa1 << endl;;
            }
        }
    }

}

Measured memory_bytes: 3200
var
 s,a,b,c,d:longint;
begin
 readln(s);
 d:=s mod 10;
 c:=s div 10 mod 10;
 b:=s div 100 mod 10;
 a:=s div 1000;
 if a+b+c-d=7 then writeln(a,'+',b,'+',c,'-',d,'=7') else
 if a+b-c-d=7 then writeln(a,'+',b,'-',c,'-',d,'=7') else
 if a-b-c-d=7 then writeln(a,'-',b,'-',c,'-',d,'=7') else
 if a+b+c+d=7 then writeln(a,'+',b,'+',c,'+',d,'=7') else
 if a+b-c+d=7 then writeln(a,'+',b,'-',c,'+',d,'=7') else
 if a-b-c+d=7 then writeln(a,'-',b,'-',c,'+',d,'=7') else
 if a-b+c-d=7 then writeln(a,'-',b,'+',c,'-',d,'=7') else
 if a-b+c+d=7 then writeln(a,'-',b,'+',c,'+',d,'=7');
end.

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from random import *
from functools import reduce,partial
from time import time
from pprint import pprint

def readln():
    return list(map(int,input().split(' ')))

def identity(x):
    """Return the input itself."""
    return x

def constant(c):
    """Return an function which always
    returns the input constant c."""
    def const_function(const,*args):
        return const
    return partial(const_function,c)

def inc(c = 1):
    """Return a function which reads an input x and returns x + c as output.
    By default, c equals 1."""
    return lambda x: x + c

def add(*args):
    """Return the sum of the input."""
    def add2(x,y): return x + y
    return reduce(add2,args)

def mapv(f,*lst):
    """Return a vector of the result of map."""
    return list(map(f,*lst))

def vector(*args):
    """Return a vector of input parameters."""
    return args

def sequence(n,f = constant(0)):
    """Return a vector of length n, and initialize the i'th
    item with f(i).By default the vector will initialized with 0."""
    return [f(i) for i in range(0,n)]

def matrix(n,m,f = constant(0)):
    """Return a 2-dim vector which contains n vectors with length m.
    The j's item of vector i will be initialized by f(i,j).By default,
    the vector will be initialized with 0."""
    return [[f(i,j) for j in range(0,m)] for i in range(0,n)]

def flat(v):
    """Return a flat vector which contains the elements of v in their
    origin order.If the input is not a vector, return a vector which
    only contains the input."""
    if not isinstance(v,list): return [v]
    if not v: return []
    return reduce(add,mapv(flat,v))

def partition(v,f = identity):
    """Partition vector v by f(v[i]).
    e.g. partition([1,2,3,1,2,3],identity()) == {1:[1,1,1], 2:[2,2], 3:[3]}
    By default, the vector will be partitioned by identity function."""
    result = {}
    for item in v:
        key = f(item)
        s = result.get(key)
        if s:
            s.append(item)
        else:
            result.update({key:[item]})
    return result

def getValue(key):
    """Return a function which returns the value of key in a hash-map.
    If the key do not exist, it will throw an error."""
    return lambda x: x[key]

def mapValue(f,m):
    """Replace each value in hash-map m with f(value).
    Return the new hash-map."""
    res = {}
    for key in m:
        res.update({key: f(m[key])})
    return res

p = 1000000000 + 7

n,m = readln()
c = sequence(n)
for i in range(0,m):
    a,b = readln()
    c[a-1] += 1
    c[b-1] += 1
ans = 'YES'
for count in c:
    if count % 2 == 1:
        ans = 'NO'
print(ans)


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

int main() {
    int  H,W,M; cin>>H>>W>>M;
    vector<vector<int>> h_tot(H);
    vector<pair<int,int>> w_tot(W);
    for (int i = 0; i < W; i++){
        w_tot[i].second=i;
    }
    for (int i = 0; i < M; i++){
        int h,w; cin>>h>>w;
        h--;w--;
        h_tot[h].push_back(w);
        w_tot[w].first++;
    }
    sort(h_tot.begin(),h_tot.end(),[](auto const& l,auto const& r){
        return l.size()>r.size();
    });
    int h_max=h_tot[0].size();
    int i=0;
    vector<int> w_pos;
    for (int i = 0; i < W; i++){
        w_pos.push_back(i);
    }
    while(i<H&&h_tot[i].size()==h_max){
        vector<int> tmp;
        sort(h_tot[i].begin(),h_tot[i].end());
        set_intersection(w_pos.begin(),w_pos.end(),h_tot[i].begin(),h_tot[i].end(),inserter(tmp,end(tmp)));
        w_pos=tmp;
        i++;
    }
    sort(w_tot.begin(),w_tot.end(),greater<pair<int,int>>());
    int w_max=w_tot[0].first;
    i=0;
    bool minus=true;
    while(i<W&&w_tot[i].first==w_max){
        if(!binary_search(w_pos.begin(),w_pos.end(),w_tot[i].second)){
            minus=false;
            break;
        }
        i++;
    }
    cout<<h_max+w_max-1*minus<<endl;
}

Measured memory_bytes: 24100
while line = gets
    arr = line.chomp.split.map(&:to_i)
    arr2 = [4,1,4,1,2,1,2,1]
    result = {}
    8.times{|i|
        arr2.rotate!(1)
        rest = 0
        0.upto(7){|i| rest += arr[i] - arr2[i] if arr[i] > arr2[i]}
        result[rest] = arr2.join.to_i if result[rest].nil? || result[rest] > arr2.join.to_i
    }
    puts (result.sort.first)[1].to_s.split("").join(" ")
end



Measured memory_bytes: 6944
# Author: cr4zjh0bp
# Created: Thu Mar 12 20:28:52 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

def f(x):
    s = str(x)
    n = 0
    for i in range(len(s)):
        n += int(s[i])
    return n

x = ni()

print("Yes" if x % f(x) == 0 else "No")

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {st s;
    ci(s);
  ll ans=0;
  ll S=s.sz;
  if(s[0]!='A'){
    co("WA")
  }
  else{
    ll count=0;
    ll posi=0;
    FOR(i,2,S-1){
      if(s[i]=='C'){
        count++;
        posi=i;
      }
    }
    if(count!=1){
      co("WA")
    }
    else{
      FOR(i,1,S){
        if(i==posi){
          continue;
        }
        else if(s[i]<'a'){
          co("WA")
            break;
        }
        else{
          ans++;
        }
      }
          
    }
  
}
  
          if(ans==(S-2)){
            co("AC")
          }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s,0, sizeof(s))
const int mod=100000007;
const int maxn=1000000;
const int inf = 0x3f3f3f3f;
int main()
{
    ll n;
    scanf("%lld",&n);
    printf("%lld",n*(n-1)/2);
    return 0;
}

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

const long double pi=3.14159265359;

int main()
{
 int t=1;
 //cin>>t;
 while(t--)
 {int n,m,x;
  cin>>n>>m;
  vector<int> v(m);
  long long s=0;
  for(int i=0;i<m;i++){
      cin>>x;
      s+=x;
  }
  if(s>n)
  cout<<-1;
  else
  cout<<n-s;
//   printf()
 }
 return 0;
}


Measured memory_bytes: 3664
#include <iostream>



using namespace std;


int main()
{
        
   int n,m;
   cin>>n>>m;
   int ans=0;
   int y=-1;
   int o=0;
   for(int i=0;i<m;i++)
   {
        int a;
        cin>>a;
        ans+=a;
   }
   if(ans<n){
        cout<<n-ans;

   }
   else if(ans==n)
   {
           cout<<o;
   }
   else{
        cout<<y;
   }

    return 0;
}


Measured memory_bytes: 3184
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

K = int(input())
A, B = map(int, input().split())

for i in range(A, B + 1):
    if i % K == 0:
        print("OK")
        exit()
        
print("NG")

Measured memory_bytes: 65188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>

using namespace std;

int GCD(int A,int B){
  while(A != B){
    if(A < B){
      B -= A;
    }else{
      A -= B;
    }
  }
  return A;
}

int main(){
  long long int A,B;
  long long int C,D;

  cin >> A >> B >> C >> D;

  A -= 1;

  long long int lcm = 1,gcd = 1,ans;

  gcd = GCD(C,D);

  lcm = C*D/gcd;

  ans = B - B/C - B/D + B/lcm - (A - A/C - A/D + A/lcm);

  cout << ans << endl;

  return 0;
}

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

/*
  バケット法を使った解法
  バケット法はあらかじめ取りうる値に対応するバケットを用意して
  データをバケットに格納する。
  この性質上、あらかじめ取りうる値がわかっている状態じゃないといけない
　集計処理に使用可能
*/

int main(){

    int N;
    cin >> N;
    int data[110];

    for(int i=0;i<N;i++) cin >> data[i];
    int bucket[110]={0};

    for(int i=0;i<N;i++){
        bucket[data[i]]++; 
        //data[i]の値に応じてあらかじめ設けられたbucketを探し
        //1ずつカウントしていく。
        //これにより、想定していた数値が何回出てきたか集計できる。
    }

    int ans=0;
    for(int i=1;i<=100;i++){
        //もしbucketの中身が1より大きい場合、
        //あらかじめつくったバケットには値が入っていることになる
        //これをカウントすれば答えが求まる
        if(bucket[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int maxi[1<<26],mask,dp[200000+1];
int main(){
	fastio;
	string s;
	cin>>s;
	memset(maxi,63,sizeof(maxi));
	maxi[0]=0;
	int len=s.length();
	rep(i,len){
		mask^=1<<(s[i]-'a');
		dp[i]=maxi[mask]+1;
		rep(j,26){
			dp[i]=min(dp[i],maxi[mask^(1<<j)]+1);
		}
		maxi[mask]=min(maxi[mask],dp[i]);
	}
	cout<<dp[len-1]<<endl;
	return 0;
}


Measured memory_bytes: 263504
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  for (int i = 0; i < M; i++) {
    cin >> p.at(i) >> S.at(i);
  }
  int correct = 0;
  int penalty = 0;
  vector<int> a(N + 1);
  vector<int> b(N + 1);
  for (int i = 0; i < M; i++) {
    if (a.at(p.at(i)) == 0) {
      if (S.at(i) == "AC") {
        a.at(p.at(i)) = 1;
        correct++;
      }
      else {
        b.at(p.at(i))++;
      }
    }
  }
  for (int i = 1; i < N + 1; i++) {
    if (a.at(i) == 1) {
      penalty += b.at(i);
    }
  }
  cout << correct << " " << penalty << endl;
}

Measured memory_bytes: 6912
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		for(int i = 0;i<=s[0];i++) {
			for(int j = 0;j<=s[1];j++) {
				if(i*s[1]+j*s[0]-i*j*2==s[2]){
					Console.WriteLine("Yes");
					return;
				}
			}
		}
		Console.WriteLine("No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27500
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long H, W, K, dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };
	string S[800] = {};
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) cin >> S[i];
	queue<pair<pair<long long, long long>, long long> > Q;
	long long SX, SY;
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (S[i][j] == 'S') SX = i, SY = j;
	Q.push({ { SX,SY }, K });
	while (!Q.empty()) {
		pair<pair<long long, long long>, long long> PP = Q.front();
		Q.pop();
		pair<long long, long long> P = PP.first;
		long long X = PP.second;
		if (S[P.first][P.second] == 'X') continue;
		S[P.first][P.second] = 'X';
		if (P.first == 0 || P.first == H - 1 || P.second == 0 || P.second == W - 1) {
			cout << 1 << endl;
			return 0;
		}
		if (X == 0) continue;
		for (int i = 0; i < 4; i++) {
			long long NX = P.first + dx[i], NY = P.second + dy[i];
			if (NX < 0 || H <= NX || NY < 0 || W <= NY) {

			}
			if (S[NX][NY] == '.') Q.push({ { NX, NY }, X - 1 });
		}
	}
	long long Dist = 1000;
	for (long long i = 0; i < H; i++) {
		for (long long j = 0; j < W; j++) {
			if (S[i][j] == 'X') {
				Dist = min({ Dist, i, H - i - 1, j, W - j - 1 });
			}
		}
	}
	cout << (Dist + K - 1) / K + 1 << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

int main()
{
    int n;
    int a[15];
    int x[15][14];
    int y[15][14];
    int state[15] = { 2 }; // 2:no touch, 0:unkind, 1:honest
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        rep(j, a[i]) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    int ans = 0;
    // 正直者、不親切な人を全パターン探索
    for (int bit = 0; bit < (1 << n); bit++) {
        // 状態をクリア
        rep(i, n) state[i] = 2;
        // 矛盾していないことを表すフラグ
        bool is_match = true;
        // 正直者の人数をカウント
        int count = 0;
        // 1人ずつ確認
        for (int i = 0; i < n; i++) {
            // 人iが正直者の場合
            if (bit & (1 << i)) {
                // iの証言を全て調べる
                for (int j = 0; j < a[i]; j++) {
                    // これまで調べた証言と矛盾していた場合、フラグを落とす
                    if ((y[i][j] == 1 && state[x[i][j]] == 0) || (y[i][j] == 0 && state[x[i][j]] == 1) ||
                        (y[i][j] == 0 && (bit & (1 << x[i][j]))) || (y[i][j] == 1 && !(bit & (1<<x[i][j])))) {
                        is_match = false;
                    }
                    // 矛盾していない場合、証言の情報をstateに格納
                    else {
                        state[x[i][j]] = y[i][j];
                    }
                }
                count++;
            }
        }
        // 全ての証言が矛盾していなかったらカウントをansに格納
        if (is_match) ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(void){
	int a, b;
	char op;
	
	while(1){
		scanf("%d %c %d", &a, & op, &b);
		if (op == '+' ) printf("%d\n", a + b);
		else if (op == '-' ) printf("%d\n", a - b);
		else if (op == '*' ) printf("%d\n", a * b);
		else if (op == '/' && b != 0) printf("%d\n", a / b);
		else if (op == '/' && b == 0) printf("Error: Zero devision is not defined.\n");
		else if (op == '?') break;
		else continue;
	}
		
	return 0;
}

Measured memory_bytes: 1028
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
	double r;
	scanf("%lf", &r);
	printf("%.6lf %.6lf", r * r * M_PI, 2 * r * M_PI);
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int a, b;
    cin >> a >> b;

    cout << (6 - a - b);

    return 0;
}


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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

int main() {
	int a = read(), b = read(), c = read();
	int ans = 1e9;
	ans = min(ans, a + b);
	ans = min(b + c, ans);
	ans = min(ans, c + a);
	cout << ans << '\n';
	return 0;
}

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

public class Main {
	public static void main(String[] args) throws Exception {
	
		try{
			
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String buf = br.readLine();
	
    int m, f, r;
    
    StringTokenizer st = new StringTokenizer(buf, " ");
    m = Integer.parseInt(st.nextToken());
    f = Integer.parseInt(st.nextToken());
    r = Integer.parseInt(st.nextToken());

    while(true) {
        if (m == -1 && f == -1 && r==-1) break;
        else if (m == -1 || f == -1) {
            System.out.println("F");
        }
        else if (m + f >= 80) {
            System.out.println("A");
        }
        else if (m + f < 80 && m + f >= 65) {
            System.out.println("B");
        }
        else if (m + f < 65 && m + f >= 50) {
            System.out.println("C");
        }
        else if (m + f < 50 && m + f >= 30) {
            if (r >= 50) System.out.println("C");
            else System.out.println("D");
        }
        else System.out.println("F");
         
        buf = br.readLine();
        st = new StringTokenizer(buf," ");
        m = Integer.parseInt(st.nextToken());
        f = Integer.parseInt(st.nextToken());
        r = Integer.parseInt(st.nextToken());
    }
    
} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    }

Measured memory_bytes: 24304
N,A,B,C=map(int,input().split())
l=[int(input()) for _ in range(N)]
inf=10**18
def dfs(cur,a,b,c):
  if cur==N:
    if min(a,b,c)>0:
      return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
      return inf
  res0 = dfs(cur+1,a,b,c)
  res1 = dfs(cur+1,a+l[cur],b,c)+10
  res2 = dfs(cur+1,a,b+l[cur],c)+10
  res3 = dfs(cur+1,a,b,c+l[cur])+10
  return min(res0,res1,res2,res3)
print(dfs(0,0,0,0))

Measured memory_bytes: 9232
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
char s[5010];
ll n,m,i,j,f[5010][5010];
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
int main(){
	scanf("%lld",&n);
	scanf("%s",s+1);
	m=strlen(s+1);
	f[0][0]=1;
	for(i=0;i<n;i++)
	 for(j=0;j<=i;j++){
	 	f[i+1][j+1]=(f[i+1][j+1]+f[i][j]*2%p)%p;
	 	if(j)f[i+1][j-1]=(f[i+1][j-1]+f[i][j])%p;
	 	 else f[i+1][0]=(f[i+1][0]+f[i][0])%p;
	 }
	//for(i=1;i<=n;i++)
	// for(j=0;j<=i;j++)printf("%d %d %d\n",i,j,f[i][j]);
	printf("%lld",(ll)f[n][m]*ksm(ksm(2,m),p-2)%p);
}
/*
0和1是等价的。。
然后直接f[i][j]表示i次按了j个即可。。
最后把答案除以2^n...... 
*/

Measured memory_bytes: 194176
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int64_t> lucas(87);
  lucas.at(0) = 2;
  lucas.at(1) = 1;
  for (int i = 2; i < 87; i++) {
    lucas.at(i) = lucas.at(i - 1) + lucas.at(i - 2);
  }
  int N;
  cin >> N;
  cout << lucas.at(N) << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

i64 N;

void rec(string s, char nxt) {
    if (s.length() == N) {
        cout << s << endl;
        return;
    }

    string a;
    for (char c = 'a'; c <= nxt; c++) {
        a = s + c;
        if (c == nxt) {
            rec(a, nxt + 1);
        } else {
            rec(a, nxt);
        }
    }
}

int main() {
    cin >> N;

    rec("", 'a');

    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
int n,dp[N];
vector<int> v[N];
inline bool cmp(int a,int b){
	return dp[a]<dp[b];
}
void dfs(int p){
	for(unsigned i=0;i<v[p].size();i++)dfs(v[p][i]);
	sort(v[p].begin(),v[p].end(),cmp);
	for(unsigned i=0;i<v[p].size();i++)dp[p]=max(dp[p],(int)(v[p].size()-i)+dp[v[p][i]]);
}
int main(){
	n=read();
	for(int i=2;i<=n;i++)v[read()].push_back(i);
	dfs(1);
	cout<<dp[1]<<endl;
}

Measured memory_bytes: 10752
#include<stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        int x=i;
        if(x%3==0){
            printf(" %d",i);
        }
        else{
            do{
                if(x%10==3){
                    printf(" %d",i);
                    x=0;
                }
                x/=10;
            }while(x);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2100
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	long n;
	cin >> n;
	long ans = 0;
	for (long i = 1; i * i + i <= n; i++)
	{
		long m = (n-i)/i;
		if (i < m && i*m+i == n)
		{
			ans += m;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
import io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val t = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toLong))
    .toArray

  val dp = Array.ofDim[Long](n)
  dp(0) = 1
  (1 until n)
    .foreach(i => {
      val roundUpA = t(i)(0) - 1
      val roundUpB = t(i)(1) - 1
      val a = (dp(i-1) * t(i-1)(0) + roundUpA) / t(i)(0)
      val b = (dp(i-1) * t(i-1)(1) + roundUpB) / t(i)(1)
      dp(i) = math.max(a, b)
    })

  val ans = t(n-1).sum * dp(n-1)
  println(ans)
}

Measured memory_bytes: 25936
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  ll s;
  const ll c = 1000000000;
  cin >> s;
  ll x = (c - (c + s) % c) % c;
  ll y = (s + x) / c;
  cout << "0 0 1000000000 1 " << x << " " << y << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int a[101][101];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int b[101];
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    int c[101];
    for (int i = 0; i < n; i++) {
        int e = 0;
        for (int j = 0; j < m; j++) {
            e += a[i][j] * b[j];
        }
        c[i] = e;
    }
    for (int i = 0; i < n; i++) {
        cout << c[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
// Problem : D - .. (Double Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    //int T; cin >> T;
    //while(T--) 
 	//{
  //    
  //  }
	int N,M;
	cin>>N>>M;
	vi adj[N+1];
	vi vis(N+1);
	queue<int> m;
	F0R(x,M)
	{
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	m.push(1);
	vi ans(N+1);
	while(sz(m)!=0)
	{
		int node=m.front();
		m.pop();
		F0R(x,sz(adj[node]))
		{
			int val=adj[node][x];
			if(!vis[val])
			{
				ans[val]=node;
				vis[val]=1;
				m.push(val);
			}
		}
	}
	FOR(x,1,N+1)
	{
		if(!vis[N])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	FOR(x,2,sz(ans))
	{
		cout<<ans[x]<<endl;
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
 



Measured memory_bytes: 10572
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 100000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int main()
{
    int N; scanf("%d",&N);
    ll s=1000,n=0,v=200;
    rep(i,1,N)
    {
        int x; scanf("%d",&x);
        if(v<x)//可以买入
        {
            v=x;//更新股票价值
        }
        else if(v>x)//股票要跌了，要在上一天卖掉
        {
            s+=n*v;//此时以v的价格卖出n个，相当于上一天卖完
            n=s/x;//以x的价格买入n个
            v=x;//更新价值
            s%=x;//剩下的钱
        }
    }
    printf("%lld\n",s+n*v);
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int N;
  cin >> N;
  vint x(N),y(N),h(N);
  rep(i,N) cin >> x[i] >> y[i] >> h[i];
  int MAX = 100;
  erep(posX,MAX){
    erep(posY,MAX){
      int needH = -1;
      rep(i,N){
        if(h[i] > 0){
          int tmp = h[i] + abs(posX - x[i]) + abs(posY - y[i]);
          if(needH == -1){
            needH = tmp;
          }
          else if(needH != tmp){
            needH = -2;
            break;
          }
        }
      }
      if(needH == -2) continue;

      rep(i,N){
        if(h[i] == 0){
          int dist = abs(posX - x[i]) + abs(posY - y[i]);
          if(needH > dist){
            needH = -2;
          }
        }
      }
      if(needH == -2) continue;

      cout << posX <<' ' <<  posY << ' ' << needH << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
N=int(input())
l=[]
for i in range(N):
    l.append(input())
if len(list(set(l)))!=len(l):
    print("No")
else:
    end=l[0][len(l[0])-1]
    del l[0]
    c=True
    for j in l:
        if j[0]!=end:
            c=False
            break;
        end=j[len(j)-1]
    if c:
        print("Yes")
    else:
        print("No")


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

int main() {
  ll n;
  cin >> n;
  ll ans=n-1;
  rep(i,1000001){
    if(i!=0)if(n%i==0){
      ans=min(ans,i+n/i-2);
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 3628
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  string s;
  map<string, int> m;
  cin >> s;
  m.insert({"SUN", 7});
  m.insert({"MON", 6});
  m.insert({"TUE", 5});
  m.insert({"WED", 4});
  m.insert({"THU", 3});
  m.insert({"FRI", 2});
  m.insert({"SAT", 1});
  cout << m[s] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 200010, mod = 1e9 + 7;
int two[MX], inv[MX];
int n;
vector<vi> e;
ll ans;
int rec(int c, int p){
	vi cs;
	int sum = 1;
	for(int i : e[c]) if(i != p){
		int x = rec(i, c);
		sum += x;
		cs.pb(x);
	}
	if(c != p) cs.pb(n - sum);
	if(cs.size() < 2) return sum;
	
	ll tmp = 1, t = 1, u = 1;
	for(int i : cs) t = t * inv[i] % mod;
	tmp += mod - t;
	
	for(int i : cs) tmp += mod - t * two[i] % mod * (1 + mod - inv[i]) % mod;
	ans += tmp % mod;
	
	return sum;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n;
	e.resize(n);
	
	two[0] = inv[0] = 1;
	rep(i, n){
		two[i + 1] = two[i] * 2ll % mod;
		inv[i + 1] = inv[i] * (mod - mod / 2ll) % mod;
	}
	
	rep(i, n - 1){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	rec(0, 0);
	cout << ans % mod * inv[1] % mod << endl;
	return 0;
}

Measured memory_bytes: 26368
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	int ans1, ans2;
	int n, m, na, nb, nc, tyo, place[16], ans;
	int cup[3][16];
	while (1) {
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 16; ++j)
				cup[i][j] = 0;
		}
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		cin >> na;
		for (int i = 0; i < na; ++i) cin >> cup[0][i];
		cin >> nb;
		for (int i = 0; i < nb; ++i)cin >> cup[1][i];
		cin >> nc;
		for (int i = 0; i < nc; ++i)cin >> cup[2][i];
		for (int p = 0; p < 2; ++p) {
			tyo = 0;
			if (p == 0)place[0] = 0;
			else place[0] = 2;
			int np;
			if (place[0] == 0)np = 2;
			else np = 0;
			for (int k = 1; k < 16; ++k) place[k] = place[0];
			bool bo = false; int at, ar;
			for (int i = 1; i <= n; ++i) {
				for (int j = 0; j < na; ++j) {
					if (cup[0][j] == i) {
						at = 0;
						ar = j;
						bo = true;
						break;
					}
				}
				for (int j = 0; j < nb; ++j) {
					if (bo)break;
					if (cup[1][j] == i) {
						at = 1;
						ar = j;
						bo = true;
						break;
					}
				}
				for (int j = 0; j < nc; ++j) {
					if (bo)break;
					if (cup[2][j] == i) {
						at = 2;
						ar = j;
						bo = true;
						break;
					}
				}
				bo = false;
				if (at == place[i]) {
				}
				else {
					if (at == 1) {
						tyo += pow(3, n - i);
						for (int k = i + 1; k < 16; ++k) {
							if (place[k] == 0)place[k] = 2;
							else place[k] = 0;
						}
					}
					else tyo += 2 * (pow(3, n - i));
				}
			}
			if (p == 0)ans1 = tyo;
			else ans2 = tyo;
		}
		if (m < min(ans1, ans2))cout << -1 << endl;
		else cout << min(ans1, ans2) << endl;
	}
	return 0;
}


Measured memory_bytes: 3152
import java.util.*;

public class Main {
	String S;
	int result = 0;

	Main() {
		Scanner in = new Scanner(System.in);
		S = in.nextLine();
		in.close();
	}

	void calc() {
		int zeroNum = 0, oneNum = 0;
		for (int i = 0; i < S.length(); ++i) {
			if (S.charAt(i) == '0') {
				++zeroNum;
			} else {
				++oneNum;
			}
		}
		result = Math.min(zeroNum, oneNum) * 2;
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calc();
		System.out.println(ins.result);
	}

}


Measured memory_bytes: 27328
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map.remove(l(1)).get
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Int](721)
    log.par.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = 1)
    })
    time.sum
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


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


bool f(int n) {
    int i;
    for (i = 1; i*i <= n; i++)
        ;
    if ((i-1)*(i-1) == n)
        return true;
    return false;
}


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

    int n;
    cin >> n;
    int i;
    for (i = 1; i*i <= n; i++) {
    }
    cout << (i-1)*(i-1) << endl;


    return 0;
}




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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;

    mat C(2001, vec(2001, 0));
    C[0][0] = 1;
    REP(i,1,2001) {
        C[i][0] = 1;
        REP(j,1,2001) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
        }
    }

    REP(i,1,K+1) PR((C[N-K+1][i]*C[K-1][i-1])%MOD);

    return 0;
}

/*



*/

Measured memory_bytes: 34652
c = int(input())
a = [0]
for i in range(30):
    if i%2 == 0 or i >= 20:
        a.append(a[i]+20)
    else:
        a.append(a[i]+19)
for i in range(c):
    y, m, d = map(int,input().split())
    b = int((y-1)/3) * 590 + a[m + ((y+2)%3) * 10 - 1] + d
    print(196470 - b + 1)



Measured memory_bytes: 5592
K=int(input())
ans=0
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
for a in range(K):
  for b in range(K):
    for c in range(K):
      ans+=gcd(a+1,b+1,c+1)
print(ans)

Measured memory_bytes: 69764
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

vector<int> parent(100005,0);
vector<int> size(100005,0);

void make_set(int a)
{
    parent[a] = a;
    size[a] = 1;
}

int find_set(int a)
{
    if(a == parent[a])
        return a;
    return parent[a] = find_set(parent[a]);
}

void union_set(int a, int b)
{
    a = find_set(a);
    b = find_set(b);
    if(a!=b)
    {
        if(size[a] < size[b])
            swap(a,b);
        parent[b] = a;
        size[a]+=size[b];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    // randers();
    long long int n,m;
    cin>>n>>m;
    int a[m],b[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    long long int curr = n*(n-1);
    curr/=2;
    long long int ans[m];
    ans[m-1]=curr;
    for(int i=0;i<n;i++)
    {
        parent[i] = i;
        size[i] = 1;
    }
    for(int i=m-1;i>=0;i--)
    {
        ans[i] = curr;
        if(find_set(a[i])!=find_set(b[i]))
            curr-=(size[parent[a[i]]]*size[parent[b[i]]]);
        union_set(a[i],b[i]);
    }
    for(int i=0;i<m;i++)
        cout<<ans[i]<<endl;
    return 0;
   
}

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

int main ()
{
    int n, a, b, c, x;
    while (cin >> n >> a >> b >> c >> x, (n || a || b || c || x)) {
        int count = 0;
        for (int i = 0; i < n; i++) {
            int y;
            cin >> y;
            while (count < 10002) {
                if (y == x) {
                    break;
                } else {
                    x = (a * x + b) % c;
                    count++;
                }
            }
            if (i < n - 1) {
                x = (a * x + b) % c;
                count++;
            }
        }
        cout << (count <= 10000 ? count : -1) << endl;
    }

    return 0;
}

Measured memory_bytes: 1160