akhauriyash/Code-Regression huggingface dataset:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
l = nl()
a = [0 for i in range(n + 1)]
for i in range(n):
    a[i + 1] = a[i] + l[i]
ans1 = 0
ans2 = 0
diff = 0
fluc = 0
b = a.copy()
for i in range(1, n + 1):
    a[i] += fluc
    diff = 0
    if i % 2 == 0 and a[i] <= 0:
        diff += -a[i] + 1
        fluc += diff
        ans1 += abs(diff)
    elif i % 2 == 1 and a[i] >= 0:
        diff -= a[i] + 1
        fluc += diff
        ans1 += abs(diff)
diff = 0
fluc = 0
a = b.copy()
for i in range(1, n + 1):
    a[i] += fluc
    diff = 0
    if i % 2 == 1 and a[i] <= 0:
        diff += -a[i] + 1
        fluc += diff
        ans2 += abs(diff)
    elif i % 2 == 0 and a[i] >= 0:
        diff -= a[i] + 1
        fluc += diff
        ans2 += abs(diff)
print(min(ans1, ans2))


Measured memory_bytes: 16656
#include<iostream>
using namespace std;
int main() 
{
  while(true) 
  {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) break;

    if (x < y)
    cout<<x<<" "<<y<<endl;
    else
    cout<<y<<" "<<x<<endl;
  }

  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;

typedef long long ll;

ll N, M;
ll ans = 0;

int main() {
	cin >> N >> M;
	priority_queue<ll>A;
	int temp;
	for (int i = 0; i < N; i++) {
		cin >> temp;
		A.push(temp);
	}
	for (int i = 0; i < M; i++) {
		int r = A.top();
		A.pop();
		A.push(r / 2);
	}
	for (int i = 0; i < N; i++) {
		ans += A.top();
		A.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	ll N;
	cin >> N;
	vector<ll> mem(N, 0);

	rep2 (i, 2, N + 1)
	{
		ll buka;
		cin >> buka;
		mem[buka - 1] += 1;
	}

	rep(i, N)
	{
		cout << mem[i] << '\n';
	}
	return 0;
}


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

int main(void) {
	int n;
	cin >> n;
	int a[n+1] = {0};
	int b[n] = {0};
	long long int count = 0;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] > b[i]) { //monsters > capacity
			count += b[i];
		} else {
			count += a[i];
			if (a[i+1] > b[i] - a[i]) {
				count += b[i] - a[i];
				a[i+1] -= b[i] - a[i];
			} else {
				count += a[i+1];
				a[i+1] = 0;
			}
		}
	}
	cout << count << "\n";
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            ulong m = ulong.Parse(input[1]);

            
            string[] input_a = Console.ReadLine().Split(' ');
            ulong[] ai = new ulong[n];
            ulong[] bi = new ulong[n];
            for(int i = 0;i < n;i++)
            {
                ai[i] = ulong.Parse(input_a[i]) / 2;
                bi[i] = ai[i];
            }
          
          
            
            if(n == 1)
            {
                if(ai[0] > m)
                    Console.WriteLine('0');
                else
                    Console.WriteLine((m - ai[0]) / 2 / ai[0] + 1);
                return;
            }
          
            for(int j = 0; j < 50;j++)
            {
                int count = 0;
                for(int i = 0;i < n;i++)
                {
                    int temp = (int)(bi[i] % 2);
                    if(temp == 0)
                    {
                        count++;
                        bi[i] /= 2;
                    }
                }
                if(count != 0 && count != n)
                    {
                        Console.WriteLine('0');
                        return;
                    }
            }

            Array.Sort(ai);
            ulong a = ai[n - 1];
            ulong b = ai[n - 2];
            ulong tempa = a;
            ulong tempb = b;
            ulong r = 1;

            while( r != 0 ) 
            {
                r = a % b;
                a = b;
                b = r;
            }

            a = tempa * tempb / a;
            
            if(a > m)
                {
                    Console.WriteLine('0');
                    return;
                }

            for(int i = n - 3;i >= 0; i--)
            {
                ulong temp2a = a;
                b = ai[i];
                ulong temp2b = ai[i];
                r = 1;
                while( r != 0 ) 
                {
                    r = a % b;
                    a = b;
                    b = r;
                }

                a = temp2a * temp2b / a;

                if(a > m)
                {
                    Console.WriteLine('0');
                    return;
                }

            }
        Console.WriteLine((m - a) / 2 / a + 1);
        }
        
    }

            

Measured memory_bytes: 26204
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<algorithm>
using namespace std;
int sovle(){
    string str;
    cin>>str;
    int n = str.size();
    int res = 0;
    for(int i=0;i<n/2;i++){
        if(str[i] != str[n-1-i]) res++;
    }
    return res;
}


int main(){
    int T = 1;
    while(T--){
        int re = sovle();
        cout<<re<<endl;
    }
    return 0;
}

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

typedef long long lint;
typedef pair<int, pair<int, int>> ppi;
const int MX=100010;

int n, m, X[MX];;
int U[MX], cnt[MX]; lint sz[MX]; 
ppi E[MX];

int find(int x){
	return x==U[x] ? x : U[x]=find(U[x]);
}
void unite(int x, int y){
	x = find(x), y = find(y);
	if(x==y) return;
	U[y]=x, sz[x]+=sz[y], cnt[x]+=cnt[y], cnt[y]=0;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m;
	for(int i=1; i<=n; i++) cin>>X[i];
	for(int i=1; i<=m; i++){
		int u,v,c; cin>>u>>v>>c;
		E[i] = {c, {u,v}};
	}
	sort(E+1, E+m+1);

	for(int i=1; i<=n; i++)
		U[i]=i, sz[i]=X[i];

	int sum=0;
	for(int i=1; i<=m; i++){
		int u,v; tie(u,v) = E[i].second;
		unite(u,v);
		cnt[find(u)]++;
		if(sz[find(u)] >= E[i].first){
			sum += cnt[find(u)];
			cnt[find(u)] = 0;
		}
	}
	cout<<m-sum<<'\n';
	return 0;
}

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

int main(){
        int a,b,x;
   do{
            scanf("%d",&x);
        }while(x<1 || x>1000);
        do{
            scanf("%d",&a);
        }while(a<1 || a>1000);
         do{
            scanf("%d",&b);
        }while(b<1 || b>1000);

  if((abs(x-abs(a)))<abs((x-abs(b)))) printf("A");
  else printf("B");

    return 0;
}


Measured memory_bytes: 1612
import std.stdio,std.string,std.conv;

int main()
{
	int n;
	while((n = readln.chomp.to!int) != 0)
	{
		int ans = 0;
		while((n /= 5) != 0)
		{
			ans += n;
		}

		ans.writeln;
	}
	return 0;
}

Measured memory_bytes: 1048
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  string N;
  cin >> N;
  if (N[0] == '7' || N[1] == '7' || N[2] == '7')
    cout << "Yes" << endl;
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
ll N,tm[505];
vector<tuple<int,int,int>> tp;
int main(void) {
	cin >> N;
	FOR(i, 0, N-1) {
		int a, b, c;
		cin >> a >> b >> c;
		FOR(k,0,i+1) {
			if (tm[k] < b)tm[k] = b;
			while (tm[k] % c != 0)tm[k]++;
			tm[k] += a;
		}
	}
	FOR(i,0,N)ct(tm[i]);
	
	return 0;
}

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

typedef long long ll;

using namespace std;

int main() {
    int N, A[100];
    bool approved = true;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0) {
            approved = false;
        }
    }
    cout << ( approved ? "APPROVED" : "DENIED" ) << endl;
    return 0;
}



Measured memory_bytes: 256
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

var lines = [];
var d, g, c, p;
var result = Infinity;

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var tmp = lines.shift().split(" ");
    d = Number(tmp[0]);
    g = Number(tmp[1]);

    p = Array(d + 1); p.fill(0);
    c = Array(d + 1); c.fill(0);

    for (var i = 0; i < d; i++) {
        tmp = lines[i].split(" ");

        p[i + 1] = {
            point: (i + 1) * 100,
            n: Number(tmp[0]),
        };
        c[i + 1] = Number(tmp[1]);
    }

    dfs(0, []);
    console.log(result);
});

function dfs(n, comb) {
    if (n === d) { calc(comb); return (0); }
    for (var i = 0; i < 2; i++) {
        comb[n] = i;
        dfs(n + 1, comb);
    }
}
function calc(comb) {
    var counter = 0; var sum = 0;
    var bonus = 0; var point = 0;

    for (var i = d; i > 0; i--) {
        if (comb[i - 1] === 1) {
            bonus = c[i];
            point = p[i].point * p[i].n;

            sum = sum + point + bonus;
            counter = counter + p[i].n;
        }
    }

    for (var i = d; i > 0; i--) {
        if (g - sum <= 0) { continue; }
        if (comb[i - 1] === 1) { var div = 0; }
        else { var div = Math.floor((g - sum) / (i * 100)) < p[i].n - 1 ? Math.floor((g - sum) / (i * 100)) : p[i].n - 1; }

        counter = counter + div;
        sum = sum + div * i * 100;
    }

    if (g <= sum && counter < result) { result = counter; }
}

Measured memory_bytes: 21448
#include<bits/stdc++.h>
using namespace std;
int n,a,dp[10005];
int main()
{
	scanf("%d",&n);
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		for(int j=10000;j>=0;j--)
		{
			if(dp[j]==1)
			{
				if(j+a<=10000)
				{
					dp[j+a]=1;
				}
			}
		}
	}
	for(int i=10000;i>=0;i--)
	{
		if(i==0)
		{
			printf("0\n");
			break;
		}
		if(i%10!=0&&dp[i]==1)
		{
			printf("%d\n",i);
			break;
		}
	}
}

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

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


int main() {
	int n;
	cin >> n;
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	cout << sum << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first < b.first;
    }
}
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0,1,1,-1,-1};
const vector<ll> dy{0,1,0,-1,1,-1,1,-1};


ll cnt=0;
vector<vector<bool>> seen(110,vector<bool>(110));
vector<vector<bool>> seen2(110,vector<bool>(110));
vector<vector<bool>> G;
ll W,H;
void dfs(ll h, ll w){
    seen[h][w] = 1;
    cnt++;
    rep(dir,8){
        ll nh = h + dy[dir];
        ll nw = w + dx[dir];

        if(!In_map(nh,nw,H,W)) continue;
        if(G[nh][nw] == 0) continue;
        if(seen[nh][nw]) continue;
        dfs(nh,nw);
    }



}


int main() {
    while(1){
    seen = seen2;
    G.clear();
    cin>>W>>H;
    if(W==0 && H==0) break;
    ll num=0;
    rep(i,H){
        G.emplace_back();
        rep(j,W){
            bool c;
            cin>>c;
            G[i].pb(c);
        }
    }
    
    ll cnt=0;
    rep(i,H){
        rep(j,W){
            if(G[i][j] == 0) continue;
            if(seen[i][j]) continue;
            dfs(i,j);
            cnt++;
            
        }
    }

    cout<<cnt<<endl;
    }
    return 0;
    

}


Measured memory_bytes: 3204
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int a, b, c;
	cin >> a >> b >> c;
	a *= 100;
	b *= 10;
	c += a + b;
	if (c % 4)cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;

}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
struct edge{int to,cost;};

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

int n, m;
int d[251];
vec G[252];
vec rG[252];
bool can_goal[252];
bool visited[252];

void dfs(int v){
    can_goal[v] = true;
    for(int i=0;i<rG[v].size();i++){
        if(!can_goal[rG[v][i]]) dfs(rG[v][i]);
    }
}

bool dfs2(int v){
    visited[v] = true;
    if(!can_goal[v]) return false;
    for(int i=0;i<G[v].size();i++){
        if(!visited[G[v][i]]&&!dfs2(G[v][i])){
            return false;
        }
    }
    return true;
}

void add_edge(int f,int t){
    G[f].push_back(t);
    rG[t].push_back(f);
}

int main(){
    while(cin >> m, m){
        cin >> n;

        for(int i=0;i<n+2;i++){
            G[i].clear();
            rG[i].clear();
        }
        d[0] = 0;
        for(int i=1;i<=n;i++){
            scanf("%d", &d[i]);
        }
        for(int i=0;i<n+1;i++){
            for(int j=1;j<=m;j++){
                if(i+j >= n+1 || i+j+d[i+j] >= n+1){
                    add_edge(i, n+1);
                }else{
                    add_edge(i, max(0, i+j+d[i+j]));
                }
            }
        }

        memset(can_goal, 0, sizeof(can_goal));
        dfs(n+1);
        memset(visited, 0, sizeof(visited));
        if(dfs2(0))cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;

int main(){
    int N;
    cin >> N;
    set<string> S;
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        S.insert(tmp);
    }
    cout << S.size() << endl;
    return 0;
}


Measured memory_bytes: 19176
#define _GLIBCXX_DEBUG

#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    
    ll n;
    cin >> n;

    string s;
    cin >> s;

    ll count = 0;
    //ll before_count;
    ll max_x = 0;
    REP(i,n){
        //before_count = count;
        if(s[i] == 'I'){
            count++;
        }
        else{
            count--;
        }
        max_x = max(max_x,count);
    }
    if(max_x < 0){
        max_x = 0;
    }
    cout << max_x << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
#include <algorithm>
using namespace std;


int main()
{
    int n,i,j,x=1;
    int p[1000]={0};
    int a[1000]={2};
     scanf("%d",&n);
     if(n==1)
     printf("1\n");
   else
   {
     for(i=3;i<=n;i++)
   {
    int flag=1;
    for(j=2;j<i;j++)
    {
      if(i%j==0)
      {
          flag=0;
          break;
      }
    }
    if(flag)a[x++]=i;
   }
   int temp;
   for(i=2;i<=n;i++)
   {
       temp=i;
       for(j=0;j<x;j++)
       {
           while(temp%a[j]==0)
           {
               p[j]++;
               temp/=a[j];
           }
       }
   }
   long long sum=1;
   for(j=0;j<x;j++)
   {
      sum*=(p[j]+1);
      sum%=(1000000000+7);
   }
   printf("%lld\n",sum);
   }
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    
    int dist = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (x <= abs(k - x)) {
            dist += 2 * x;
        } else {
            dist += 2 * abs(k - x);
        }
    }

    cout << dist << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e4+10;
#define PI 3.1415927
#define ll long long
int main()
{
	string s;
	int n;
	cin>>n;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		s[i]+=n;
		while(s[i]>'Z')
		s[i]-=26;
		cout<<s[i];
	}
	cout<<endl;
 } 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif

//	https://tenka1-2018-beginner.contest.atcoder.jp/assignments

static void A_Measure();

int main()
{
	A_Measure();

	fflush(stdout);
	return 0;
}

static void A_Measure()
{
	char szS[4] = { 0 };

	scanf(" %s", szS);

	if (strlen(szS) == 3) {
		char tmp = szS[0];
		szS[0] = szS[2];
		szS[2] = tmp;
	}
	printf("%s\n", szS);
}


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

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

n = I()
edges = [[] for _ in range(n)]
ab = [[i] + LI() for i in range(n-1)]
cnt = [0] * n
for i, a, b in ab:
    edges[a-1].append((i, b-1))
    edges[b-1].append((i, a-1))
    cnt[a-1] += 1
    cnt[b-1] += 1

k = max(cnt)
print(k)
que = deque([(0, -1, 0)])
edges_color = [None] * (n-1)
while que:
    v, p, col = que.popleft()
    cnt = 1
    for i, u in edges[v]:
        if edges_color[i] != None:
            continue
        if u == p:
            continue
        if cnt != col:
            edges_color[i] = cnt
        else:
            edges_color[i] = cnt + 1
            cnt += 1
        que.append((u, v, cnt))
        cnt += 1
for c in edges_color:
    print(c)

Measured memory_bytes: 112616
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define fi first
#define se second
#define MN 303
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct st{
	int l,r,x;
}a[MN];
typedef pair<int,int> pr;
vector <pr> v[MN];
int f[MN][MN][MN];
int n,m,res;
inline bool cmp(st a,st b){
	return (a.r==b.r)?a.l<b.l:a.r<b.r;
}
int main()
{
	n=in();m=in();
	for (int i=1;i<=m;++i){
		a[i].l=in();a[i].r=in();a[i].x=in();
		v[a[i].r].push_back(mp(a[i].l,a[i].x));
	}f[1][0][0]=3;
	for (int i=1;i<=n;++i)
	for (int j=0;j<i||(!j);++j)
	for (int k=0;k<i||(!k);++k){
		int siz=v[i].size(),cnt=0;
		for (int h=0;h<siz;++h){
			cnt=(v[i][h].fi<=i)+(v[i][h].fi<=j)+(v[i][h].fi<=k);
			if (cnt!=v[i][h].se) f[i][j][k]=0;
		}
		f[i+1][j][k]=(1ll*f[i+1][j][k]+f[i][j][k])%mod;
		f[i+1][i][k]=(1ll*f[i+1][i][k]+f[i][j][k])%mod;
		f[i+1][i][j]=(1ll*f[i+1][i][j]+f[i][j][k])%mod;
	}
	for (int j=0;j<n;++j)
	for (int k=0;k<j||(!k);++k) res=(1ll*res+f[n][j][k])%mod;
	printf("%d",res);return 0;
}

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

int main(){
	int n;
	cin>>n;
	if(n%10==7){
		cout<<"Yes"<<endl;
	}
	else if(n%100/10==7){
		cout<<"Yes"<<endl;
	}
	else if(n/100==7){
		cout<<"Yes"<<endl;
	}
	else if(n%100==77){
		cout<<"Yes"<<endl;
	}
	else if(n/10==77){
		cout<<"Yes"<<endl;
	}
	else if(n/100==7 && n%10==7){
		cout<<"Yes"<<endl;
	}
	else if(n==777){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3672
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a = int(input())
    b = int(input())
    h = int(input())

    res = ((a + b) * h) // 2
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M = LMIIS()
    tree = UnionFind(N)
    P = LMIIS()
    for i in range(M):
        x,y = LMIIS()
        tree.union(x-1,y-1)
    ans = 0
    for i in range(N):
        if i+1 == P[i] or tree.find(i) == tree.find(P[i]-1):
            ans += 1
    print(ans)



    

if __name__ == '__main__':
    main()

Measured memory_bytes: 109544
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/05/01 05:13:15 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define int long long
#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using PII = pair<int, int>;

// TOP
void	Main()
{
	int n, limit;
	cin >> n >> limit;
	vector<int>	dp(limit + 1);
	rep(i, n)
	{
		int	w, v;
		cin >> w >> v;
		rrep(j, limit)
		{
			if (j + w > limit)
				continue;
			dp.at(j + w) = max(dp.at(j + w), dp.at(j) + v);
		}
	}
	cout << dp.back() << endl;
}
// END

int32_t		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1024
N = int(input())
# 残せるものは残す方針
A = list(map(int, input().split()))
pointa = 1
flag = False
for i in range(N):
    if A[i] == pointa:
        flag = True
        pointa += 1

if flag:
    print(N-(pointa-1))
else:
    print(-1)


Measured memory_bytes: 26268
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 998244353LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */
// quoted from beet-aizu
template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    // using F = function<T(T, T)>
    // using G = function<T(T, E)>
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }

    /* TODO わからない 聞く 
    template<typename C>
    int find(int a,int b,C &check,int k,int l,int r){
        if(!check(dat[k])||r<=a||b<=l) return -1;
        if(k>=n) return k-n;
        int m=(l+r)>>1;
        int vl=find(a,b,check,(k<<1)|0,l,m);
        if(~vl) return vl;
        return find(a,b,check,(k<<1)|1,m,r);
    }
    template<typename C>
    int find(int a,int b,C &check){
        return find(a,b,check,1,0,n);
    }*/
    
};


int main(){
  using T = lint;  // type T
  using E = lint;  // type E
  auto f = [](T a, T b){ // return type T value
    return (a + b) % MOD;
  };
  auto g = [](T a, E b){ // return type T value
    return (a + b) % MOD;  // return b;
  };
  T ti = 0;  // identity element
  SegmentTree<T, E, decltype(f), decltype(g)> sg(f, g, ti);  // don't change

  lint n, k; cin >> n >> k;
  sg.build(vector<T>(n, 0));
  sg.update(0, 1);

  vector<lint> l(k);
  vector<lint> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {

      int left = i - r[j];
      if (left < 0) left = 0;
      int right = i - l[j];

      if (right < 0) continue;

      lint add = sg.query(left, right + 1);
      sg.update(i, add);
    }
  }


  cout << sg.query(n - 1, n) << endl;
}


Measured memory_bytes: 8324
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	vector<long long> a(n), b(n);
	for(int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	sort(a.begin(), a.end());
	b[0] = a[0];
	for(int i = 1; i < n; i++) {
		b[i] = b[i - 1] + a[i];
	}
	int ans = 1;
	for(int i = n - 2; i >= 0; i--){
		if(b[i] * 2 < a[i + 1]){
			break;
		}
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


int main() {

    int n;
    ll a, b;
    cin >> n >> a >> b;

    vector<ll> monsters(n);
    rep(i, n) cin >> monsters[i];

    auto check = [&](ll mid) {
        vector<ll> m = monsters;
        rep(i, n) {
            ll need = (m[i] + b - 1) / b;
            if (need <= mid) {
                m[i] = 0;
            } else {
                m[i] -= mid * b;
                assert(m[i] > 0);
            }
        }

        ll count = 0;
        ll na = a - b;
        for (ll h : m) count += (h + na - 1) / na;
        return count <= mid;
    };

    ll floor = 0, ceil = INF;
    while (floor + 1 < ceil) {
        ll mid = (floor + ceil) / 2;
        bool ok = check(mid);
        if (ok) {
            ceil = mid;
        } else {
            floor = mid;
        }
    }
    assert(check(floor) == false);
    assert(check(ceil) == true);

    cout << ceil << endl;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<math.h>
#include<iomanip>
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	//int n;
	//cin >> n;
	//if (n % 10 == 3)
	//	cout << "bon";
	//else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
	//	cout << "pon";
	//else
	//	cout << "hon";

	//int n = 0;
	//cin >> n;
	//string duck;
	//cin.ignore();
	//getline(cin, duck);
	//if (n > duck.size())
	//	n = duck.size();
	//for (int i = 0; i < n; i++) {
	//	cout << duck[i];
	//}
	//if(n<duck.size())
	//cout << "...";

	double h, m;
	int a, b;
	cin >> a >> b;
	cin >> h >> m;
	 
	
	double degree = abs(h * 30+m/60.0*30 - m * 6);
	
	if (degree > 180)
		degree = 360 - degree;
	
	if (degree == 180)
	{
		cout <<fixed<<setprecision(20)<< a + b;
	}
	else 
	{
		double duck = 0;
		double delta = degree*PI / 180.0;
		duck = pow(a, 2) + pow(b, 2) - 2 * a*b*cos(delta);
		cout << fixed << setprecision(20) << pow(duck, 0.5);
	}



    return 0;
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main(){
   string s;
   cin>>s;
   int num = 0;
   for(char c : s){
       num+=(c-'0');
   }
   cout<<(num%9==0?"Yes":"No")<<endl;
}

Measured memory_bytes: 3716
import sys
import re


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s=input()

if re.fullmatch("A?KIHA?BA?RA?", s):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 70516
n = int(input())
a = list(map(int, input().split()))
odd = a[0::2]
even = a[1::2]
ans = []
if n%2 == 0:
	even.reverse()
	ans.extend(even)
	ans.extend(odd)
	print (*ans)
else:
	odd.reverse()
	ans.extend(odd)
	ans.extend(even)
	print (*ans)

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

using namespace std;

int main(){
	string in, out;
	bool flg = false;
	getline(cin, in);

	replace(in.begin(), in.end(), ',', ' ');
	replace(in.begin(), in.end(), '.', ' ');
	
	for(int i=0; i<in.size(); i++){
		if(in[i] == ' ' || in[i] == '\n'){
			if(out.size() > 2 && out.size() < 7){
				if(flg){ cout<<" "; }
				cout<<out;
				flg = true;
			}
			out = "";
		}else{
			out += in[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1168
<?php
  while ($line = fgets(STDIN)) {
   $array[] = trim($line);
   for($i = 0; $i < count($array); $i++) {
     $array[$i] = (int)$array[$i];
   }
  }

  $large_yen = $array[0];
  $middle_yen = $array[1];
  $small_yen = $array[2];
  $balance = $array[3];
  $count = 0;
  
  for($a = 0; $a <= $large_yen; $a++) {
   	for($b = 0; $b <= $middle_yen; $b++) {
      for($c = 0; $c <= $small_yen; $c++) {
       	$total = $a * 500 + $b * 100 + $c * 50;
        if($total == $balance) $count++;
      }
   	}
  }

  echo($count);


Measured memory_bytes: 3576
#!/usr/bin/env python3
import sys
# import itertools
import collections


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    # # TLE
    # c = itertools.combinations_with_replacement(range(1, N + 1), 2)
    # cnt = 0
    # for i in c:
    #     x = i[0]
    #     y = i[1]
    #     if x + A[x - 1] == y - A[y - 1]:
    #         cnt += 1
    # print(cnt)

    L = []  # 左辺
    R = []  # 右辺
    for i in range(N):
        x = y = i + 1
        L.append(x + A[i])
        R.append(y - A[i])
    cl = collections.Counter(L)
    cr = collections.Counter(R)
    ans = 0
    for i in range(N):
        if i in cl and i in cr:
            ans += cl[i] * cr[i]
    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 63796
a=int(input())
b=int(input())
c=int(input())
x=int(input())
n=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i*500+j*100+k*50 == x:
                n+=1
print(n)

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

#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)


using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n + 1; ++i) {
        if (i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    solve();
    return 0;
}


Measured memory_bytes: 3692
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};


bool length_cmp( string &a, string &b ){
  return a.size() < b.size();
}

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num * 10 + ( s[i] ^ 48 );
  }
  return num;
}

ll CtoLL( char c )
{
	if( 'a' <= c && c <= 'z'){
		return (ll)( c ^ 96 ) ;
	}
	else if( 'A' <= c && c <= 'Z'){
		return (ll)( c ^ 64 );
	}
  return 0;
}


//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(x) LIN(y)
    puta( x + y / 2 );
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    long N=gl();
	    long A=gl();
	    long B=gl();
	    long max=B*(N-1)+A;
	    long min=A*(N-1)+B;
	    
	    System.out.println(Math.max(max-min+1,0));
//        if(k==H+W-1) {
//        	System.out.println("Possible");
//        }else {
//        	System.out.println("Impossible");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35500
n = gets.to_i
a = []
n.times do |i|
  x,y = gets.split.map &:to_i
  a << [x,y]
end

dist = []
(0..n-1).to_a.combination(2) do |i,j|
  x = a[i][0]-a[j][0]
  y = a[i][1]-a[j][1]
  if y < 0 || (y == 0 && x < 0)
    y = -y
    x = -x
  end
  dist << [x,y]
end

cnt = dist.group_by(&:itself)
  .values
  .map(&:size)
  .max

cnt ||= 0
puts n - cnt

Measured memory_bytes: 1916
import numpy as np

n , k = map(int, input().split())

p = np.array(list(map(int, input().split())))


index = 0
goukei = sum(p[0:k])
max = goukei
for j in range(n-k):
    goukei = (goukei - p[j] + p[j+k])
    if goukei > max:
        max = goukei
        index = j+1

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

Measured memory_bytes: 33784
# INPUT
n = int(input())
words = [input() for _ in range(n)]

# PROCESS
answer = "Yes"
already_taken = []
for idx in range(len(words)):
  
  if (idx == 0):
    already_taken.append(words[idx])
    continue

  if (words[idx] in already_taken):
    answer = "No"
    break
  if (words[idx][0] != already_taken[-1][len(already_taken[-1])-1]):
    answer = "No"
    break
  already_taken.append(words[idx])

# OUTPUT
print(answer)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int
main()
{
  int n;
  cin >> n;
  int hp;
  cin >> hp;
  int hn;
  int m = 0;
  int tm = 0;
  for (int i = 0; i < n - 1; ++i) {
    cin >> hn;
    if (hn <= hp) {
      ++tm;
    }
    else {
      if (tm > m) {
        m = tm;
      }
      tm = 0;
    }
    hp = hn;
  }
  if (tm > m) {
    m = tm;
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1 << 18, MOD = 998'244'353, INF = 0x3f3f3f3f;

int n;
pair<int, int> p[N];
int uf[N];
int find(int x) { return x == uf[x] ? x : uf[x] = find(uf[x]); }
void merge(int a, int b) {
  a = find(a); b = find(b);
  if (a > b) swap(a, b); 
  uf[a] = b;
}

ll dp[N];

pair<int, int> t[2*N];
void upd(int x, int v, int i) {
  t[N+x] = {v, i};
  for (x += N, x /= 2; x; x /= 2) {
    t[x] = max(t[2*x], t[2*x+1]);
  }
}
pair<int, int> query(int l, int r) {
  pair<int, int> ans = {-INF, -1};
  for (l += N, r += N+1; l < r; l /= 2, r /= 2) {
    if (l%2) ans = max(ans, t[l++]);
    if (r%2) ans = max(ans, t[--r]);
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  iota(uf, uf + N, 0);
  fill(t, t + 2*N, make_pair(-INF, -1));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + n);
  for (int i = n-1; i >= 0; i--) {
    int j = upper_bound(p, p + n, make_pair(p[i].first+p[i].second, -INF)) - p - 1;
    auto v = query(i, j);
    //cerr << i << " -> " << v.second << nl;
    if (v.second != -1) merge(i, v.second);
    upd(i, p[i].first+p[i].second, i);
  }
  dp[n] = 1;
  for (int i = n-1; i >= 0; i--) {
    // don't knock
    dp[i] += dp[i+1];
    // knock
    dp[i] += dp[find(i)+1];
    dp[i] %= MOD;
  }
  cout << dp[0] << nl;
}


Measured memory_bytes: 8960
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    int a,b;
    cin >> a >> b;
    if(a>=13){
        cout << b << endl;
    }else if(a<=12 && 6<=a){
        cout << b/2 << endl;
    }else{
        cout << 0 <<endl;
    }
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll X;
vector<ll> A;

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

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

  cin >> X;
  ll P = 100;
  ll count = 0;
  while (P < X) {
    P = floor(P + 0.01*P);
    count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3736
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin>>
#define co cout<<
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{


long long a,b,c,d,e,f,g,h;


string s;
cin>>a>>s>>b;

if (s=="+")
{
	/* code */
	cout<<a+b<<endl;
}
else
cout<<a-b<<endl;

return 0;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int query(int x) {
  cout << x << endl;
  string res;
  cin >> res;
  if (res == "Male") return 0;
  else if (res == "Female") return 1;
  else exit(0);
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  int lo = 0, hi = N-1;
  int base = query(0);
  while (hi - lo > 1) {
    int mid = (lo+hi) / 2;
    if (query(mid) != (base+mid)%2) hi = mid;
    else lo = mid;
  }
  query(lo);
  query(hi);
  abort();
  return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll a,b;
    cin >> a >> b;

    ll a2 = 0;
    ll b2 = 0;

    if(a <= b){
        rep(i,b){
            a2 += a * pow(10,b-i-1);
        }
    }
    else{
        rep(i,a){
            b2 += b * pow(10,a-i-1);
        }
    }
    cout << max(a2,b2);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    int k;
    cin >> n >> k;
    vector<int> ng_num;
    rep(i, k) {
        int d;
        cin >> d;
        ng_num.push_back(d);
    }
    sort(ng_num.begin(), ng_num.end());
    int ans = n;
    while(1) {
        bool ok = true;
        rep(i, ng_num.size()) {
            int tmp_ans = ans;
            while(1) {
                if ( tmp_ans == 0 ) break;
                if ( tmp_ans % 10 == ng_num[i] ) {
                    ok = false;
                }
                tmp_ans /= 10;
            }
            if ( !ok ) break;
        }
        if ( ok ) break;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
$<.map{|l|(n=l.to_i)>0&&(d=n-1
e=n*n+1
h=n/2
s=(0..h+1).flat_map{|i|[e/2-h-d*i,e-h-d*i]}[0,n]
n.times{puts"%4d"*n%s;s=s.rotate(-1).map{|i|i%n>0?i+1:i-d}})}

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

using namespace std;


using ll = long long;

const int N = 20;

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int l;
    cin >> l;
    l--;
    int cur = 1;
    vector<tuple<int, int, int> > ans;
    while (l > 0) {
        if (l % 2 == 0) {
            ans.emplace_back(cur, N, l);
            l--;
        }
        ans.emplace_back(cur, cur + 1, 0);
        ans.emplace_back(cur, cur + 1, (l + 1) / 2);
        l /= 2;
        cur++;
    }
    while (cur != N) {
        ans.emplace_back(cur, cur + 1, 0);
        cur++;
    }
    cout << N << " " << ans.size() << endl;
    for (const auto& e : ans) {
        cout << get<0>(e) << " " << get<1>(e) << " " << get<2>(e) << endl;
    }
}




Measured memory_bytes: 256