akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
 
int main(){
	int n;
	cin >> n;
	ll a[n], l[n+1], h[n+1];
	for(int i=0; i<n; i++) cin >> a[i];
	l[n]=2, h[n]=2;

	for(int i=n-1; i>=0; i--){
		l[i]=l[i+1];
		if(l[i+1]%a[i]!=0) l[i]+=a[i]-l[i+1]%a[i];
		h[i]=h[i+1]-h[i+1]%a[i]+a[i]-1;
		if(h[i]<l[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << l[0] << " " << h[0] << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    vi arr;
    int v[n + 1];
    fore(i, 0, n){
        cin >> v[i];
        arr.pb(v[i]);
    }
    sort(all(arr));
    int r = n / 2;
    int l = r - 1; 
    fore(i, 0, n){
        if(v[i] < arr[l])
            cout << arr[r];
        else if(v[i] > arr[r])
            cout << arr[l];
        else{
            if(v[i] == arr[l])
                cout << arr[r];
            else
                cout << arr[l];
        }
        cout << '\n';
    }
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

Measured memory_bytes: 3956
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for b in range(n)]
    s=sum(a[0:k])
    t=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        t.append(s)
    print(max(t))


Measured memory_bytes: 11708
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String ans = "";
        for (int i = 0; i < 3; i++) {
        	ans += sc.next().charAt(0);
        }
        
        System.out.println(ans.toUpperCase());
    }
}

Measured memory_bytes: 21844
# ARC091D - Remainder Reminder
def main():
    N, K = tuple(map(int, input().split()))
    if K == 0:
        print(N ** 2)
    else:
        ans = sum(
            N // i * (i - K) + max(0, (N % i) - K + 1) for i in range(K + 1, N + 1)
        )
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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


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

const ll MOD = 1000000007;
const ll INF = 1000000000;

int h[105];
ll ans = 0;


void func(int L, int R){
    if (L >= R) return;
    int mi = INF;
    for (int i = L; i < R; i++) mi = min(mi, h[i]);
    for (int i = L; i < R; i++) h[i] -= mi;
    ans += mi;

    vector<int> v;
    v.push_back(-1);
    for (int i = L; i < R; i++){
        if (h[i] == 0) v.push_back(i);
    }
    v.push_back(R);

    for (int i = 0; i < v.size() - 1; i++) func(v[i] + 1, v[i + 1]);

}
int main(void){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];
    func(0, n);
    cout << ans << endl;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(M)]
ans = min(a) + min(b)
for i in range(M):
    c = a[L[i][0] - 1] + b[L[i][1] - 1] - L[i][2]
    if c < ans:
        ans = c
print(ans)


Measured memory_bytes: 38560
import fractions

n = int(input())
a = list(map(int, input().split()))

ans = 0

l = [0]
r = [0]

for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[n-i-1]))

ans = 0

for i in range(n):
    ans = max(ans, fractions.gcd(l[i],r[n-i-1]))

print(ans)

Measured memory_bytes: 16576
#include<bits/stdc++.h>
using namespace std;
int main(){
  long double a,b;
   cin>>a>>b;
      	 if(a>b){
      	 	cout<<"GREATER";
		   }
		   else if(a<b){
		   	cout<<"LESS";
		   }
		   else
		     cout<<"EQUAL";
	  }

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7

def solve(l):
    tmp = 0
    tmpS = ''
    for i in range(l,L):
        if S[i] == '1':
            return (2*solve(i+1) + pow(3,L-1-i,mod))%mod
    else:
        return 1

S = input()
L = len(S)
print(solve(0)%mod)


Measured memory_bytes: 98220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int l=0;
    ll ans = (ll)n;

    ll bit = 0;
    for(int i = 0; i < n; i++){
        ll t = a[i];
        int j;
        if(ll(bit^t) == ll(bit+t)){
            bit = bit^t;
            ans += (ll)i-(ll)l;
        }else{
            bit = bit^a[l];
            l++;
            i--;
        }
    }
    cout << ans << endl;


    return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <math.h>

using std::vector;

int main(void){
    int n;
    std::cin >> n;

    vector<int> b;
    for (int i = 0; i < n - 1; i++){
        int tmp;
        std::cin >> tmp;
        b.push_back(tmp);
    }

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

    a[0] = b[0];
    a[1] = b[0];
    for (int i = 1; i < b.size(); i++){
        if (b[i] <= a[i]){
            a[i] = b[i];
            a[i+1] = b[i];
        } else {
            a[i+1] = b[i];
        }
    }

    int sum = 0;
    for (int el = 0; el < n; el++){
        sum += a[el];
    }
    std::cout << sum << std::endl;
    delete[](a);
    return 0;
}

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

using namespace std;


long long H, W;
long long ans = 10000000000;

long long max3(long long a, long long b, long long c){
    if(a >= b && a >= c) return a;
    if(b >= a && b >= c) return b;
    else return c;
}
long long min3(long long a, long long b, long long c){
    if(a <= b && a <= c) return a;
    if(b <= a && b <= c) return b;
    else return c;
}

void solve() {
    long long a, b, c;
    for(int i = 0; i < H; i++) {
        a = W * i;
        b = (H - i) * (W / 2);
        c = (H - i) * (W - W / 2);
        ans = min((max3(a,b,c) - min3(a,b,c)), ans);
        b = W * ((H - i) / 2);
        c = W * ((H - i) - (H - i) / 2);
        ans = min((max3(a,b,c) - min3(a,b,c)), ans);
    }
    
    for(int i = 0; i < W; i++) {
        a = H * i;
        b = (W - i) * (H / 2);
        c = (W - i) * (H - H / 2);
        ans = min((max3(a,b,c) - min3(a,b,c)), ans);
        b = H * ((W - i) / 2);
        c = H * ((W - i) - (W - i) / 2);
        ans = min((max3(a,b,c) - min3(a,b,c)), ans);
    }
}

int main() {
    cin >> H >> W;
    solve();
    cout << ans << endl;
}

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

const int N = 6E6 + 5, MOD = 998244353;

int n, m, dp[N];
long long hs[N], ht[N], pw[N];
char s[N], t[N];

long long get_hash(long long hsh[], int l, int r) {
    return ((hsh[r] - hsh[l - 1] * pw[r - l + 1]) % MOD + MOD) % MOD;
}

int solve() {
    pw[0] = 1;
    for (int i = 1; i < N; i++) {
        pw[i] = pw[i - 1] * 31 % MOD;
    }
    int n = strlen(s + 1), m = strlen(t + 1);
    for (int i = 1; i <= n; i++) {
        hs[i] = (hs[i - 1] * 31 + s[i] - 'a' + 1) % MOD;
    }
    for (int i = 1; i <= m; i++) {
        ht[i] = (ht[i - 1] * 31 + t[i] - 'a' + 1) % MOD;
    }
    int ans = 0;
    for (int i = m; i <= n; i++) {
        if (get_hash(ht, 1, m) == get_hash(hs, i - m + 1, i)) {
            dp[i] = dp[i - m] + 1;
        } else {
            dp[i] = 0;
        }
        ans = max(ans, dp[i]);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> (s + 1) >> (t + 1);
    n = strlen(s + 1); m = strlen(t + 1);
    int k = n;
    while (k < m) {
        for (int i = k + 1; i <= k + n; i++) {
            s[i] = s[i - k];
        }
        k += n;
    }
    for (int i = 1; i <= k; i++) {
        s[i + k] = s[i + 2 * k] = s[i];
    }
    int fi = solve();
    for (int i = 1; i <= k; i++) {
        s[i + 3 * k] = s[i];
    }
    int se = solve();
    if (se > fi) {
        cout << -1;
    } else {
        cout << fi;
    }
}


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

public class Main {
	public static void main(String[] args) throws IOException{
		InputReader in = new InputReader(System.in);
		
		while (true) {
			int height = in.readInt();
			int width = in.readInt();
			if (height == 0 && width == 0) break;
			
			StringBuilder sBuffer = new StringBuilder();
			for (int i = 0; i < height; i++) {		
				for (int j = 0; j < width; j++) {
					if ((i + j) % 2 == 0) {
						sBuffer.append("#");
					}else {
						sBuffer.append(".");
					}
				}
				sBuffer.append("\n");
			}
			System.out.println(sBuffer.toString());
		}
	}
}

class InputReader{
	private BufferedReader br;
	private StringTokenizer buffer = null;	
	
	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));				
	}

	public String read() throws IOException {
		while(buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return buffer.nextToken();
	}
	
	public int readInt() throws IOException {
		while(buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return Integer.parseInt(buffer.nextToken());
	}
}


Measured memory_bytes: 25556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge{ll to, cost;};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000

using Graph = vector<vector<edge>>;

int main(){
    ll n;
    cin >> n;
    ll amari = n % 10;
    if(amari == 2 || amari == 4 || amari == 5 || amari == 7 || amari == 9 ){
        cout << "hon" << endl;
    }
    else if(amari == 0 || amari == 1 || amari == 6 || amari == 8){
        cout << "pon" << endl;
    }
    else{
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3620
def main():
    N = int(input())
    # ある数値nについて、n[0]..n[-1]とすると
    # 1~n-1の中のある数値mに対して、n[0]==m[-1]&&n[-1]==m[0]となるようなmがいくつ存在するか調べたい
    # n:1...3 -> m:3...1かつlen(n)>len(m)を満たすもの*2
    # n:3...1 -> m:1...3かつlen(n)>=len(m)を満たすもの*2
    # n:1...1 -> m:1...1かつlen(n)>=len(m)を満たすもの*2
    # 下のパターンで、n[0]==n[-1]のときだけ(n,n)が重複するので-1する
    if N<=9:
        print(N)
    else:
        count = 9
        for n in range(10,N+1):
            n = str(n)
            nlen = len(n)
            if n[-1] == '0':
                continue
            if n[0]<n[-1]:
                tmp = int('1'*(nlen-2)) if nlen>2 else 0
                count += tmp*2
            elif n[0]>n[-1]:
                tmp = int('1'*(nlen-1)) if nlen>2 else 1
                count += tmp*2
            else:
                # 2桁以上(10~)と比較
                tmp = int('1'*(nlen-2))+int(n[1:-1])+1 if nlen>2 else 1
                count += tmp*2-1
                # 1桁(1~9)と比較
                count += 2
        print(count)

main()


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;


int h[100005];
int main(){
	int n, a;
	scanf("%d ", &n);
	FORI(0, n) {
		scanf("%d ", &a);
		h[a]++;
	}
	int ans = -1;
	for(int i=0;i<100000;i++) {
		int x = h[i];
		if (i - 1 >= 0)
			x += h[i - 1];
		if (i + 1 < n)
			x += h[i + 1];
		ans = max(ans, x);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();

        int a[] = new int[m];
        int totalL = 0;
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            if (a[i] < x) totalL++;
        }
        System.out.println(Math.min(totalL, m - totalL));
    }
}


Measured memory_bytes: 24020
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int a,b,t;
    cin >> a >> b >> t;
    int m = t/a;
    cout << b*m;
    return 0;
}



Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
string s;
int main(){
    ____();
    cin >> s;
    if(s=="SUN") cout << 7 << endl;
    else if(s=="MON") cout << 6 << endl;
    else if(s=="SAT") cout << 1 << endl;
    else if(s=="TUE") cout << 5 << endl;
    else if(s=="WED") cout << 4 << endl;
    else if(s=="THU") cout << 3 << endl;
    else if(s=="FRI") cout << 2 << endl;
    return 0;
}

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

int main() {
  int n;
  while (scanf("%d", &n), n) {
    map<char, char> table;
    for (int i = 0; i < n; ++i) {
      char from, to; scanf(" %c %c", &from, &to);
      table[from] = to;
    }
    int m; scanf("%d", &m);
    for (int i = 0; i < m; ++i){
      char ch; scanf(" %c", &ch);
      putchar(table.count(ch) ? table[ch] : ch);
    }
    puts("");
  }
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <stack>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll dp[100005][2];
string t, L = "x";

int main(void) {
  cin >> t;
  int n = sz(t);
  L += t;
  
  dp[0][0] = 1;
  for (int i=1; i<=n; i++) for (int j=0; j<=1; j++) {
    int u = j ? 1 : L[i] - '0';
    for (int k=0; k<=u; k++) {
      dp[i][(j || k<u)] += dp[i-1][j] * (k ? 2 : 1);
      dp[i][j] %= MOD;
      
    }
  
  }
  
  cout << (dp[n][0] + dp[n][1])%MOD  << "\n";

  return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int A, B;
	scanf("%d%d", &A, &B);
	if (A >= 13) {
		printf("%d", B);
	}
	else if (A >= 6 && A <= 12) {
		printf("%d", B / 2);
	}
	else {
		printf("0");
	}
	return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
scale = 21
#scale = 4
seg = [0 for _ in range(2**scale)]
db = [2**i for i in range(scale)]
rdb = list(reversed(db))
#print(rdb)
for _ in range(n):
  c = int(input())
  l = max(c-k,0)
  r = min(c+k+1,2**(scale-1))
  maxi = 0
  now = [[l,r]]
  #print(now)
  for i in range(scale):
    last = now
    now = []
    for xy in last:
      x,y = xy
      if x == y:
        continue
      X = (x-1) // rdb[i] + 1
      Y = y     // rdb[i]
      #print(x,y,X,Y,rdb[i])
      if X < Y:
        for Z in range(X,Y):
          maxi = max(maxi,seg[db[i]+Z])
        now.append([x,X*rdb[i]])
        now.append([Y*rdb[i],y])
      else:
        now.append(xy)
      #print(int(X<Y),X,maxi)
    #print(now,rdb[i],maxi)
  c += db[-1]
  while True:
    seg[c] = max(seg[c],maxi + 1)
    c //= 2
    if not c:
      break
  #print(seg)
print(seg[1])

Measured memory_bytes: 160120
#include <bits/stdc++.h>
using namespace std;
int main() {
  int l,r,d;
  int cnt = 0;
  cin >> l >> r >> d;
  for (int i = l; i <= r;i++){
    if(i%d==0){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int diff = 0;
    for(int i=1; i<=N; i++){
        int a;
        cin >> a;
        if(i != a) diff++;
    }
    cout << (diff <= 2 ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>



int main()
{
	int N;
	scanf("%d",&N);
	if (N % 2 == 0) {
		N = N / 2;
		printf("%d", N);
	}
	else {
		N = N / 2 + 1;
		printf("%d",N);
	}
}

Measured memory_bytes: 128
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,a,b,s=0,i,d[100010];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d",&a);
    hin(a);
  }
  for(i=0;i<m;i++)d[i]=N[hout()];
  R=C=1;
  for(i=1;i<m;i++)hin(d[i-1]-d[i]);
  for(;i<=n;i++)hin(0);
  s=d[0]-d[m-1];
  //printf("%d\n",s);
  while(--n)s-=N[hout()];
  printf("%d\n",s);
  return 0;
}


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

int main(){
	ll n; cin >> n;
	vl a(n);
	vector<vl> x(n,vl(0));
	vector<vl> y(n,vl(0));
	rep(i,n){
		cin >> a[i];
		rep(j,a[i]){
			ll x0,y0;
			cin >> x0 >> y0;
			--x0;
			x[i].push_back(x0);
			y[i].push_back(y0);
		}
	}
	ll ans = 0;
	rep(tmp,(1 << n)){
		bitset<16> bi(tmp);
		bool ok = true;
		rep(i,n){
			if(!(bi.test(i)))continue;
			rep(j,a[i]){
				if(bi.test(x[i][j]) == 0 && y[i][j] == 1)ok = false;
				else if(bi.test(x[i][j]) == 1 && y[i][j] == 0)ok = false;
			}
		}
		ll m = bi.count();
		if(ok)ans = max(ans,m);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#define MOD 1000000007

long long int power(long long int s, long long int t)
{
	long long int ans = 1;
	long long int k = s;
	while(t)
	{
		if(t%2==1) ans*=k, ans%=MOD;
		k*=k, k%=MOD;
		t/=2;
	}
	return ans;
}
long long int inv(long long int k)
{
	return power(k,MOD-2);
}

std::pair<long long int,int> check1[200010];
long long int check2[200010];
std::vector<int> V[200010];
long long int fact[200010];
std::pair<long long int,int> func(int k, int prev)
{
	if(check1[k].second!=0) return check1[k];
	
	long long int ans = 1;
	int size = 0;
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		ans *= func(V[k][i],k).first, ans %= MOD;
		size += func(V[k][i],k).second;
	}
	ans *= fact[size], ans %= MOD;
	
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		ans *= inv(fact[func(V[k][i],k).second]), ans %= MOD;
	}
	
	return check1[k] = std::make_pair(ans,size+1);
}

long long int func2(int k, int prev, long long int value, int s)
{
	long long int ans = value;
	int size = s;
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		ans *= func(V[k][i],k).first, ans %= MOD;
		size += func(V[k][i],k).second;
	}
	ans *= fact[size], ans %= MOD;
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		ans *= inv(fact[func(V[k][i],k).second]), ans %= MOD;
	}
	ans *= inv(fact[s]), ans %= MOD;
	check2[k] = ans;
	
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		
		int S = size - func(V[k][i],k).second;
		long long int A = ans;
		A *= inv(fact[size]), A %= MOD;
		A *= fact[S], A %= MOD;
		A *= fact[func(V[k][i],k).second], A %= MOD;
		A *= inv(func(V[k][i],k).first), A %= MOD;
		func2(V[k][i],k,A,S+1);
	}
}

int main()
{
	fact[0] = 1;
	for(int i=1;i<=200000;i++) fact[i] = fact[i-1]*i, fact[i] %= MOD;
	int a;
	scanf("%d",&a);
	for(int i=1;i<a;i++)
	{
		int b,c;
		scanf("%d%d",&b,&c);
		V[b].push_back(c);
		V[c].push_back(b);
	}
	
	func2(1,0,1,0);
	for(int i=1;i<=a;i++) printf("%lld\n",check2[i]);
	
}

Measured memory_bytes: 20212
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n - 1; ++i) {
    int a;
    cin >> a;
    v[a - 1]++;
  }
  for (auto e : v) {
    cout << e << endl;
  }
  return 0;
}


Measured memory_bytes: 3536
S = input()
MOD = 10 ** 9 + 7

dp = [1,0,0,0]


for s in S:
    if s == 'A':
        dp[1] += dp[0]
    elif s == 'B':
        dp[2] += dp[1]
    elif s == 'C':
        dp[3] += dp[2]
    elif s == '?':
        dp[3] *= 3
        dp[3] += dp[2]
        dp[2] *= 3
        dp[2] += dp[1]
        dp[1] *= 3
        dp[1] += dp[0]
        dp[0] *= 3

    for i in range(4):
        dp[i] %= MOD


print(dp[3])


Measured memory_bytes: 3188
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import System.IO
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
trace _ = id

solve :: Maybe Int -> IO Int
solve nForTest =
  ask (10^10) >>= ite3 (binsch2 1 0 9) (binsch (10^8) (10^9 - 1))
  where

  binsch :: Int -> Int -> IO Int
  binsch lo hi
    | lo + 1 == hi = phase2 hi
    | otherwise = do
        let mi = (lo + hi) `div` 2
        ask (mi * 10) >>= ite3 (binsch lo mi) (binsch mi hi)
    
  phase2 :: Int -> IO Int
  phase2 n = binsch2 b 0 (k+1)
    where (b,k) = nDiv10 0 n
  
  binsch2 :: Int -> Int -> Int -> IO Int
  binsch2 b x y
    | x == y = return $ b * (10 ^ x)
    | otherwise = do
        let mL = (x + y) `div` 2
            mR = mL + 1
            t = (b * 10^mL + b * 10^mR) `div` 2
            cons = isConsis (b * (10 ^ x)) t
        ask t >>= ite3 (binsch2 b x mL) (binsch2 b mR y) . (== cons)
  
  ask :: Int -> IO Bool
  ask n = traceLM "ask" (n,) z
    where z = askX n
  askX n = sub n nForTest where
    sub n (Just n0) = return $ isConsis n n0
    sub n Nothing = do
      putStrLn $ "? " ++ show n
      line <- getLine
      let [resp] = words line
      return $ resp == "Y"

nDiv10 :: Int -> Int -> (Int, Int)
nDiv10 !acc n | r == 0 = nDiv10 (acc+1) d
              | otherwise = (n,acc)
  where (d,r) = divMod n 10
  
isConsis :: Int -> Int -> Bool
isConsis a b = traceL "isConsis" (a,b,z) z
  where z = isConsisX a b
isConsisX a b = (a < b) == (show a < show b)

main :: IO ()
main = do
  hSetBuffering stdin  NoBuffering
  hSetBuffering stdout NoBuffering
  n <- solve Nothing
  putStrLn $ "! " ++ show n
  
-------------------------------------------------------------------------------

ite3 :: a -> a -> Bool -> a
ite3 t e i = if i then t else e

traceL :: Show a => String -> a -> b -> b
traceL label showObj val = trace (label ++ " " ++ show showObj) val

traceLM :: (Monad m, Show a) => String -> (b -> a) -> m b -> m b
traceLM label showFn act = do
  aaa <- act
  traceL label (showFn aaa) (return ())
  return aaa

-------------------------------------------------------------------------------

lstTest = [1,10,100,10^9,3712,5000,60000,789000000,949741092,
           9,979,999,999000,10^9-1]
alltest = do
  forM_ lstTest $ \n -> do
    m <- solve (Just n)
    unless (m == n) (error ("Test Failed.  " ++ show (n,m)))
  putStrLn "pass."
  


Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="SAT")
    {
        cout<<1<<endl;
    }
    else if(s=="SUN")
    {
        cout<<7<<endl;
    }
    else if(s=="MON")
    {
        cout<<6<<endl;
    }
    else if(s=="TUE")
    {
        cout<<5<<endl;
    }
    else if(s=="WED")
    {
        cout<<4<<endl;
    }
    else if(s=="THU")
    {
        cout<<3<<endl;
    }
    else if(s=="FRI")
    {
        cout<<2<<endl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int x = 0;
	for (int i = 0; i < 3; i++) {
		int y;
		cin >> y;
		x += y;
	}

	cout << (x >= 22 ? "bust" : "win");
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

int main()
{
   string s;
   cin>>s;
   if(s[0]!='A'){
    cout<<"WA";
    return 0;
   }
   else{
        int c=0,c2=0;
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C'){
            c+=1;
        }
    }
    for(int i=0;i<s.size();i++){
        if(s[i]>=65&&s[i]<=90){
            c2+=1;
        }
    }
    if(c==1&&c2==2){
        cout<<"AC";
    }
    else{
        cout<<"WA";
    }

   }
    return 0;
}


Measured memory_bytes: 3596
z = 1
n = gets.to_i
array = []
n.times do
  a,b = gets.split
  c = b.to_i
  array << [a,c,z]
  z += 1
end

array.sort!{|a,b| a[1] <=> b[1]}
array.reverse!
array.sort!{|a,b| a[0] <=> b[0]}
for i in 0..(n-1)
  puts array[i][2]
end


Measured memory_bytes: 1788
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    a, b, c, d = get_int_multi()

    a1 = a * c
    a2 = a * d
    a3 = b * c
    a4 = b * d

    print(max(a1,a2,a3,a4))

if __name__ == '__main__':
    main()

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

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

  int n = s.size();
  if(t.substr(0,n) == s){
    ANS("Yes");
  }else{
    ANS("No");
  }

  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	char c;
	cin >> c;
	c++;
	cout << c;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main(void) {
    int N;
    cin>>N;
    vector<int> D;
    for (int i = 0; i < N; i++) {
        int d;
        cin>>d;
        D.push_back(d);
    }
    int delicious = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            delicious += D.at(i) * D.at(j);
        }
    }
    cout << delicious << endl;
    return 0;
}

Measured memory_bytes: 256
#import math
#=input()
#=int(input())
a,b,c,k=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

if k <= a:
    ans = k
elif k <= a + b:
    ans = a
else:
    ans = a - (k - a - b)

print(ans)

Measured memory_bytes: 9168
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n,y; cin >> n >> y;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; i+j <= n; ++j){
            if(10000*i + 5000*j + 1000*(n-i-j) == y){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
from collections import deque

N, M, Q = map(int, input().split())

query = [list(map(int, input().split())) for _ in range(Q)]

rlt = 0

stc = deque([])
for i in range(1,M+1):
  stc.append([0,i])

while stc:
  lst = stc.pop()
  if len(lst) == N+1:
    now = 0
    for a,b,c,d in query:
      if lst[b] - lst[a] == c:
        now += d
    rlt = max(rlt, now)
  else:
    for j in range(lst[-1],M+1):
      tmp = lst + [j]
      stc.append(tmp)

print(rlt)

Measured memory_bytes: 74928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var nk = RIs;
			var a = RIs;
			var k = nk[1];
			var n = nk[0];

			var ans = (int)Math.Ceiling((double)(n - 1 ) / (k - 1));
			Out(ans);
		}
	}
}


Measured memory_bytes: 20064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<vector<int>> c(3,vector<int>(3));
	rep(i,3){
		rep(j,3){
			cin >> c[i][j];
		}
	}
	rep(a1,101){
		int b1,b2,b3;
		if(c[0][0]<a1 || c[0][1]<a1 || c[0][2]<a1) break;
		b1=c[0][0]-a1;
		b2=c[0][1]-a1;
		b3=c[0][2]-a1;
		rep(a2,101){
			rep(a3,101){
				if(a2+b1==c[1][0] && a2+b2==c[1][1] && a2+b3==c[1][2] && a3+b1==c[2][0] && a3+b2==c[2][1] && a3+b3==c[2][2]){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
const int MOD = 1e9+7;
//}}}

int a[100];
int main(void){
	int N;
	cin >> N;
	rep(i, N) cin >> a[i];
	sort(a, a + N);
	reverse(a, a + N);
	int ans = 0;
	rep(i, N){
		ans += (i % 2 ? -a[i] : a[i]);
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int bk = b;
  while (bk > 0) {
    bk /= 10;
    a *= 10;
  }
  a += b;
  
  double ans = sqrt(a);
  if (ceil(ans) == floor(ans)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
//using Graph = vector<vector<int>>;


const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

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

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  int n,T;
  cin >> n >> T;
  int t[n+1],c[n+1];
  int ans = 0,mini = INF;
  rep (i,n){
    cin >> c[i] >> t[i];
    if (mini > c[i] && t[i]<=T){
      mini = c[i];
      ans = c[i];
    }
  }
  if (ans == 0) cout << "TLE" << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int m = S / 60 % 60;
        int s = S % 60;
        
        
        
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26400
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
  string s;
  cin >>s;
  ll k,l=0;
  cin >>k;
  ll ss=s.size();
  if(s[0]=='1'){
    l++;
    ll p;
    for(ll i=1;i<ss;i++){
      if(s[i]!='1') {
        p=i;
        break;
      }
      else l++;
    }
    if(k<=l) cout <<1<<endl;
    else cout <<s[p]<<endl;
  }
  else{
    cout <<s[0]<<endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <setjmp.h>

static const char * e;
static jmp_buf      co;

static int expr ( int );

static int
term (
  const int n
  )
{
  if ( *e == '(' )
  {
    int ret;

    ++e;
    ret = expr ( n );
    ++e;

    return ( ret );
  }

  if ( n == 0 )
  {
    printf ( "%c\n", *e );
    longjmp ( co, 1 );
  }
  ++e;

  return ( 1 );
}

static int
expr (
  int n
  )
{
  int res = 0;

  for ( ; ; )
  {
    const char * b;
    int p = 0;
    int ret;

    if ( *e == ')' || *e == '\0' ) break ;

    while ( isdigit ( *e ) )
    {
      p = ( p * 10 ) + ( *( e++ ) - '0' );
    }
    p = p ? p : 1;

    b = e;
    ret = term ( n );
    if ( n >= ret && n < ret * p )
    {
      e = b;
      ret = term ( n % ret )
          + ret * ( n / ret );
    }

    res += ret * p;
    n   -= ret * p;
  }

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    char s[ 128 ];
    int n;

    scanf ( " %s %d", s, &n );
    if ( n == 0 && !strcmp ( s, "0" ) ) break ;

    e = s;
    if ( setjmp ( co ) == 0 )
    {
      expr ( n );
      puts ( "0" );
    }
  }

  return ( 0 );
}

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

int main() {
	
	int n;
	int T[100000];
	int A[100000];

	cin >> n;
	rep(i, 0, n) cin >> T[i];
	rep(i, 0, n) cin >> A[i];

	if (T[n - 1] != A[0]) {
		cout << '0' << endl;
		return 0;
	}

	if (n == 2 || n == 1) {
		cout << '1' << endl;
		return 0;
	}

	
	long long int re = 1;
	rep(i, 1, n - 1) {
		if (T[i-1] == T[i] && A[i] == A[i + 1]) {
			re = re * min(T[i], A[i]) % 1000000007;
		}
		if (T[i] > A[i] && T[i - 1] != T[i]) {
			cout << '0' << endl;
			return 0;
		}
		if (T[i] < A[i] && A[i] != A[i + 1]) {
			cout << '0' << endl;
			return 0;
		}
	}

	cout << re << endl;

	return 0;
}

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

template <typename flow_t>
struct Dinic {
    const flow_t INF;

    struct edge {
        int to;
        flow_t cap;
        int rev;
        bool isrev;
        int idx;
    };

    vector<vector<edge>> graph;
    vector<int> min_cost, iter;

    Dinic(int V) : INF(numeric_limits<flow_t>::max()), graph(V) {}

    void add_edge(int from, int to, flow_t cap, int idx = -1) {
        graph[from].emplace_back(
            (edge){to, cap, (int)graph[to].size(), false, idx});
        graph[to].emplace_back(
            (edge){from, 0, (int)graph[from].size() - 1, true, idx});
    }

    bool bfs(int s, int t) {
        min_cost.assign(graph.size(), -1);
        queue<int> que;
        min_cost[s] = 0;
        que.push(s);
        while (!que.empty() && min_cost[t] == -1) {
            int p = que.front();
            que.pop();
            for (auto &e : graph[p]) {
                if (e.cap > 0 && min_cost[e.to] == -1) {
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return min_cost[t] != -1;
    }

    flow_t dfs(int idx, const int t, flow_t flow) {
        if (idx == t) return flow;
        for (int &i = iter[idx]; i < graph[idx].size(); i++) {
            edge &e = graph[idx][i];
            if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
                flow_t d = dfs(e.to, t, min(flow, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    flow_t max_flow(int s, int t) {
        flow_t flow = 0;
        while (bfs(s, t)) {
            iter.assign(graph.size(), 0);
            flow_t f = 0;
            while ((f = dfs(s, t, INF)) > 0) flow += f;
        }
        return flow;
    }
};

int main() {
    int V, E;
    cin >> V >> E;
    Dinic<int> dinic(V);
    for (int i = 0; i < E; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        dinic.add_edge(u, v, c);
    }
    cout << dinic.max_flow(0, V - 1) << endl;
}


Measured memory_bytes: 3244
#include <stdio.h>
 
main(){
  static int a[2000001],c[10001],b[2000001],k,n,i;
 
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
   
  k=0;
  for(i=1;i<=n;i++){
    if(a[i]>k) k=a[i];
  }
 
  for(i=0;i<=k;i++){
    c[i]=0;
  }
   
  for(i=1;i<=n;i++){
    c[a[i]]++;
  }
   
  for(i=1;i<=k;i++){
    c[i]=c[i]+c[i-1];
  }
 
  for(i=n;i>0;i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }
 
  for(i=1;i<=n;i++){
    if(i > 1) printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}

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

int main(){ 
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    if(s[a]!='-'){
        cout<<"No";
        return 0;
    }
    for(int i=0;i<a;i++){
        if(s[i]=='-'){
            cout<<"No";
            return 0;
        }
    }
    for(int i=a+1;i<a+b+1;i++){
        if(s[i]=='-'){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
//from PKU1125
#define M 101
double dist[M][M],d;
next[M][M],x[M],y[M];
main(){
	int a,b,k,n,i,j;
	for(;scanf("%d",&n),n;){
		/*initialize*/
		for(i=1;i<=n;i++)scanf("%d",&a),scanf("%d%d",x+a,y+a);
		for(i=1;i<=n;i++)for(j=1;j<=n;next[i][j]=j,j++)
			dist[i][j]=(d=hypot(x[i]-x[j],y[i]-y[j]))<50.1?d:999;

		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j],next[i][j]=next[i][k];
					}
		}

		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d",&a,&b);
				if(dist[a][b]>998)puts("NA");
				else{
					for(j=a;j!=b;j=next[j][b])printf("%d ",j);
					printf("%d\n",b);
				}
			}
		}
	}exit(0);
}

Measured memory_bytes: 744
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if(e-a <= f){
		cout << "Yay!";
	}else{
		cout << ":(";
	}
}

Measured memory_bytes: 256
n,a,b=gets.split.map(&:to_i)
case
  when a.zero? then puts 0
  when (n%(a+b)).zero? then puts a*(n/(a+b))
  else puts (n%(a+b))<=a ? a*(n/(a+b))+(n%(a+b)) : a*(n/(a+b))+a
end

Measured memory_bytes: 14388
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9999999999;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define f first
#define s second
#define pi 3.141592653589793238
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	ll x;
	cin >> x;

	ll a = x%100;
	x/=100;

	ll b = x%100;

	bool f = false,f2= false;

	if(a>=1&&a<=12) f = true;
	if(b>=1&&b<=12)f2=true;




	if(f&&f2) cout << "AMBIGUOUS\n";
	else if(!f&&!f2) cout << "NA\n";
	else if(f) cout << "YYMM\n";
	else cout << "MMYY\n";
	return 0;
}



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



int main(){
	ll n,m;
	cin>>n>>m;
	ll mcm = 1;
	ll array[n];
	for (int i = 0; i < n; ++i){
		cin>>array[i];		
		ll g = __gcd(mcm,array[i]);
		mcm *= array[i]/g;
		if(mcm > 2*m){
			cout<< 0<<endl;
			return 0;
		} 
	}	
	for (int i = 0; i <n; ++i)
	{
		if((mcm/2)%array[i] != array[i]/2){
			cout<< 0<<endl;
			return 0;
		}
	}
	ll ans = m/mcm;
	ll val = m%mcm;
	if(val >= mcm/2)ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
// AtCoder
// ABC 171 A - alphabet

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <random>
#include <vector>
#include <chrono>

using namespace std;
//using namespace std::chrono;


int main()
{
	//steady_clock::time_point start = steady_clock::now();
	char alpha;

	cin >> alpha;
	
	// 計算
	if (isupper(alpha)) {
		cout << "A" << endl;
	} else {
		cout << "a" << endl;
	}

	//計算時間集計
	/*
	steady_clock::time_point end = steady_clock::now();
    steady_clock::duration d = end - start;
	cout << "計算時間は" << duration_cast<milliseconds>(d).count() << "ミリ秒です。\n";
	*/
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	set<char> st(s.begin(),s.end());
	cout<<(st.count('7')?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a;
    cin>>a;
    for(int i=1; i<=9; i++) {
    	if(a%i == 0) {
    		int j = a/i;
    		if(j <= 9) {
    			cout<<"Yes\n";
    			return 0;
    		}
    	}
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
ll f[2220]={0,0,0,1};
int main()
{

    int s;
    cin>>s;
    for(int i=4;i<=s;i++)
    {
        f[i]=(f[i-1]+f[i-3])%mod;
    }
    cout<<f[s]<<endl;

    return 0;

}


Measured memory_bytes: 3624
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

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

using namespace std;

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

const int INF = 1001001001;

signed main()
{
    int h, w;
    cin >> h >> w;
    
    rep(i, h) rep(j, w){
        string s;
        cin >> s;
        if(s == "snuke"){
            cout << char(j+'A') << i+1 << endl;
        }
    }
}


Measured memory_bytes: 764
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>

int main (void){

    int N;
    scanf("%d",&N);

    int n1,n2,n3,n4,n5,n6;
    n1 = N / 100000;
    n2 = N / 10000 - n1 * 10;
    n3 = N / 1000 - n2 * 10 - n1 * 100;
    n4 = N / 100 - n3 * 10 - n2 * 100 -n1 *1000;
    n5 = N / 10 - n4 * 10 - n3 * 100 - n2 * 1000 - n1 * 10000;
    n6 = N /1 - n5 * 10 - n4 * 100 - n3 * 1000 - n2 * 10000 - n1 * 100000;

    int ans =0;

    if(n1>0){
        ans = 900 + 9 + 90000; 
    }

    if(n1==0 && n2>0){
        ans += n3 * 1000 + n4 * 100 + n5 * 10 + n6 + 1;
        for(int i=1;i<n2;i++){
            ans += 10000;
        }
        ans += 900 + 9;
    }

    if(n1==0 && n2==0 && n3>0){
        ans = 900 + 9;
    }

    if(n1==0 && n2==0 && n3==0 && n4>0){
        ans +=  n5 * 10 + n6 + 1;
        for(int i=1;i<n4;i++){
            ans += 100;
        }
        ans += 9;
    }    

    if(n1==0 && n2==0 && n3==0 && n4==0 && n5>0){
        ans = 9;
    }

    if(n1==0 && n2==0 && n3==0 && n4==0 && n5==0 && n6>0){
        ans +=  n6 ;
    }

    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128