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

class UnionFindTree {
private:
    vector<int> parent;
    vector<int> count;

public:
    UnionFindTree(int n) : parent(n), count(n, 1) {
        for (int i = 0; i < n; i++) parent[i] = i;
    }
    int get_root(const int x) {
        if (parent[x] == x) return x;
        return parent[x] = get_root(parent[x]);
    }
    void unite(const int x, const int y) {
        int rx = get_root(x), ry = get_root(y);
        if (rx == ry) return;
        parent[rx] = ry;
        count[ry] += count[rx];
        count[rx] = 0;
    }
    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }
    int get_size(const int x) { return count[get_root(x)]; }
    void print() {
        for (auto elm : parent) cout << elm << " ";
        cout << endl;
        for (auto elm : count) cout << elm << " ";
        cout << endl;
    }
};
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> p(n), x(n);
    set<pair<int, int>> y;
    UnionFindTree tree(n);
    for (auto i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        x[i] = {p[i].first, i};
    }
    sort(x.begin(), x.end());
    for (auto i = 0; i < n; i++) {
        // auto tmp =
        //     y.lower_bound({p[x[i].second].second, 0});
        for (auto itr = y.begin(); itr != y.end();) {
            if (itr->first > p[x[i].second].second) break;
            tree.unite(x[i].second, itr->second);
            if (itr == y.begin()) ++itr;
            else
                itr = y.erase(itr);
        }
        if (y.empty() or
            p[x[i].second].second < y.begin()->first)
            y.insert({p[x[i].second].second, x[i].second});
    }
    for (auto i = 0; i < n; i++)
        cout << tree.get_size(i) << endl;
    return 0;
}

Measured memory_bytes: 13648
import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

from math import gcd

INF = float('inf')
NIL = - 1

N = int(input())
ans = 0
for i in range(1, N + 1):
    if i == 1:
        ans += N ** 2
        continue
    for j in range(1, N + 1):
        if j == 1:
            ans += N
            continue
        tmp = gcd(i, j)
        for k in range(1, N + 1):
            ans += gcd(tmp, k)
print(ans)




Measured memory_bytes: 9580
n=int(input())
h=list(map(int,input().split()))
ans=0

while sum(h)>0:
    flug=0
    for i in range(n):
        if h[i]>0:
            h[i]-=1
            flug=1
        else:
            if flug==1:
                ans+=1
                flug=0
    else:
        if flug==1:
            ans+=1
    
print(ans)

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int N;
int digit[4];

int main()
{
    ZERO(digit);
    cin >> N;
    digit[0] = N / 1000;
    digit[1] = (N % 1000) / 100;
    digit[2] = (N % 100) / 10;
    digit[3] = N % 10;

    if(digit[0] == digit[1] && digit[0] == digit[2] ||
       digit[1] == digit[2] && digit[1] == digit[3]) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}


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

const int N = 123456;
const int INF = 1e9;

int n;
vector<pair<int, int>> g[N];
int dist[N];

int m;
int d[N];

void gg() {
    puts("No");
    exit(0);
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        g[a].emplace_back(b, 1);
        g[b].emplace_back(a, 1);
    }

    scanf("%d", &m);
    fill_n(d, n, -1);
    for (int i = 0; i < m; i++) {
        int v, c;
        scanf("%d %d", &v, &c);
        v--;
        d[v] = c;
        g[n].emplace_back(v, c);
    }

    fill_n(dist, n + 1, INF);
    dist[n] = 0;

    set<pair<int, int>> que;
    que.emplace(0, n);

    while (!que.empty()) {
        int d, v;
        tie(d, v) = *que.begin();
        que.erase(que.begin());
        if (d != dist[v]) {
            continue;
        }

        for (auto e: g[v]) {
            int w = e.second + d;
            int u = e.first;
            if (dist[u] <= w) {
                continue;
            }

            que.erase({dist[u], u});
            que.emplace(w, u);
            dist[u] = w;
        }
    }

    for (int i = 0; i < n; i++) {
        if (d[i] != -1 && d[i] != dist[i]) {
            gg();
        }

        for (auto e: g[i]) {
            if (abs(dist[e.first] - dist[i]) != 1) {
                puts("No");
                return 0;
            }
        }
    }

    puts("Yes");
    for (int i = 0; i < n; i++) {
        printf("%d\n", dist[i]);
    }
}


Measured memory_bytes: 13684
#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int a[n],i;
    for(i=0;i<=n-1;i++)scanf("%d",&a[i]);
    int maxp=a[1]-a[0];
    int min=a[0];
    for(i=1;i<=n-1;i++){
        if(maxp<a[i]-min)maxp=a[i]-min;
        if(min>a[i])min=a[i];
    }
    printf("%d\n",maxp);
    
    return 0;
}

Measured memory_bytes: 1376
#include <iostream>
#include <cmath>

using namespace std;

constexpr int Mmax = 100;

void print_array(int* A, int n) {
    for (int i = 0; i < n; i++) { cout << A[i] << endl; }
}

int insertionSort(int* A, int n, int g) {
    int cnt = 0;
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 and A[j] > v) {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
    return cnt;
}

void shellSort(int* A, int n) {
    // init
    int m;
    int* G = new int[Mmax];
    G[0] = 1;
    for (m = 1; m < Mmax; m++) {
        int g = 0.5 * (pow(3,m+1) - 1);
        if (g > n) { break; }
        G[m] = g;
    }

    // sort
    int cnt = 0;
    for (int i = m-1; i >= 0; i--) {
        int d_cnt = insertionSort(A, n, G[i]);
        cnt += d_cnt;
    }

    // print
    cout << m << endl;
    for (int i = m-1; i >= 0; i--) {
        if (i < m-1) { cout << " "; }
        cout << G[i];
    }
    cout << endl;
    cout << cnt << endl;
}

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

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

    shellSort(a, n);
    print_array(a, n);

    return 0;
}

Measured memory_bytes: 7036
S=input()
XXX=int(S[0:2])
YYY=int(S[2:4])

YM=False
MY=False


if YYY<13 and YYY>0:
	MY=True


if XXX>0 and XXX<13:
	YM=True


if MY and YM :
	print("AMBIGUOUS")
elif MY:
	print("YYMM")
elif YM:
	print("MMYY")
else:
	print("NA")

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

int main()
{
    int a,b;
    int W,H;
    cin >> H >> W;
    
    while(H)
    {
        for(int j=0; j<W; j++)
        {
            cout << '#';
        }
        cout << endl;

        for(int i=0; i<H-2; i++)
        {
            cout << '#';

            for(int j=0; j<W-2; j++)
            {
                cout << '.';
            }
           
            cout << '#';

            cout << endl;
        }

        for(int j=0; j<W; j++)
        {
            cout << '#';
        }
        cout << endl;

    cout << endl;
    cin >> H >> W;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a[114514];
int cnt1, cnt2;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		cnt1 += a[i];
		if (i % 2)cnt2 += a[i];
	}
	cout << cnt1 - cnt2 * 2 << " ";
	int b = cnt1 - cnt2 * 2;
	rep(i, n - 1) {
		if (i == n - 2)cout << a[i] * 2 - b << endl;
		else {
			cout << a[i] * 2 - b << " ";
			b = a[i] * 2 - b;
		}
	}
}

Measured memory_bytes: 2048
import heapq
N, H = map(int, input().split())
buki = []
for i in range(N):
  a, b = map(int, input().split())
  heapq.heappush(buki, (-a, False))
  heapq.heappush(buki, (-b, True))

ans = 0
while H > 0:
  attack, once = heapq.heappop(buki)
  attack = -attack
  if once:
    # print("throw :" + str(attack), H, H-attack)
    H -= attack
    ans += 1
  else:
    n = (H+attack-1) // attack
    # print("slash :" + str(attack) + "*" + str(n), H, H-attack*n)
    H -= attack * n
    ans += n

print(ans)

Measured memory_bytes: 23812
void main()
{
    long n = rdElem;
    dchar[] s = rdStr.to!(dchar[]);

    long mod = 10 ^^9 + 7;
    s.sort!"a < b";
    auto g = s.group.array;
    long result = 1;
    foreach (x; g)
    {
        result = result * (x[1].to!long + 1) % mod;
    }

    writeln(result - 1);
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int N; cin >> N;
    vector<int> lis;
    for (int i = 1;i <= N;i++){
        lis.push_back(i);
    }

    int P[10];
    int Q[10];

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

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

    int cnt = 0;
    int a,b;
    do{
        for (int i = 0;i < N;i++){
            if(lis[i] != P[i]) break;
            if(i == N-1) a = cnt;
        }
        for (int i = 0;i < N;i++){
            if(lis[i] != Q[i]) break;
            if(i == N-1) b = cnt;
        }
        cnt++;
    }while(next_permutation(lis.begin(),lis.end()));

    cout << abs(a-b) << endl;

    return 0;

}

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

int main()
{
  int n,k;
  cin>>n>>k;
  int h[n];
  long int x[n];
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
  
  x[0]=0;
  x[1]=abs(h[1]-h[0]);
  
  for(int i=2;i<n;i++)
  {
    int j= max(i-k,0);
    x[i]=x[i-1]+abs(h[i]-h[i-1]);
    for(;j<i-1;j++)
      x[i]=min(x[i],x[j]+abs(h[i]-h[j]));
    
  }
  cout<<x[n-1];
  
  return 0; 
}


Measured memory_bytes: 1408
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")


using namespace std;

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

const int N = 5000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, fac[N], a[N], sz[N], COM[N], dp[N], k, com, mark[N];
vi G[N];

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

void DFS(int v, int c){
	mark[v] = 1;
	COM[v] = c;
	sz[c]++;
	for (auto u:G[v]){
		if (mark[u] == 0) DFS(u, c);
	}
}

int POW(int x, int y){
	int res = 1;
	while (y){
		if (y & 1) res = mul(res, x);
		y >>= 1;
		x = mul(x, x);
	}
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		if (a[i] == -1) k++;
		else G[a[i]].pb(i), G[i].pb(a[i]);
	}
	for (int i = 1; i <= n; i++){
		if (!mark[i]) DFS(i, ++com);
	}
	dp[0] = 1;
	ll ans = mul(POW(n - 1, k), (n - (com - k)));
//	cout << POW(n - 1, k) << '\n';
//	cout << com << ' ' << k << '\n';
//	cout << ans << '\n';
	for (int i = 1; i <= n; i++){
		if (a[i] != -1) continue;
		ll res = 0;
		for (int j = 1; j < min(k, i); j++){
			res += mul(POW(n - 1, k - j - 1), mul(mul(dp[j], fac[j]), sz[COM[i]]));
			res %= MOD;
		}
//		cout << res << '\n';
		res += mul(POW(n - 1, k - 1), sz[COM[i]] - 1);
//		cout << res << '\n';
		res %= MOD;
		ans -= res;
		ans %= MOD;
		ans += MOD;
		ans %= MOD;
		for (int j = i; j >= 1; j--){
			dp[j] += mul(dp[j - 1], sz[COM[i]]);
			dp[j] %= MOD;
		}
	}
	cout << ans;








	return 0;
}


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

int n,m;
vector<vector<int>> dat(1000000);
vector<int> ans(1000000);

int main(){
    cin>>n>>m;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        dat[a].push_back(b);
        dat[b].push_back(a);
    }
    cout<<"Yes"<<endl;
    queue<int> que;
    que.push(1);
    while(que.size()){
        int q=que.front();que.pop();
        for(int p:dat[q]){
            if(ans[p]!=0) continue;
            ans[p]=q;
            que.push(p);
        }
    }
    for(int i=2;i<=n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 34856
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> seat(17, -1);
    multimap<int, int> leave;

    vector<int> waitTime(100);
    int time = 0;
    for(int i=0; i<100; ++i){
        while(leave.size() > 0 && leave.begin()->first <= 5*i){
            replace(seat.begin(), seat.end(), leave.begin()->second, -1);
            leave.erase(leave.begin());
        }

        time = max(time, 5*i);
        int num = (i%5==1? 5:2);
        vector<int> tmp(num, -1);
        for(;;){
            int j = search(seat.begin(), seat.end(), tmp.begin(), tmp.end()) - seat.begin();
            if(j == 17){
                time = leave.begin()->first;
                while(leave.size() > 0 && leave.begin()->first == time){
                    replace(seat.begin(), seat.end(), leave.begin()->second, -1);
                    leave.erase(leave.begin());
                }
            }else{
                for(int k=0; k<num; ++k)
                    seat[j+k] = i;
                break;
            }
        }

        waitTime[i] = time - 5*i;
        leave.insert(make_pair(time + 17*(i%2) + 3*(i%3) + 19, i));
    }

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;
        cout << waitTime[n] << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;
const int MAXN = 2005, N = MAXN;
const int mod = 1e9 + 7, inv2 = (mod + 1) / 2;
int dp[MAXN][3][MAXN], odp[3][MAXN], sz[MAXN];
vector<int> adj[N];
void sadd(int &x, int y) {
	x += y;
	while (x >= mod) x -= mod;
}
void dfs(int v, int p = -1) {
	dp[v][0][1] = 1;
	sz[v] = 1;
	for (int u : adj[v]) {
		if (u != p) {
			dfs(u, v);
			memcpy(odp, dp[v], sizeof dp[v]);
			memset(dp[v], 0, sizeof dp[v]);
			for (int dv = 0; dv <= 2; ++dv) {
				for (int du = 0; du <= 2; ++du) {
					for (int use = 0; use <= 1; ++use) {
						if (use == 1 && (du > 1 || dv > 1)) continue;
						for (int cv = 1; cv <= sz[v]; ++cv)
							for (int cu = 1; cu <= sz[u]; ++cu) {
								int ways = (use == 1 ? mod - 1 : 1);
								if (use) {
									if (du == 0 && dv == 0) 
										ways = (long long) ways * 2 % mod;
									if (du == 1 && dv == 1)
										ways = (long long) ways * inv2 % mod;
								}
								sadd(dp[v][dv + use][cv + cu - use], 
										odp[dv][cv] * (long long) dp[u][du][cu] % mod * ways % mod);
							}

					}
				}
			}
			sz[v] += sz[u];
		}
	}
	
}
int f[N];
int main(){
	f[0] =1 ;
	for (int j = 1; j < N; ++j) f[j] = (long long) f[j - 1] * j % mod;
	int n;
	cin >> n;
	for (int j = 1; j < n; ++j) {
		int p;
		cin >> p;
		adj[--p].push_back(j);
	}
	dfs(0);
	int res = 0;
	for (int j = 0; j < N; ++j)

		for (int d = 0; d <= 2; ++d) if (dp[0][d][j]) {
			sadd(res, dp[0][d][j] * (long long) f[j] % mod);
		//	cout << " hi " << d << ' ' << j << ' ' << dp[0][d][j] << endl;
		}
	cout << res << endl;
	
}



Measured memory_bytes: 47744
S=input()
K=int(input())
N=len(S)
count=1
countlist=[]
anssub=0
for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1
if S[N-2]!=S[N-1]:
  count=1
countlist+=[count]  
for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2
a=countlist[0]+countlist[-1]
if S[0]==S[-1]:
  anssub2=a//2
else:
  anssub2=0
  if countlist[0]!=1:
    anssub2+=countlist[0]//2
  if countlist[-1]!=1:
    anssub2+=countlist[-1]//2
  
b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,m; cin>>n;
	vl a(n);
	rep(i,0,n)cin>>a[i];
	sort(all(a));
	ll ans=0;
	rep(i,0,n){
		rep(j,i,n){
			if(i==j)continue;
			ll k=a[i]+a[j];
			//cout<<"i:"<<a[i]<<" j:"<<a[j];
			ll l=upper_bound(all(a),k-1)-a.begin();
			ll m=l-j-1;
			//cout<<"m:"<<l-j-1<<endl;
			if(m>=0)ans+=m;
		}
	}
	cout<<ans<<endl;
			
			
			
	
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double eps=1e-9;
double ABS(double a){return max(a,-a);}
int main(){
	double d;
	while(scanf("%lf",&d),ABS(d)>eps){
		double px,py,vx,vy;
		scanf("%lf%lf%lf%lf",&px,&py,&vx,&vy);
		if(ABS(px*vy-vx*py)>eps){
			printf("impossible\n");continue;
		}
		if(px*vx+py*vy<0){
			double r=sqrt(px*px+py*py);
			if(r>d)printf("impossible\n");
			else printf("%.12f\n",r);
		}else{
			double r=2.0-sqrt(px*px+py*py);
			if(r>d)printf("impossible\n");
			else printf("%.12f\n",r);
		}
	}
}

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


ll ans=0;
void dfs(int i,string num,ll N,vector<bool> used)
{
	if(num.size()>=10||(ll)atoi((num.c_str()))>N) return;
	//cout<<(ll)atoi((num.c_str()))<<endl;
	if(used[3]&&used[5]&&used[7]) ans++;
	int use_num[3]={3,5,7};
	for(int x : use_num)
	{
		bool prev=true;
		if(!used[x]) prev=false;
		used[x]=true;
		if(num.size()<=i) num+=(char)(x+'0');
		else num[i]=(char)(x+'0');
		dfs(i+1,num,N,used);
		used[x]=prev;
	}
}
int main()
{
	ll N;
	cin>>N;
	vector<bool> used(10,false);
	dfs(0,"",N,used);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3592
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

// ref: https://github.com/hatoo/competitive-rust-snippets/blob/master/src/binary_search.rs
#[allow(dead_code)]
pub trait BinarySearch<T> {
    /// the first element which does not compare less than val
    fn lower_bound(&self, x: &T) -> usize;
    /// the first element which compares grater than val
    fn upper_bound(&self, x: &T) -> usize;
}

#[allow(dead_code)]
impl <T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut ng = -1;
        let mut ok = self.len() as i32;
        while ok - ng > 1 {
            let mid = (ng + ok) / 2;
            if self[mid as usize] >= *x {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok as usize
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut ng = -1;
        let mut ok = self.len() as i32;
        while ok - ng > 1 {
            let mid = (ng + ok) / 2;
            if self[mid as usize] > *x {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok as usize
    }
}

fn main() {
    input! {
        n: usize,
        a_: [i32; n],
        b: [i32; n],
        c_: [i32; n],
    }
    let mut a = a_.clone();
    a.sort();
    let mut c = c_.clone();
    c.sort();

    let mut ret = 0;
    for i in 0..b.len() {
        ret += a.lower_bound(&b[i]) * (n - c.upper_bound(&b[i]));
    }

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


Measured memory_bytes: 4264
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;
typedef pair<double, double> P;

double Helon(P a, P b, P c)
{
	double square = 0;
	double x, y, z;
	x = sqrt((b.first - a.first) * (b.first - a.first) + (b.second - a.second) * (b.second - a.second));
	y = sqrt((c.first - a.first) * (c.first - a.first) + (c.second - a.second) * (c.second - a.second));
	z = sqrt((c.first - b.first) * (c.first - b.first) + (c.second - b.second) * (c.second - b.second));
	double s = (x + y + z) / 2;
	square = sqrt(s * (s - x) * (s - y) * (s - z));
	return(square);
}

void solve()
{
	vector<P> Vec;
	P p;
	while(~scanf("%lf,%lf", &p.first, &p.second))
	{
		Vec.push_back(p);
	}
	double square = 0;
	int size = Vec.size();
	for(int i = 1; i < size - 1; ++i)
	{
		square += Helon(Vec[0], Vec[i], Vec[i + 1]);
	}
	printf("%.6f\n", square);
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
// inputに入力データ全体が入る
function Main(input) {
    var N = input[0]-0;
    var list = ["a","b","c","d","e","f","g","h","i","j", "k"];
    var ans = {0:[], 1:["a"]};
    for(var i=2;i<=N;i++){
        ans[i] = [];
        var preAns = ans[i-1];
        var nowAns = ans[i];
        preAns.forEach(preans=>{
            var max = "a";
            preans.split("").forEach(v=>{
                max = max<v?v:max;
            });
            var endflg = false;
            for(var i=0;i<list.length-1;i++){
                nowAns.push(preans + list[i]);
                
                if(endflg) break;
                if(max == list[i])endflg=true;
            }
        });
        
    }
    console.log(ans[N].join("\n"));
}



Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));



Measured memory_bytes: 35900
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	string A,B,C;
	string result="NO";
	cin >> A;
    cin >> B;
    cin >> C;
    if(A.back()==B.front() && B.back()==C.front()) result="YES";
    
	cout << result << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  int cnt = 0;
  rep(i, n){
    int sum = c;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    rep(i, m){
      sum += a[i] * b[i];
    }
    if(sum > 0) cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
use strict;
use warnings;

my $i = <>;
my ($a, $b) = split(/\s/, $i);

if ($a != $b) {
    my $result = ($a + $b) / 2;
    if ($result =~ /^[0-9]+$/) {
        print $result;
    } else {
        print "IMPOSSIBLE";
    }
} else {
    print "IMPOSSIBLE";
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

bool eval_formula(string &formula,int &i){
    if(formula[i]=='T'){
        ++i;
        return true;
    }
    if(formula[i]=='F'){
        ++i;
        return false;
    }
    if(formula[i]=='-'){
        ++i;
        return !eval_formula(formula,i);
    }
    if(formula[i]=='('){
        ++i;
        bool left=eval_formula(formula,i);
        
        string op;
        switch(formula[i]){
            case '*':
            op='*';
            ++i;
            break;
            
            case '+':
            op='+';
            ++i;
            break;
            
            case '-':
            op="->";
            ++i;
            ++i;
            break;

            default:
            assert(false);
            break;
        }
        
        bool right=eval_formula(formula,i);
        assert(formula[i]==')');
        ++i;
        
        bool res;
        if(op=="*") res=left and right;
        if(op=="+") res=left or right;
        if(op=="->") res=!left or right;
        return res;
    }
    print(formula);
    print(i);
    assert(false);
}

pair<string,string> pair_formula(string& equation){
    string formula1,formula2;
    rep(i,0,equation.size()) if(equation[i]=='='){
        formula1=equation.substr(0,i);
        formula2=equation.substr(i+1);
        break;
    }
    return make_pair(formula1,formula2);
}

void solve(string equation){
    map<char,vector<int>> vals;
    rep(i,0,equation.size()) if('a'<= equation[i] and equation[i]<='z') vals[equation[i]].push_back(i);
    
    if(vals.empty()){
        auto pf=pair_formula(equation);
        int i1=0,i2=0;
        if(eval_formula(pf.first,i1)==eval_formula(pf.second,i2)) cout << "YES" << endl;
        else cout << "NO" << endl;
        return;
    }

    bool equal=true;
    rep(assign,0,1<<vals.size()){
        int i=0;
        for(auto &p:vals){
            for(int j:p.second){
                if(1&(assign>>i)) equation[j]='T';
                else equation[j]='F';
            }
            ++i;
        }
        auto pf=pair_formula(equation);
        int i1=0,i2=0;
        if(eval_formula(pf.first,i1)!=eval_formula(pf.second,i2)){
            equal=false;
            break;
        }
    }

    if(equal) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    for(;;){
        string equation;
        cin >> equation;
        if(equation=="#") break;
        solve(equation);
    }
    return 0;
}

Measured memory_bytes: 3260
A = [str(x) for x in input()]
B = [str(x) for x in input()]
C = [str(x) for x in input()]
t = 0
c = ""
while True:
    if t == 0:
        if len(A) == 0:
            print("A")
            exit(0)
        else:
            c = A.pop(0)
    elif t == 1:
        if len(B) == 0:
            print("B")
            exit(0)
        else:
            c = B.pop(0)
    else:
        if len(C) == 0:
            print("C")
            exit(0)
        else:
            c = C.pop(0)

    if c == "a":
        t = 0
    elif c == "b":
        t = 1
    else:
        t = 2


Measured memory_bytes: 3064
N = int(input())

ans = [0]*(N+1)
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      n = pow(x,2) + pow(y,2) + pow(z,2) + x*y + y*z + z*x
      if n <= N:
        ans[n] += 1
        
for i in range(1,N+1):
  print(ans[i])


Measured memory_bytes: 9092
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 10;

int dp[N][10];

int main() {
	fast_cin();
	string s; cin >> s;
	int n = s.length();
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= 3; ++j) {
			if (dp[i][j] < 0) {
				continue;
			}
			for (int k = 1; k <= 3 and i + k <= n; ++k) {
				if (s.substr(i - j, j) != s.substr(i, k)) {
					dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
				}
			}
		}
	}
	int ans = max(dp[n][1], max(dp[n][2], dp[n][3]));
	cout << ans << '\n';
}

Measured memory_bytes: 8340
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int n,m;
vector<pair<int,int> > edge[444];
int dp[444];
int solve(int i){
  if(!i) return 0;
  if(dp[i]) return dp[i];
  int ret = 0;
  for(int j = 0; j < (int)edge[i].size(); j++){
    ret = max(ret,solve(edge[i][j].first)+edge[i][j].second);
  }
  return dp[i] = ret;
}
int main(void){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a,b,c;
    cin >> a >> b >> c;
    edge[b].push_back(make_pair(a,c));
  }
  cout << solve(n-1) << endl;
}

Measured memory_bytes: 1216
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)

for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split())

from functools import lru_cache
@lru_cache(None)
def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    if t <= ss:
        return dfs(eki+1, ss+cc)
    else:
        m = -(-t//ff)
        return dfs(eki+1, ff*m+cc)

for i in range(n):
    print(dfs(i,0))


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

using namespace std;

const int N = 1005;
int n;
pair<long long, long long> arr[N];

bool check(long long h){
    long long curl = h * arr[n].first, curr = h * arr[n].second;
    for(int i = n - 1; i >= 1; i--){

        bool found1 = false, found2 = false;
        long long k = min(curl / arr[i].first, curr / arr[i].second);
        if(k == 0){
            return false;
        } else {
            long long newl = k * arr[i].first;
            long long newr = k * arr[i].second;
            if(newl <= curl && newr <= curr){
                curl = newl;
                curr = newr;
            }
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        arr[i] = {a, b};
    }
    long long g = arr[n].first + arr[n].second;
    long long l = 1, r = 1000000000000000000 / g, ans = -1;
    while(l <= r){
        long long mid = l + (r - l) / 2;
        if(check(mid)){
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    cout << g * ans << '\n';
    return 0;
}

Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define PI					acos(-1.0)
#define vi					vector<int>
#define vii					vector<vi>
#define vll					vector<ll>
#define mid(s,e)			(s+(e-s)/2)
#define clz(n)				__builtin_clzll(n))

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template<typename T>
void printVec(const T &v, char sep=' ') {for (auto &i: v) cout << i << sep;}
template<typename T>
void printVecPair(const T &v, char sep=' ') {for (auto &i: v) cout << i.first <<" " << i.second<< sep;}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	string s;
	cin>>s;
	int n = s.size();
	vi ans(n,0);
	for(int i=0;i<n;i++) {
			int cntR = 0;
			while(s[i] != 'L') {
					cntR++;
					i++;
			}
			int R = i-1;
			int L = i;
			int cntL=0;
			while(s[i] == 'L') {
					cntL++;
					i++;
			}
			cntR--;
			ans[R] =  cntR/2 + (cntL/2 + 1);
			ans[L] =  cntR - cntR/2 + cntL - cntL/2;
			i--;
			
	}
	for(int i=0;i<n;i++) {
			cout<<ans[i]<<" ";
	}
}





Measured memory_bytes: 1104
from fractions import*
n,*a=map(int,open(0).read().split())
*b,=a=a+[0]
r=range(n)
for i in r:a[i]=gcd(a[i],a[i-1]);b[n-i-1]=gcd(b[n-i-1],b[n-i])
print(max(gcd(a[i-1],b[i+1])for i in r))

Measured memory_bytes: 16120
#include <bits/stdc++.h>
using namespace std;
#define LL   long long
#define LIM  100000
#define SZ   100

LL n, value, capacity, dp[SZ+5][LIM+5], weight[SZ+5], val[SZ+5];
bool vis[SZ+5][LIM+5];


LL f(LL in, LL cur){
    if(cur <= 0) return 0;
    if(in > n) return INT_MAX/2;

    if(vis[in][cur]) return dp[in][cur];
    vis[in][cur] = 1;
    LL take = INT_MAX/2, notTake;
    if(cur-val[in] >= 0) take = weight[in] + f(in+1, cur-val[in]);
    notTake = f(in+1, cur);
    return dp[in][cur] = min(take, notTake);
}

int main(){
    cin>>n>>capacity;
    for(int i = 1; i <= n; i++){
        cin>>weight[i]>>val[i];
        value += val[i];
    }
    LL res = 0;
    for(LL i = 1; i <= value; i++){
        LL curWeight = f(1, i);
        if(curWeight <= capacity) res = max(res, i);
    }
    cout<<res<<'\n';
}





Measured memory_bytes: 91352
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;

int a[200010];
ll sum;

int main(){
    //这题没做出来
    //这是别人的代码，贪心法的实现
    //最大的数可以收益1次，而剩下的都可以两次，分别是两边
    //可以使用1-8的数试一下，可以发现很简单，比赛时没有仔细思考
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    // if(n>1)
    // {
    //     sum+=a[n-1];
    // }
    // int k=n-2;
    // n=n-2;
    // while(n>=2)
    // {
    //     sum=sum+2*a[k--];
    //     // printf("+ 2*%d",a[k+1]);
    //     n=n-2;

    // }
    // if(n==1)
    // {
    //     sum+=a[k];
    // }
    // printf("\n%d",sum);
    // return 0;


    //官方题解就是排序，然后加
    //瓶颈为排序算法，O(nlogn)
    for(int i = 1;i<n;i++){
        sum+=a[n-1-i/2];
    }
    printf("%lld",sum);

    //官方提到了更加快捷的方法
    //Median of medians,可以到O(n)的复杂度
    // TODO

}

Measured memory_bytes: 2472
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2);
}

void solve()
{
	int n , k;
	
	cin >> n >> k;
	
	cout << min(n % k, k - n%k);
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3624
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const N = nextInt()
    const a = nextIntArray()
    function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}
    let ans = a[0]
    for(let i = 1; i<a.length; i++){
        ans = gcd(ans, a[i])
    }
    console.log(ans)
}
Main()


Measured memory_bytes: 40340
temp = list(map(int, input().split()))
X = temp[0]
Y = temp[1]

ans = 0

if(X==1):
  ans += 300000
if(Y==1):
  ans += 300000
if(X==2):
  ans += 200000
if(Y==2):
  ans += 200000
if(X==3):
  ans += 100000
if(Y==3):
  ans += 100000
if(X==1 and Y==1):
  ans += 400000
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

vector<vector<ll>> g(55);
ll n, m;
map<pair<ll, ll>, ll> mp;

ll dfs(ll a, ll b, ll p = -1) {
    ll res = 0;
    for (auto u : g[a])
        if (u != p) {
            if (u == b) {
                res = 1LL << (mp[{a, b}] - 1);
                return res;
            }
            res = dfs(u, b, a);
            if (res) {
                res |= 1LL << (mp[{a, u}] - 1);
                break;
            }
        }
    return res;
}

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

    cin >> n;
    rep(i, 1, n) {
        ll a, b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        mp[{a, b}] = mp[{b, a}] = i;
    }
    cin >> m;
    vector<ll> y(m);
    rep(i, 0, m) {
        ll u, v;
        cin >> u >> v;
        y[i] = dfs(u, v);
    }
    ll ans = 1LL << (n - 1);
    for (ll b = 1; b < (1LL << m); b++) {
        ll d = 0;
        ll c = 1;
        rep(i, 0, m) if ((b >> i) & 1LL) {
            c *= -1;
            d |= y[i];
        }
        ll q = 0;
        rep(i, 0, n) if ((d >> i) & 1LL) {
            q++;
        }
        ans += c * (1LL << (n - 1 - q));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# AOJ 1608: Selection of Participants of an Experime...
# Python3 2018.7.13 bal4u

while True:
	n = int(input())
	if n == 0: break
	a = list(map(int, input().split()))
	a.sort()
	ans = a[1]-a[0]
	for i in range(2, n):
		if a[i]-a[i-1] < ans: ans = a[i]-a[i-1];
	print(ans)



Measured memory_bytes: 5628
#include<stdio.h>

int main(void){
    int w,h,x,y,r;

    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);

    if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}


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

using namespace std;
typedef long long ll;
const int maxn = 1005;

int main()
{
    int n,k;
    string s;
    while(cin>>n>>k>>s){
        int ans = 0;
        int head = 0, tail = 0;
        int k2 = k;
        while(head < n){
            while(head < n && s[head] == '1') head++;
            ans = max(ans , head - tail);
            while(head < n && s[head] == '0') head++;
            k2--;
            if(k2 < 0){
                while(tail < n && s[tail] == '1')
                    tail++;
                while(tail < n && s[tail] == '0')
                    tail++;
            }
            ans = max(ans, head - tail);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s;cin>>s;
  
  if (s=="Sunny"){
	  cout<<"Cloudy"<<endl;
	  return 0;
  }
  if (s=="Cloudy"){
	  cout<<"Rainy"<<endl;
	  return 0;
  }
  if (s=="Rainy"){
	  cout<<"Sunny"<<endl;
	  return 0;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    int cnt = 0;
    REP(i,0,n/4+1) {
        if ((n - i * 4) % 7 == 0) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[1005];
const int DR[4] = {0, 1, 0, -1};
const int DC[4] = {1, 0, -1, 0};
int sp[1005][1005];
int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	memset(sp, -1, sizeof(sp));
	queue<pair<int, int>> Q;
	for (int i = 0; i < h; ++i) {
		scanf("%s", str);
		for (int j = 0; j < w; ++j) {
			if (str[j] == '#') {
				sp[i][j] = 0;
				Q.push({i, j});
			}
		}
	}
	int ans = 0;
	while (!Q.empty()) {
		auto x = Q.front();
		Q.pop();
		ans = sp[x.first][x.second];
		for (int d = 0; d < 4; ++d) {
			int nr = x.first + DR[d];
			int nc = x.second + DC[d];
			if (nr < 0 || nc < 0 || nr >= h || nc >= w) continue;
			if (sp[nr][nc] != -1) continue;
			sp[nr][nc] = sp[x.first][x.second] + 1;
			Q.push({nr, nc});
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 15192
#include <stdio.h>

int main(void)
{
	int candy;
	int n;
	
	while (scanf("%d", &candy) != EOF){
		
		n = candy % 39;
		
		if (n == 0){
			printf("3C39\n");
		}
		else {
			printf("3C%02d\n", n);
		}
	}
	return (0);
}

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

int max = 0;
int r, c;

int retu(int data[11][10001]){
	int res = 0;

	for (int i = 0; i < c; i++){
		int cnt = 0;
		for (int j = 0; j < r; j++){
			if (data[j][i] == 0)cnt++;
		}
		if (cnt >= r / 2)continue;
		else{
			for (int j = 0; j < r; j++)data[j][i] = std::abs(data[j][i] - 1);
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			if (data[i][j] == 0)res++;
		}
	}

	return res;
}

void gyo(int data[11][10001], int k, bool flg){

	if (k == r)return;

	if (flg){
		for (int i = 0; i < c; i++)data[k][i] = std::abs(data[k][i] - 1);
	}

	max = std::max(max, retu(data));

	gyo(data, k + 1, true);
	gyo(data, k + 1, false);

	return;
}

int main(){

	while (std::cin >> r >> c, r, c){

		int data[11][10001];
		max = 0;

		for (int i = 0; i < r; i++){
			for (int j = 0; j < c; j++){
				std::cin >> data[i][j];
			}
		}

		gyo(data, 0, true);
		gyo(data, 0, false);

		std::cout << max << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1556