akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <queue>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const int INF = 1e9;
const ll MOD = 1e9 + 7;

struct edge
{
    int to, cost;
};

int di_n; //頂点数
vector<edge> G[1123456];
int di_dis[1123456] = {INF};

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(di_dis, di_dis + 1123456, INF);
    di_dis[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int di_n_ = p.second;
        if (di_dis[di_n_] < p.first)
            continue;
        for (int i = 0; i < G[di_n_].size(); i++)
        {
            edge e = G[di_n_][i];
            if (di_dis[e.to] > di_dis[di_n_] + e.cost)
            {
                di_dis[e.to] = di_dis[di_n_] + e.cost;
                que.push(P(di_dis[e.to], e.to));
            }
        }
    }
}

int main()
{
    int n, m, p[212345], q[212345], c[212345];
    map<P, int> mp;
    cin >> n >> m;

    di_n = 0;

    REP(i, m)
    {
        cin >> p[i] >> q[i] >> c[i];

        if (mp[P(p[i], c[i])] == 0)
        {
            di_n++;
            mp[P(p[i], c[i])] = di_n;
        }
        if (mp[P(q[i], c[i])] == 0)
        {
            di_n++;
            mp[P(q[i], c[i])] = di_n;
        }
        if (mp[P(p[i], -1)] == 0)
        {
            di_n++;
            mp[P(p[i], -1)] = di_n;
        }
        if (mp[P(q[i], -1)] == 0)
        {
            di_n++;
            mp[P(q[i], -1)] = di_n;
        }

        G[mp[P(p[i], c[i])]].push_back(edge{mp[P(q[i], c[i])], 0});
        G[mp[P(p[i], c[i])]].push_back(edge{mp[P(p[i], -1)], 0});

            G[mp[P(p[i], -1)]].push_back(edge{mp[P(p[i], c[i])], 1});
         

        G[mp[P(q[i], c[i])]].push_back(edge{mp[P(p[i], c[i])], 0});
        G[mp[P(q[i], c[i])]].push_back(edge{mp[P(q[i], -1)], 0});

            G[mp[P(q[i], -1)]].push_back(edge{mp[P(q[i], c[i])], 1});
          
    }

    dijkstra(mp[P(1, -1)]);

    if (di_dis[mp[P(n, -1)]] == INF || mp[P(n, -1)] == 0)
    {
        cout << -1 << endl;
        return 0;
    }

    cout << di_dis[mp[P(n, -1)]] << endl;

    return 0;
}


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

public class Main {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader fr = new FastReader();

		int N = fr.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];

		for (int i = 0; i < N; i++) {
			a[i] = fr.nextInt();
			b[i] = fr.nextInt();
			c[i] = fr.nextInt();
		}

		int[][] dp = new int[2 * N][3]; // 3 for 3 activities

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 3; j++) {
				if (i == 0) {
					switch (j) {
					case 0:
						dp[i][j] = a[i];
						break;
					case 1:
						dp[i][j] = b[i];
						break;
					case 2:
						dp[i][j] = c[i];
						break;
					}
				} else {
					for (int k = 0; k < 3; k++) {
						if (j == k) {
							/* Do nothing */ } else if (j == 0)
							dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + a[i]);
						else if (j == 1)
							dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + b[i]);
						else if (j == 2)
							dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + c[i]);
					}
				}
			}
		}
		
		int ret = 0;
		
		ret = Math.max(ret, dp[N-1][0]);
		ret = Math.max(ret, dp[N-1][1]);
		ret = Math.max(ret, dp[N-1][2]);
		
		System.out.println(ret);
	}

}


Measured memory_bytes: 63364
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, M, cap;
    cin >> N >> M >> cap;
    if (N == 0 && M == 0 && cap == 0){
      break;
    }
    cap *= 10;
    string src, dest;
    cin >> src >> dest;
    vector<string> c1(N), c2(N);
    vector<int> d(N);
    for (int i = 0; i < N; i++){
      cin >> c1[i] >> c2[i] >> d[i];
    }
    vector<string> s(M);
    for (int i = 0; i < M; i++){
      cin >> s[i];
    }
    vector<string> city;
    for (int i = 0; i < N; i++){
      city.push_back(c1[i]);
      city.push_back(c2[i]);
    }
    sort(city.begin(), city.end());
    city.erase(unique(city.begin(), city.end()), city.end());
    int cnt = city.size();
    map<string, int> mp;
    for (int i = 0; i < cnt; i++){
      mp[city[i]] = i;
    }
    int t1 = mp[src];
    int t2 = mp[dest];
    vector<vector<pair<int, int>>> E(cnt);
    for (int i = 0; i < N; i++){
      int v = mp[c1[i]];
      int w = mp[c2[i]];
      E[v].push_back(make_pair(d[i], w));
      E[w].push_back(make_pair(d[i], v));
    }
    vector<bool> a(cnt, false);
    for (int i = 0; i < M; i++){
      a[mp[s[i]]] = true;
    }
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
    pq.push(make_tuple(0, t1, cap));
    set<pair<int, int>> used;
    int ans = -1;
    while (!pq.empty()){
      int t = get<0>(pq.top());
      int v = get<1>(pq.top());
      int c = get<2>(pq.top());
      pq.pop();
      if (v == t2){
        ans = t;
        break;
      }
      if (!used.count(make_pair(v, c))){
        used.insert(make_pair(v, c));
        for (auto P : E[v]){
          int d = P.first;
          int w = P.second;
          int c2 = c - d;
          if (c2 >= 0){
            if (a[w]){
              c2 = cap;
            }
            if (!used.count(make_pair(w, c2))){
              pq.push(make_tuple(t + d, w, c2));
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 211256
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100 + 10;
char S[Maxn];
int A[Maxn], Sum[Maxn], Pos[Maxn];
inline void chkmax(int &x, int y) { x = max(x, y); }
inline void chkmin(int &x, int y) { x = min(x, y); }
int main()
{
	scanf("%s", S);
	for (int i = 1; i <= 26; ++i) Pos[i] = -1;
	for (int i = 0; i < strlen(S); ++i)
	{
		int cur = S[i] - 'a' + 1;
		chkmax(Sum[cur], i - Pos[cur] - 1);
		Pos[cur] = i;
	}
	int Ans = 0x3f3f3f3f;
	for (int i = 1; i <= 26; ++i)
	{
		chkmax(Sum[i], strlen(S) - Pos[i] - 1);
		chkmin(Ans, Sum[i]);
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

#let
N = int(input())
A = map(int, input().split())

#var
ans = sys.maxsize

for i, v in enumerate(A):
    cnt = 0
    j = v
    while j % 2 == 0:
        cnt += 1
        j //= 2
    ans = min(ans, cnt)

print(ans)

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

using namespace std;

#define endl "\n"
//a#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vvi vector < vector < int >  >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define fore(i,c) for(int i = 1; i <= (int)c; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
//#define double long double
#define a first
#define b second


int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);

    string s;
    cin >> s;
    bool b = false, a = false;
    for(auto x:s){
        if(x == 'A'){
            a = true;
        }else if(x == 'B')
            b = true;
    }    

    if(b && a) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
// use std::collections::HashMap;

fn solve() -> i32 {
    let _ = read();
    let s = read_line_str();
    // let mut hmap: HashMap<char, i32> = HashMap::new();

    for i in s.replace("\n", "").replace(" ", "").chars() {
        if i == 'Y' {
            println!("Four");
            return 0;
        }
    }
    println!("Three");
    return 0;
}

fn main() {
    solve();
    // let _ = read();
    // let s = read_line_str();
    // let mut hmap: HashMap<char, i32> = HashMap::new();

    // for i in s.replace("\n", "").replace(" ", "").chars() {
    //     let mut n: i32 = 0;
    //     match hmap.get(&i) {
    //         Some(k) => n = *k,
    //         None => (),
    //     }
    //     hmap.insert(i, n + 1);
    // }

    // // for (k, v) in hmap.drain() {
    // //     println!("{}:{}", k, v);
    // // }

    // if hmap.keys().len() == 3 {
    //     println!("Three");
    // } else {
    //     println!("Four");
    // }
}

fn read() -> i32 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// fn read_line() -> (i32, i32) {
//     let mut s = String::new();
//     std::io::stdin().read_line(&mut s).ok();
//     let v : Vec<i32> = s.trim()
//         .split_whitespace()
//         .map(|e| e.parse().ok().unwrap())
//         .collect();
//     return (v[0], v[1]);
// }

fn read_line_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  long long H, W;
  cin >> H >> W;
  if(H != 1 && W != 1){
    cout << (H * W + 1) / 2 << endl;
    return 0;
  }
  
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = n; i > 0; i /= 10) {
    sum += i % 10;
  }
  cout << (n % sum == 0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    map<string , int>mp;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<mp.size();
    return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
};

char inputbuf[4096];
char *ptr = inputbuf;

int main() {
	fread_unlocked(inputbuf, 1, sizeof(inputbuf), stdin);
	int n = 0;
	while (*ptr >= '0' && *ptr <= '9') n = n * 10 + *ptr++ - '0';
	while (*ptr != 'R' && *ptr != 'G' && *ptr != 'B') ptr++;
	
	int back[3] = { 0 };
	int forward[3] = { 0 };
	int a[n];
	for (int i = 0; i < n; i++) {
		a[i] = ptr[i] == 'R' ? 0 : ptr[i] == 'G' ? 1 : 2;
		back[a[i]]++;
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<40961, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = (int64_t) count[i][j] * count[(i + 1) % 3][j] % 40961;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}


Measured memory_bytes: 3948
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999

n = int(input())
A = [-INF] + get_nums_l()

# log(n)
# log(A)

edges = [ [] for _ in range(n+1) ]
# for _ in range(n-1):
for line in map(lambda s: s.strip(), sys.stdin.readlines()):
    # line = input()
    # log(line)
    u,v = map(int, line.split())
    edges[u].append(v)
    edges[v].append(u)

def dfs(dp, u, p=None):

    # log(u)
    # log(dp)

    # dpの中でA[u]以上の値が入っている最小のindex
    i = bisect_left(dp, A[u])

    old = dp[i]
    dp[i] = A[u]

    # 有効値(INF以外)が入っている最大のindex
    ans[u] = bisect_left(dp, INF) - 1

    for v in edges[u]:
        if v == p:
            continue
        dfs(dp, v, u)

    # 巻き戻し
    dp[i] = old

# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)

# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF

dfs(dp, 1, None)

for i in range(1, n+1):
    print(ans[i])


Measured memory_bytes: 361732
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int main()
{
	int h,w;
	scanf("%d%d", &h, &w);
	char str[h + 1][w + 1];
	int i = 0;
	int j;
	while (i < h)
	{
		scanf("%s", str[i]);
		i++;
	}
	i = 0;
	while (i < h)
	{
		printf("%s\n", str[i]);
		printf("%s\n", str[i]);
		i++;
	}
	return (0);
}

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

const int N = 200005;
const int INF = 1000000005;
const int MOD = 998244353;
typedef long long i64;

int a[N], b[N];
vector<int> V;

int main ()
{
    int n;
    cin >> n;
    i64 ans = 0;
    bool flag = true;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] != b[i]) flag = false;
        if (a[i] <= b[i]) ans += b[i];
        else V.push_back(b[i]);
    }
    if (flag) puts("0");
    else {
        sort(V.begin(), V.end());
        for (int i = 1; i < V.size(); ++i) ans += V[i];
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a;
    cin >> a;

    cout << pow(a,3) << endl;
   return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],dp[100001],k;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i],dp[i]=1000000000;
dp[1]=0;
for(int i=2;i<=n;i++)
for(int j=max(1,i-k);j<i;j++)
dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
cout<<dp[n];
return 0;
}


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

using namespace std;
#define ll long long
int main(){
    int n;
    cin >> n;
    ll ans=0;
    vector<int> a(101,0);
    a[0]=1;
    for(int i=1;i<=100;i++){
        if (i<4)continue;
        if(a[i-4]==1)a[i]=1;
        if (i<7)continue;
        if(a[i-7]==1)a[i]=1;

    }
    if (a[n])cout <<"Yes"<<endl;
    else cout <<"No"<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>

#define st first
#define nd second

using namespace std;

typedef long long ll;

const int MAXN = 2E5 + 10;

pair<int, int> a[MAXN];
int pre[MAXN], nex[MAXN];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i <= n; ++i)
		nex[i] = i + 1, pre[i + 1] = i;
	for (int i = 1; i <= n; ++i){
		scanf("%d", &a[i].st);
		a[i].nd = i;
	}
	sort(a + 1, a + n + 1);
	ll ans = 0;
	for (int i = n; i >= 1; --i){
		int u = a[i].nd;
//		printf("%d %d %d %d\n", u, a[i].st, pre[u], nex[u]);
		ans += (ll)a[i].st * (u - pre[u]) * (nex[u] - u);
		pre[nex[u]] = pre[u];
		nex[pre[u]] = nex[u];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

bool check(int n, map<ll, int> &t) {
	if (t.size() == 1) {
		if ((*t.begin()).first == 0) return true;
	}
	else if (t.size() == 2) {
		if (n % 3 != 0) return false;

		int zeroNum = (*t.begin()).second;
		int xNum = (*t.rbegin()).second;

		if ((*t.begin()).first != 0 && (*t.rbegin()).first == 0) swap(zeroNum, xNum);

		if (zeroNum == n / 3 && xNum == n * 2 / 3) return true;
		else return false;
	}
	else if (t.size() == 3) {
		if (n % 3 != 0) return false;

		int s = 0;
		for (auto p = t.begin(); p != t.end(); ++p) {
			if ((*p).second != n / 3) return false;
			s ^= (*p).first;
		}

		if(s == 0) return true;
		else return false;
	}

	return false;
}

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];

	map<ll, int> t;
	rep(i, n) ++t[a[i]];

	if (check(n, t)) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}


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

using namespace std;
typedef long long ll;

int INF = 100000000;

int main()
{

    int N;

    cin >> N;

    vector<vector<int>> hijo(N, vector<int>(0));
    vector<int> X(N);
    vector<int> X_inv(N, 0);
    vector<vector<int>> depth(N, vector<int>(0));
    for (int i = 0; i < N - 1; i++)
    {
        int p;
        cin >> p;
        hijo[p - 1].push_back(i + 1);
    }

    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        X[i] = x;
    }

    int depthn = 0;
    depth[0].push_back(0);

    vector<int> S(0);
    S.push_back(0);

    while (S.size() != 0)
    {

        depthn++;

        vector<int> A = S;
        S.clear();
        for (int v : A)
        {
            for (int u : hijo[v])
            {
                S.push_back(u);
                depth[depthn].push_back(u);
            }
        }
    }

    for (int k = depthn - 1; k >= 0; k--)
    {

        for (int v : depth[k])
        {


            int num = hijo[v].size();

            int sum = 0;

            vector<vector<int>> dp(X[v] + 1, vector<int>(num + 1, INF));

            if (hijo[v].size() > 0)
            {

                for (int j = 0; j < X[v] + 1; j++)
                {

                    dp[j][0] = 0;

                    if (X[hijo[v][0]] <= j)
                    {

                        dp[j][1] = X_inv[hijo[v][0]];
                    }
                    if (j >= X_inv[hijo[v][0]])
                    {
                        dp[j][1] = min(X[hijo[v][0]], dp[j][1]);
                    }
                }

                for (int i = 0; i < num; i++)
                {

                    sum += X[hijo[v][i]];
                }

                for (int i = 1; i < num; i++)
                {
                    for (int j = 0; j < X[v] + 1; j++)
                    {
                        if (j >= X[hijo[v][i]])
                        {
                            dp[j][i + 1] = dp[j - X[hijo[v][i]]][i] + X_inv[hijo[v][i]];
                        }

                        if (j >= X_inv[hijo[v][i]])
                        {
                            dp[j][i + 1] = min(dp[j - X_inv[hijo[v][i]]][i] + X[hijo[v][i]], dp[j][i + 1]);
                        }
                    }
                }

                X_inv[v] = dp[X[v]][num];


                if (X_inv[v] > 5000000)
                {

                    cout << "IMPOSSIBLE" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "POSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1528
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    x,t=parseMap(split(readline()))
    println(max(x-t,0))
end
main()

Measured memory_bytes: 166592
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;
 
 
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int N, K;
  cin >> N >> K;
  int A[N];
  rep(i, N){
    cin >> A[i];
  }
 
  int sum[N+1] = {};
  map<int, int> mp;
  for(int i=1;i<=N;i++){
    sum[i] = sum[i-1] + A[i-1] - 1;
    sum[i] %= K;
  }
 
  for(int i=1;i<min(K, N+1);i++){
    mp[sum[i]]++;
  }
  int ans = mp[0];
  for(int i=1;i<=N;i++){
    mp[sum[i]]--;
    if(i+K-1 <= N){
      mp[sum[i+K-1]]++;
    }
    ans += mp[sum[i]];
  }
  
  cout << ans << endl;
 
}

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

int main(){
    ll n;
    cin >> n;
    ll l = 0, r = n;

    cout << l << endl;
    string t, u = " ";
    cin >> t;
    if (t == "Vacant") exit;
    else u = t;

    while (r - l  > 1){
        ll y = (l + r) / 2;
        cout << y << endl;
        string s;
        cin >> s;
        if (s == "Vacant") break;
        else{
            if (((y - l + 1) % 2 == 0 && u != s) || ((y - l + 1) % 2 != 0 && u == s)){
                l = y;
                u = s;
            }
            else r = y;
        }
    }
}

Measured memory_bytes: 852
from fractions import  gcd
a, b, c, d = map(int, input().split())
e = c*d//gcd(c, d)
p = b//c - (a-1)//c
q = b//d - (a-1)//d
r = b//e - (a-1)//e
l = b-a+1
print(l - (p+q-r))

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

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    
    vector<int> p;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        p.push_back(t);
    }
    
    sort(p.begin(), p.end());
    
    int a = 0;
    for (int i = 0; i < n/2 + 1; i++) {
        int K = p[i];
        int ABC = 0;
        for (int i = 0; i < n/2 + 1; i++) {
            if (p[i] < K) {
                ABC++;
            }
        }
        
        if (ABC == n/2) {
            a = i;
            break;
        }
    }
    
    if (a == 0) {
        cout << a << endl;
        return 0;
    }
    
    cout << p[a] - p[a-1] << endl;
    
    return 0;
}

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

int main() 
{
   int X, Y, Z, K;
   cin >> X >> Y >> Z >> K;

   vector<long long> A(X);
   for (int i = 0; i < X; i++)
      cin >> A.at(i);
   
   vector<long long> B(Y);
   for (int i = 0; i < Y; i++)
      cin >> B.at(i);
   
   vector<long long> C(Z);
   for (int i = 0; i < Z; i++)
      cin >> C.at(i);

   vector<long long> AB(X * Y);
   
   for (int i = 0; i < X; i++)
   {
      for (int j = 0; j < Y; j++)
      {
         AB.at(i * Y + j) = A.at(i) + B.at(j);
      }
   }
   
   sort(AB.begin(), AB.end());
   reverse(AB.begin(), AB.end());

   int N = min (X * Y, K);
   vector<long long> ABC(N * Z);

   for (int i = 0; i < N; i++)
   {
      for (int j = 0; j < Z; j++)
      {
         ABC.at(i * Z + j) = AB.at(i) + C.at(j);
      }
   }
   
   sort(ABC.begin(), ABC.end());
   reverse(ABC.begin(), ABC.end());

   for (int i = 0; i < K; i++)
      cout << ABC.at(i) << endl;
}


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


int main() {
  string S;
  cin >> S;
  
  char a = S.at(0);
  char b = S.at(1);
  char c = S.at(2);
  
  cout << a << b << c <<endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>

using ForwardIt = typename std::string::const_iterator;

std::string node(ForwardIt&);
std::string node(ForwardIt&, ForwardIt&, char);
std::string tree(ForwardIt&, ForwardIt&, char);

std::string node(ForwardIt& s) {
  assert(*s == '(');
  std::string res(1, *s++);
  int opened=1;
  while (opened) {
    if (*s == '(') {
      ++opened;
    } else if (*s == ')') {
      --opened;
    }
    res += *s++;
  }
  return res;
}

std::string node(ForwardIt& s, ForwardIt& t, char op) {
  std::string res;
  if (*s != '(') {
    assert(*s == ',' || *s == ')');
    if (*t != '(') {
      assert(*t == ',' || *t == ')');
    } else {
      std::string tmp=node(t);
      if (op == 'u') res += tmp;
    }
  } else if (*t != '(') {
    assert(*t == ',' || *t == ')');
    std::string tmp=node(s);
    if (op == 'u') res += tmp;
  } else {
    res += tree(s, t, op);
  }
  return res;
}

std::string tree(ForwardIt& s, ForwardIt& t, char op) {
  assert(*s == '(');
  assert(*t == '(');
  ++s;
  ++t;

  std::string res="(";

  res += node(s, t, op);

  assert(*s == ',');
  assert(*t == ',');
  ++s;
  ++t;

  res += ',';

  res += node(s, t, op);

  assert(*s == ')');
  assert(*t == ')');
  ++s;
  ++t;

  res += ')';
  return res;
}

int testcase_ends() {
  char op;
  if (scanf(" %c", &op) == EOF) return 1;

  char buf[1024];
  scanf("%s", buf);
  std::string s=buf;
  scanf("%s", buf);
  std::string t=buf;

  auto s_it=s.cbegin();
  auto t_it=t.cbegin();

  printf("%s\n", tree(s_it, t_it, op).c_str());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2648
import itertools

n_m_input = list(map(int, input().split()))
n = n_m_input[0]
m = n_m_input[1]

all_point_string = ''.join([str(i+1) for i in range(n-1)])
path_string_list = list(itertools.permutations(all_point_string))

edge_list = [[0]*n for _ in range(n)]
counter = 0
answer = 0

for _ in range(m):
	edge = list(map(int, input().split()))
	edge_list[edge[0]-1][edge[1]-1] = 1
	edge_list[edge[1]-1][edge[0]-1] = 1

for path in path_string_list:
	counter = 0
	path_str = '0'+''.join(path)
	for i in range(n-1):
		if edge_list[int(path_str[i])][int(path_str[i+1])] == 1:
			counter += 1
	if counter == n-1:
		answer += 1

print(answer)


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

const int N=2e5+20;

int n;
long long ans;
map <int,int> m;

int main()
{
    
	scanf("%d",&n);
    vector<int>a(n+1);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		ans+=m[a[i]-i];
		m[-a[i]-i]++;
	}

	cout<<ans;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if((H % h == 0) && (W % w == 0)){
        cout << "No" << endl;
        return 0;
    }
    /*bool checkH[600];
    bool checkW[600];
    for(int i = 1; i <= 550; i++){
        checkH[i] = false;
        checkW[i] = false;
    }
    for(int i = h; i <= H; i += h){
        checkH[i] = true;
    }
    bool checker = true;
    for(int i = H - h + 1; i <= H; i++){
        if(checkH[i]){
            checker = false;
        }
    }
    if(checker){
        checkH[H] = true;
    }
    checker = true;
    for(int i = w; i <= W; i += w){
        checkW[i] = true;
    }
    for(int i = W - w + 1; i <= W; i++){
        if(checkW[i]){
            checker = false;
        }
    }
    if(checker){
        checkW[W] = true;
    }
    int sum = 0;
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(checkH[i] && checkW[j]){
                sum -= h * w;
            } else {
                sum += 1;
            }
        }
    } 
    if(sum <= 0){
        cout << "No" << endl;
        return 0;
    }*/
    cout << "Yes" << endl;
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if((i % h == 0) && (j % w == 0)){
                cout << -1000000000;
            } else if(((i - 1) % h == 0) && ((j - 1) % w == 0)){
                cout << 1000000000 - w * h + 1;
            } else {
                cout << 1;
            }
            if(j < W){
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

const int MAX = 2 * 1e5 + 10;
long long a[MAX];
int N;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", a + i);
  }
  list<long long> vec;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) vec.emplace_front(a[i]);
    else vec.emplace_back(a[i]);
  }
  if (N % 2 == 0) {
    for (auto it = vec.rbegin(); it != vec.rend(); it++) {
      printf("%lld ", *it);
    }
    puts("");
  } else {
    for (auto it = vec.begin(); it != vec.end(); it++) {
      printf("%lld ", *it);
    }
    puts("");
  }
}


Measured memory_bytes: 9984
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ALphabet solver = new ALphabet();
        solver.solve(1, in, out);
        out.close();
    }

    static class ALphabet {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char x = in.next().toCharArray()[0];

            if (x >= 'A' && x <= 'Z')
                out.println("A");
            else
                out.println("a");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

int main(){
	int n;
  	cin >> n;
  	for(int i = 1; i < 10; i++){
      if(n % i == 0 && n/i > 0 && n/i < 10){
        cout << "Yes\n";
        return 0;
      }
    }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
// Created by arjun_singh12 (Arjun Singh) on [12-05-2020 11:19:29]
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
#define INF LLONG_MAX
#define vll vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>>
#define pb push_back
#define pll pair<ll,ll>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define repr(i,n,a) for(ll i=n;i>=a;i--)
#define endl "\n"
#define db(x); cout<<"Debug: "<<#x<<" = "<<x<<endl;
#define dbv(v); cout<<"Debug: Vector "<<#v<<" = "; for(ll i=0;i<sz(v);i++) cout<<v[i]<<" "; cout<<endl;
using namespace std;

ld dp[3003][3003];
int dp1[3003][3003];
ld solve(vector<ld> &v,ll n,ll num_of_heads)
{
	if(n==-1 && num_of_heads>(sz(v)/2))
		return 1;
	else if(n==-1)
		return 0;
	if(dp1[n][num_of_heads]!=-1) return dp[n][num_of_heads];
//	dp1[n][num_of_heads]=true;
	dp[n][num_of_heads] = v[n]*solve(v,n-1,num_of_heads+1)+(1-v[n])*solve(v,n-1,num_of_heads);
	dp1[n][num_of_heads] = 1;
	return dp[n][num_of_heads];
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll test=1;
//	cin>>test;
	while(test--)
	{
	    ll n;
	    cin>>n;
	    vector<ld> v(n);
	    rep(i,0,n) cin>>v[i];
	    rep(i,0,3003)
	    {
	    	rep(j,0,3003)
	    	{
	    		dp1[i][j]=-1;
	    		dp[i][j]=0.0;
			}
		}
		cout<<fixed<<setprecision(10);
	    cout<<solve(v,n-1,0);
//		rep(i,0,n+1)
//		{
//			rep(j,0,n+1)
//			{
//				cout<<dp[i][j]<<" ";
//			}
//			cout<<endl;
//		}
	}
}

Measured memory_bytes: 176640
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

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

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

    Dinic(int V) : graph(V) {}

    void add_edge(int from, int to, ll cap, int idx = -1) {
        graph[from].push_back({ to, cap, (int)graph[to].size(), false, idx });
        graph[to].push_back({ 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;
    }

    ll dfs(int idx, const int t, ll 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]) {
                ll 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;
    }

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

    void output() {
        for (int i = 0; i < graph.size(); i++) {
            for (auto &e : graph[i]) {
                if (e.isrev) continue;
                auto &rev_e = graph[e.to][e.rev];
                cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
            }
        }
    }
};

int main() {
    int V, E;
    scanf("%d %d", &V, &E);
    Dinic g(V);
    for (int i = 0; i < E; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        g.add_edge(a, b, c);
    }
    printf("%d\n", g.max_flow(0, V - 1));
    //g.output();
    getchar(); getchar();
}


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

int main(){
    string s; cin >> s;
    sort(s.begin(), s.end());                                          
    s[0] == s[1] && s[2] == s[3] && s[1] != s[2]
    ? cout << "Yes" : cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

constexpr int MOD = 1000000007;

int main()
{
    int N, J = 0, K = 0, L = 0;
    cin >> N;

    vector<int> st(N * 2 + 1);
    REP(_, N)
    {
        int A, B;
        cin >> A >> B;
        if (A < 0 and B > 0) st[B] = 1, K++;
        else if (A > 0 and B < 0) st[A] = 1, K++;
        else if (A > 0 and B > 0) st[A] = st[B] = 2, L++;
        else J++;
    }

    vector<vector<int>> dp[2];
    REP(d, 2) ndarray(dp[d], N - L + 1, K + 1);
    dp[0][0][0] = 1;

    int G = 0, H = 0, t = 0;

    REP(i, 2 * N)
    {
        int s = st[2 * N - i];
        if (s == 2) continue;
        else if (s)
        {
            REP(j, N - L + 1) IREP(k, K + 1)
            {
                dp[t][j][k] = (j < N - L ? dp[t][j + 1][k] : 0) + (k ? dp[t][j][k - 1] : 0);
                if (dp[t][j][k] >= MOD) dp[t][j][k] -= MOD;
            }
            H++;
        }
        else
        {
            dp[!t].assign(N - L + 1, vector<int>(K + 1));
            REP(j, N - L + 1) REP(k, K + 1) if (dp[t][j][k])
            {
                int pa2 = G + H - j - k - (H - k) * 2;
                if (j < N - L) (dp[!t][j + 1][k] += dp[t][j][k]) %= MOD;
                if (j)
                {
                    dp[!t][j - 1][k] += dp[t][j][k] * (long long int)(J - pa2 / 2) % MOD;
                    if (dp[!t][j - 1][k] >= MOD) dp[!t][j - 1][k] -= MOD;
                }
                if (k)
                {
                    dp[!t][j][k - 1] += dp[t][j][k] * (long long int)k % MOD;
                    if (dp[!t][j][k - 1] >= MOD) dp[!t][j][k - 1] -= MOD;
                }
            }
            G++;
            t = !t;
        }
    }
    cout << dp[t][0][0] << endl;
}


Measured memory_bytes: 1024
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int a=0,b=0,ab=0,o=0;
		while(scan.hasNext()){
			String mozi = scan.next();
			if(mozi.contains("AB")){
				ab++;
				continue;
			}
			if(mozi.contains("A")) a++;
			if(mozi.contains("B")) b++;
			if(mozi.contains("O")) o++;
		}
		out.println(a);
		out.println(b);
		out.println(ab);
		out.println(o);
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 17168
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

 
int main(int argc, char* argv[])
{
    long n, kk;
    scanf("%ld %ld", &n, &kk);

    vector<pair<long, long> > a(n);

    long i;
    for(i=0; i<n; i++) {
        scanf("%ld %ld", &(a[i].second), &(a[i].first));
    }
    sort( a.rbegin(), a.rend() );

    ll sum=0;
    set<long> setUsedT;
    vector<long> DforUsedT;
    ll nUsedT=0;
    for(i=0; i<kk; i++) {
        sum += a[i].first;
        if(setUsedT.insert(a[i].second).second) {
            nUsedT++;
        }
        else {
            DforUsedT.push_back(a[i].first);
        }
    }
    ll ans = sum + nUsedT * nUsedT;

    long id_rmv = (long)DforUsedT.size() -1;
    
    for(i=kk; i<n; i++) {
        if(setUsedT.insert(a[i].second).second) {
            nUsedT++;
            if(id_rmv>=0) {
                sum = sum + (a[i].first) - DforUsedT[id_rmv];
                ans = MAX(ans, sum + nUsedT * nUsedT );
                id_rmv--;
            }
            else {
                break;
            }
        }
    }

    printf("%lld\n", ans);
 
    return 0;
}


Measured memory_bytes: 5116
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for i in range(M)]

for n in range(1000):
    n = str(n)
    if len(n) != N:
        continue
    b = True
    for s,c in SC:
        if n[s-1] != str(c):
            b = False
            break
    if b:
        print(n)
        break
if not b:
    print(-1)



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
using namespace std;

int main() {
	int a, b, c,d;
	cin >> a >> b >> c>>d;
	if (abs(a-c) <= d) {
		cout << "Yes";
		return 0;
	}
	else if (abs(a-b) <=d&& abs(b-c) <= d) {
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int l;
    cin >> l;

    int tmp = l;
    int n = 0;
    while(tmp > 0)
    {
        tmp >>= 1;
        n++;
    }
    int cur = n-2;
    int cand = pow(2, cur);
    int bound = pow(2, n-1);
    vector<vector<int>> edge;
    for(int i = 1; i < n; i++)
    {
        if(l - cand >= bound)
        {
            edge.push_back({n-i, n, l-cand});
            l -= cand;
        }
        cand >>= 1; 
    }

    cout << n << " " << 2*(n-1) + (int)edge.size() << endl;
    int x = 1;
    for(int i = 1; i < n; i++)
    {
        cout << i << " " << i+1 << " " << 0 << endl;
        cout << i << " " << i+1 << " " << x << endl;
        x *= 2;
    }
    for(int i = 0; i < edge.size(); i++)
    {
        cout << edge[i][0] << " " << edge[i][1] << " " << edge[i][2] << endl;
    }
}


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

using namespace std;

#define int long long



signed main() {
	int a, b;

	cin >> a >> b;

	int ans = 0;

	if (b == 1) {
		cout << ans;
	}

	else {
		while (b > 0) {

			if (ans == 0) {
				b -= a;
				ans++;
			}
			else {
				b = b - a + 1;

				ans++;
			}
		}
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;

int main() {
	vector<vector<ll>> c(3, vector<ll>(3));
	for (ll i = 0; i < 3; i++)
	{
		for (ll j = 0; j < 3; j++)
		{
			cin >> c[i][j];
		}
	}
	for (ll i = 0; i < 2; i++)
	{
		if ((c[1][i + 1] - c[1][i] == c[0][i + 1] - c[0][i] && c[0][i + 1] - c[0][i] == c[2][i + 1] - c[2][i]) &&
			(c[i + 1][0] - c[i][0] == c[i + 1][1] - c[i][1] && c[i + 1][1] - c[i][1] == c[i + 1][2] - c[i][2])) continue;
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var ans = 'Christmas';
	var eve = ' Eve';
	var m = 25 - n;

	for(var i = 0; i < m; i++){
		ans += eve;
	}

	
	console.log(ans);
}

Measured memory_bytes: 21064
#define _USE_MATH_DEFINES

#include<math.h>
#include<stdio.h>
#include<utility>
#include<algorithm>

int main() {
	long n, m, a, sum, max, min;
	scanf("%ld", &n);///////////////////////
	m = 1;
	max = -10000000;
	min = 10000000;
	sum = 0;
	while (m <= n) {
		scanf("%ld", &a);//////////////////////////
		if (a > max) {
			max = a;
		}
		if (a < min) {
			min = a;
		}
		sum += a;
		m++;
	}
	printf("%ld %ld %ld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 2760
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;

int main() {
	int n, x, y; cin >> n >> x >> y;
	x--; y--;
	vector<int>ans(n+1, 0);
	rep(i, n-1) {
		for (int j = i + 1; j <= n - 1; j++) {
			int a = min(abs(j - i), abs(x - i) + abs(y - j)+1);
			ans[a]++;
		}
	}
	rep(i, n - 1) {
		cout << ans[i + 1] << endl;
	}
}

































    





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

int main(void){
  int D;
  cin >> D;
  int i;
  cout << "Christmas ";
  REP(i,25-D) cout << "Eve ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
K = int(input())
S = input()
s = len(S)
L = []

mod = 10 ** 9 + 7
N = 2 * 10**6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

def cmb(n, r):
  return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
 
for i in range(2, N + 1):
  fac.append( ( fac[-1] * i ) % mod )
  inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
  finv.append( finv[-1] * inv[-1]  % mod )

for i in range(K+1):
  L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )

ans = []

for i, x in enumerate(L):
  if i == 0:
    ans.append(x)
  else:
    ans.append( ( ans[i-1]*26%mod + x ) % mod )

print(ans[K])

Measured memory_bytes: 232240
R, G, B, N = map(int, input().split())

ans = 0
r = 0
g = 0
while r * R <= N:
    g = 0
    while r * R + g * G <= N:
        diff = N - (r * R + g * G)
        if diff % B == 0:
            ans += 1
        g += 1
    r += 1

print(ans)


Measured memory_bytes: 42236
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    
    
    
     public static void main(String[] args) {
        
         Scanner sc = new Scanner(System.in);
         int A = sc.nextInt();
         int L = sc.nextInt();
          int b[ ] = new int[A];
         int a[ ] = new int[A];
         for(int i = 0 ; i<A ; i++){
                   a[i]  =  i+1;
             
         }
         
       for(int i = 0 ; i<A ; i++){
               b[i]=  L+a[i]-1;
           
       }  
         Arrays.sort(b);
         int sum = 0 ;
         for(int i=0; i<b.length ; i++){
             sum+=b[i];
             
         }
         int bestsofar=Integer.MAX_VALUE;
         int ans=0;
         for(int i=0;i<A;i++)
         {
         int cur=sum-b[i];
         int diff=Math.abs(b[i]);
         if(diff<bestsofar)
         {
             ans=cur;
             bestsofar=diff;
         }
         }
      //   System.out.println(b[1]+b[2]+b[3]+b[4]+b[5]);
         System.out.println(ans);
         
    }
}


Measured memory_bytes: 22612
import Data.List
f [_] = []
f (x:y:xs) = (y-x) : f (y:xs)
main = do
  [n,m] <- map (read::String->Int) . words <$> getLine
  xs <- map (read::String->Int) . words <$> getLine -- length of xs = m
  let nn = n-1
  let ys = sortOn (0 -) $ f $ sort xs
  print $ sum $ drop nn ys


Measured memory_bytes: 34812
#include <iostream>
#include <cstdio>

using namespace std;

typedef struct{
  int k;
  char m[50];
}res;

res r[1000];
int adj[1000][1000] = {{0}};
int n;
void show(int num,int f){
  f++;
  for(int i=0;i<f;++i)
    putchar('.');
  printf("%s\n",r[num].m);

  for(int i = num ;i<n;++i)
    if(adj[i][num]){
      show(i,f);
    }
}

int main(){
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> r[i].k >> r[i].m;
    adj[i][r[i].k-1] = 1;
  }

  show(0,-1);

}

Measured memory_bytes: 5112