akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

int main(){
    int n,c;
    cin >> n >> c;
    ve<ve<int>> d(c,ve<int>(c));
    
    ve<ve<int>> x(3,ve<int>(c,0));
    rep(i,c)rep(j,c) cin >> d[i][j];
    rep(i,n)rep(j,n){
        int a;
        cin >> a;
        a--;
        x[(i+j)%3][a]++;
    }
    int ans = 2e9;
    rep(i,c)rep(j,c)rep(k,c){
        if(i==j||j==k||k==i)continue;
        int memo = 0;
        rep(a,c)memo += x[0][a]* d[a][i];
        rep(a,c)memo += x[1][a]* d[a][j];
        rep(a,c)memo += x[2][a]* d[a][k];
        chmin(ans,memo);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    int count = 0;
    for (int i = 1; i < N; i++)
    {
        int dh = H[i - 1] - H[i];
        if (dh >= 0)
        {
            count += dh;
        }
        else
        {
            count = 0;
        }
        if (count >= 2)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(a+b==4){cout<<2;return 0;}
    if(a+b==3){cout<<3;return 0;}
    if(a+b==5){cout<<1;return 0;}
}

Measured memory_bytes: 256
n,m=map(int, input().split())

if m == 0:
    if n == 1: print("0")
    if n == 2: print("10")
    if n == 3: print("100")
    exit()

c=[[],[],[]]
for i in range(int(m)):
    s1,c1=map(int, input().split())
    c[s1-1].append(c1)

tmp1 = 0
tmp10 = 0
tmp100 = 0

if len(set(c[0])) > 1:
    print("-1")
    exit()
elif len(set(c[0])) == 1:
    tmp100 = c[0][0]
else :
    tmp100 = 1

if len(set(c[1])) > 1:
    print("-1")
    exit()
elif len(set(c[1])) == 1:
    tmp10 = c[1][0]
else :
    tmp10 = 0

if len(set(c[2])) > 1:
    print("-1")
    exit()
elif len(set(c[2])) == 1:
    tmp1 = c[2][0]
else :
    tmp1 = 0

if n != 1 and tmp100==0:
    print("-1")
    exit()

if n==1:
    print(tmp100)
if n==2:
    print(tmp10*1+tmp100*10)
if n==3:
    print(tmp1+tmp10*10+tmp100*100)



Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))

H.append(H[-1])
H.append(H[-1])

#print(H)

for n in range(N):
    if H[n+1] > H[n]:
        H[n+1] -= 1
    #print(H)
    
for n in range(N):
    if H[n+1] < H[n]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    ll ans=0;
    cin >> N;
    if(N%2!=0){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll re=10;
        while(re<=N){
            ans+=N/re;
            re*=5;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
n = int(input())

l = [0] * 10001

for i in range(1, 101):
	for j in range(1, 101):
		for k in range(1, 101):
			x = i**2 + j**2 + k**2 + i*j + j*k + i*k
			if x <= 10000:
				l[x] += 1

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

Measured memory_bytes: 9192
def C(N, S):
    cand = "#" * N
    n_diff_chars = sum(a!=b for a, b in zip(cand, S))
    min_n_diff_chars = n_diff_chars
    for c in S:
        if c == ".":
            n_diff_chars -= 1
        else:
            n_diff_chars += 1
        min_n_diff_chars = min(min_n_diff_chars, n_diff_chars)
    print(min_n_diff_chars)


if __name__ == "__main__":
    N = int(input())
    S = input()
    C(N, S)

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

int main()
{
  int x, i=1;
  
  while(1)
    {
      cin >> x;
      
      if(x == 0)
	break;
      
      cout << "Case " << i << ": " << x << endl;
      i += 1;
    }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
bool check(string S) {
	if (S.size() % 2 == 1)return false;
	if (S.substr(0, S.size() / 2) == S.substr(S.size() / 2, S.size() / 2))return true;
	return false;
}
int main() {
	string S; cin >> S;
	for (int i = S.size() - 1; i >= 1; i--) {
		if (check(S.substr(0, i)) == true) { cout << i << endl; break; }
	}
	return 0;
}

Measured memory_bytes: 256
DIV = 1_000_000_007
n = gets.to_i
l = n.times.map{ gets.chomp }
l.delete('-')
s = l.size
u = l.count('U')
dp = (s+1).times.map{ [0]*(s+1) }
dp[0][0] = 1
case_u = 1
case_d = 0
for i in (0...s)
  case_d += 1 if l[i] == 'U'
  for j in (0..i+1)
    dp[i+1][j] = dp[i][j-1]*(case_u - j) if j > 0 
    dp[i+1][j] += dp[i][j]*(case_d - j) if j < i+1
    dp[i+1][j] %= DIV
  end
  case_u += 1 if l[i] == 'U'
end
p dp[s][u]

Measured memory_bytes: 9004
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, K;
vi V;

int main() {
    cin >> N >> K;
    V.resize(N);
    rep(i, N) cin >> V[i];

    int ans = 0;
    vi buf(min(N, K));
    for (int a = min(N, K); a >= 0; --a) {
        for (int b = min(N, K) - a; b >= 0; --b) {
            auto a_end = copy(V.begin(), V.begin() + a, buf.begin());
            auto b_end = copy(V.begin() + N - b, V.end(), a_end);

            sort(buf.begin(), b_end, greater<int>());
            int sum = 0;
            int bufSize = a + b;
            for (int i = 0; i < min(2 * bufSize - K, bufSize); ++i) sum += buf[i];
            for (int i = max(0, min(2 * bufSize - K, bufSize)); i < bufSize; ++i) if (buf[i] > 0) sum += buf[i];
            ans = max(ans, sum);
        }
    }
    write(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int K = scan.nextInt();

		int sum = 0;

		if(A > K){
			sum += K;
		}else if(A+B >= K){
			sum += A;
		}else{
			K -= A+B;
			sum += (A - K);
		}

		System.out.println(sum);

		scan.close();
	}
}

Measured memory_bytes: 35788
#include <bits/stdc++.h> 
using namespace std;
const int mxn = 17 , N = 5e5 + 5 , mod = 1e9 + 7;
long long grid[mxn][mxn];
long long value[1<<17];
int arr[mxn];
long long calc(int idx){
	long long ret = 0; 
	for(int i = 0; i < idx ; i++){
		for(int j = i + 1 ; j < idx ; j++){
			ret += grid[arr[i]][arr[j]];
		}
	}
	return ret;
}
long long dp[1<<mxn];
bitset<(1<<mxn)>vis;
long long solve(long long mask){
	if(vis[mask])return dp[mask];
	vis[mask] = true;
	long long ret = value[mask] ;
	for(int i = mask ; i ; i = (i - 1) & mask){
		ret = max(ret  , solve(i) + value[mask ^ i]);
	}
	return dp[mask] = ret;
}
int main(){
	int n ;
	cin>>n;
	for(int i = 0; i < n ; i++){
		for(int j = 0; j < n ; j++){
			cin>>grid[i][j];
		}
	}
	for(int i=  0; i < (1<<16) ; i++){
		int pl = 0;
		for(int j = 0; j < n ;j++){
			if(i & (1 << j))
				arr[pl++] = j;
		}
		value[i] = calc(pl);
	}
	cout<<solve((1<<n) - 1)<<endl;
	return 0;
}


Measured memory_bytes: 4648
n = int(input())
h_list = list(map(int,input().split()))
dp = [10**9]*n
dp[0] = 0
dp[1] = abs(h_list[0]-h_list[1])
for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h_list[i-1]-h_list[i]), dp[i-2]+abs(h_list[i-2]-h_list[i]))
print(dp[-1])

Measured memory_bytes: 13924
s = input()


def dfs(i, f):
    if i == 3:
        if eval(f) == 7:
            print(f+'=7')
            exit()
    else:
        dfs(i+1, f+'+' + s[i+1])
        dfs(i+1, f+'-' + s[i+1])


dfs(0, s[0])


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}

int main(){
    int N;
    int *A,B,*C;
    int i;
    int temp;
    int ans;

    cin >> N;
    A = new int[N];
    C = new int[N-1];
    for(i=0;i<N;i++){
        cin >> A[i];
    }
    ans = 0;
    for(i=0;i<N;i++){
        cin >> B;
        ans += B;
    }
    for(i=0;i<N-1;i++){
        cin >> C[i];
    }
    temp = A[0];
    //ans = B[temp-1];
    for(i=1;i<N;i++){
        if( temp + 1 == A[i] ){
            ans += C[temp-1];
        }
        temp = A[i];
        //ans += B[temp-1];

    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
import heapq

def main():
    X,Y,A,B,C = map(int,input().split())
    p = list(map(int,input().split()))
    q = list(map(int,input().split()))
    r = list(map(int,input().split()))
    p.sort()
    q.sort()
    r.sort()
    p = p[-X:]
    q = q[-Y:]
    r = r[-X-Y:]
    use = p+q
    heapq.heapify(use)
    heapq.heapify(r)
    while len(r)>0:
        unt = heapq.heappop(use)
        nc = heapq.heappop(r)
        if nc > unt:
            heapq.heappush(use,nc)
        else:
            heapq.heappush(use,unt)

    print(sum(use))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 21092
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


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


def INT(): return int(input())


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


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
w = LIST()

ans=INF

for i in range(n):
    lis1 = [w[j] for j in range(i)]
    lis2 = [w[j] for j in range(i,n)]
    ans = min(ans, abs(sum(lis1) - sum(lis2)))
print(ans)

Measured memory_bytes: 13708
N=int(input())
p=list(map(int,input().split()))

cnt=0
for i in range(N-1):
  if p[i]==i+1:
    p[i],p[i+1] = p[i+1],p[i]
    cnt+=1
if p[N-1]==N:
  p[N-2],p[N-1] = p[N-1],p[N-2]
  cnt+=1
  
print(cnt)


Measured memory_bytes: 14008
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
ll a[334334];
signed main() {
	ll n, cnt = 0, inf;
	string s;
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'E')cnt++;
	}
	rep(i, n) {
		if (s[i] == 'E')a[i] = a[i - 1] + 1;
		else a[i] = a[i - 1];
	}
	inf = cnt;
	rep(i, n) {
		inf = min(inf, i + 1 + cnt - 2 * a[i]);
	}
	cout << inf << endl;
	getchar(); getchar(); return 0;
}


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

ll n, m;
string s, t;

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n >> m >> s >> t;
  bool pos = (s[0]==t[0]);
  for(int i=2;i<=min(n,m);i++) {
    if (n%i==0 && m%i==0) {
      for(ll j=0;j*(n/i)<n && j*(m/i)<m;j++) {
        if (s[j*(n/i)] != t[j*(m/i)]) pos = false;
      }
    }
  }
  if (!pos) cout << -1 <<endl;
  else cout << n/__gcd(n,m)*m << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main (){
    int n,a,min,max;
    long int sum;
    scanf("%d %d",&n,&min);
    sum=max=min;
    for(int i=1;i<n;i++){
        scanf("%d",&a);
        sum+=a;
        if(a<min)min=a;
        else if(max<a)max=a;
    }
    printf("%d %d %ld\n",min,max,sum);
}



Measured memory_bytes: 2140
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD 1000000007
const int N = 1e2 + 5;
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
    ll n,k;
    cin >> n >> k;
    ll a[n+1]={0};
    for(ll i=1;i<=n;i++)    cin >> a[i];
    ll pre[n+1][k+1]={0},dp[n+1][k+1]={0};
    for(ll i=0;i<=a[1];i++)
    {
        dp[1][i] = 1;
    }
    pre[1][0] = dp[1][0];
    for(ll i=1;i<=k;i++)   pre[1][i] = (pre[1][i-1] + dp[1][i])%MOD;
    for(ll i=2;i<=n;i++)
    {
        for(ll j=0;j<=k;j++)
        {
            ll range = j-a[i];
            range = max(0LL,range);
            dp[i][j] = pre[i-1][j];
            if(range!=0)   dp[i][j] = (dp[i][j] - pre[i-1][range-1] + MOD)%MOD;
        }
        pre[i][0] = dp[i][0];
        for(ll j=1;j<=k;j++)       pre[i][j] = (pre[i][j-1] + dp[i][j])%MOD;
    }
    cout<<dp[n][k];
}

Measured memory_bytes: 156544
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int N, Q;

struct SegmentTree {
    int n;
    vector< set<int> > node;

    SegmentTree(string S) {
        int sz = N;
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1);

        for (int ii = 0; ii < sz; ++ii){
            int tmp = S[ii] - 'a';
            node[ii+n-1].insert(tmp);
        }
        for (int ii = n-2; ii >= 0; --ii){
            std::set_union(begin(node[2*ii+1]), end(node[2*ii+1]), begin(node[2*ii+2]), end(node[2*ii+2]), inserter(node[ii], end(node[ii])));
        }
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x].clear();
        node[x].insert(val);
        while(x > 0) {
            x = (x - 1) / 2;
            node[x].clear();
            std::set_union(begin(node[2*x+1]), end(node[2*x+1]), begin(node[2*x+2]), end(node[2*x+2]), inserter(node[x], end(node[x])));
        }
    }

    set<int> get(int a, int b, int k = 0, int l = 0, int r = -1) {
        if(r < 0) r = n;
        set<int> ret;
        if(r <= a || b <= l) return ret;
        if(a <= l && r <= b) return ret = node[k];
        set<int> sl = get(a, b, 2*k+1, l, (l+r)/2);
        set<int> sr = get(a, b, 2*k+2, (l+r)/2, r);
        set_union(begin(sl), end(sl), begin(sr), end(sr), inserter(ret, end(ret)));
        return ret;
    }
};

int main() {
    string S;
	cin >> N >> S >> Q;

    SegmentTree seg(S);

	for (int ii = 0; ii < Q; ++ii){
        int com;
        cin >> com;
        if (com == 1){
            int x;
            char y;
            cin >> x >> y;
            x--;
            int tmp = y - 'a';
            seg.update(x, tmp);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            set<int> ans = seg.get(l, r);
            cout << ans.size() << "\n";
        }
	}

	return 0;
}


Measured memory_bytes: 192204
#include "bits/stdc++.h"
using namespace std;
int x[55], y[55];

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	map <pair <int, int>, int> mp;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(i != j) {
				mp[make_pair(x[i] - x[j], y[i] - y[j])] += 1;
			}
		}
	}
	int ans = 0;
	for(auto i : mp) {
		ans = max(ans, i.second);
	}
	cout << (n - ans) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9+7;

ll bd[1<<21], n, a[22][22];

ll cp(int bm, int m) {
	if (bd[bm]==-1) {
		bd[bm] = 0;
		for (int i=1; i<=n; i++) {
			if ((a[m][i])&&(bm&(1<<(i-1))))
				bd[bm] += cp(bm^(1<<(i-1)), m-1);
		}
		bd[bm] %= M;
	}
	return bd[bm];
}

int main() {
	memset(bd, -1, sizeof(bd));
	bd[0] = 0;
	cin >> n;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			cin >> a[i][j];
	for (int i=0; i<n; i++) 
		bd[1<<i] = a[1][i+1];
	cout << cp((1<<n)-1, n) << "\n";
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;

ll divisor(ll n){
    ll res=0;
    for(ll i=1;i*i<n;i++){
        if(n%i==0){
            if(n%(n/i-1))res+=(n/i)-1;
        }
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    cout<<divisor(n)<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(auto& e : h) cin >> e;
    string ans = "Yes";
    for(int i = n - 1;i >= 1;i--){
        if(h[i-1] - h[i] == 1) h[i-1]--;
        if(h[i-1] - h[i] > 1) ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    # i 番目の勇者が i 番目の街で倒せるモンスターの最大数
    ans += min(A[i],B[i])
    # i番目の勇者の余力 r
    r = max(0,B[i]-A[i])
    # i+1 番目の街のモンスターをついでに倒しておく
    d = min(A[i+1],r)
    ans += d
    A[i+1] -= d

print(ans)


Measured memory_bytes: 19228
#include <iostream>
using namespace std;
int temp[2000000];
int main()
{
	//int* temp = new int[20000000‬];
	int coin;
	/** 500硬币兑换1000点快乐值 */
	int hap_500 = 1000;
	/** 5硬币兑换5点快乐值 */
	int hap_5 = 5;
	/** 兑换500快乐值的个数 */
	int x_500;
	/** 兑换5快乐值的个数 */
	int y_5;
	/*输入cion总数*/
	cin >> coin;
	/** 定义一个500快乐值的最大值 */
	int max_x;
	max_x = coin / 500;
	int counter;
	counter=max_x + 1;
	for (int i = 0; i <= max_x; i++)
	{
		temp[i] = i * hap_500 + (coin - i * 500) / 5 * hap_5;
	}
	//找到最大值
	int temp_max = 0;
	for (int i = 0; i <= max_x; i++)
	{
		if (temp[i] >= temp_max)
		{
			temp_max = temp[i];
		}
	}
	cout << temp_max << endl;
}

Measured memory_bytes: 8064
#include<cstdio>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
int main(){
    int n,a[100000],g,m,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    m=g=a[0];
    for(int i=1;i<n;i++){
        m=max(m,a[i]);
        g=gcd(g,a[i]);
    }
    if(m>=k&&(m-k)%g==0){
        printf("POSSIBLE\n");
    }
    else{
        printf("IMPOSSIBLE\n");
    }
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int hb,mb,sb,ha,ma,sa,h[3],m[3],s[3];
	int byoub,byoua,byou;
	int i;

	for(i=0;i<3;i++){
		scanf("%d %d %d %d %d %d\n",&hb,&mb,&sb,&ha,&ma,&sa);
		byoub=hb*60*60+mb*60+sb;
		byoua=ha*60*60+ma*60+sa;
		byou=byoua-byoub;
		s[i]=byou%60;
		byou-=s[i];
		m[i]=byou%(60*60);
		byou-=m[i];
		h[i]=byou;
		m[i]/=60;
		h[i]/=60*60;
	}
	for(i=0;i<3;i++){
		printf("%d %d %d\n",h[i],m[i],s[i]);
	}
	return 0;
}

Measured memory_bytes: 1032
#include <iostream>

int main(){
	int x, y;
	while(1){
		std::cin >> x >> y;
		if(!x && !y)
			break;
		if(x > y)
			std::cout << y << ' ' << x << std::endl;
		else
			std::cout << x << ' ' << y << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io  ios_base::sync_with_stdio(false), cin.tie(NULL),cout.tie(NULL)
int mod=1e9+7;const int N=55;
int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	return (a+b)%m;}
int sub(int a,int b,int m=mod){	return (a-b+m)%m;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
bool chk(int x,int y,int n,int m)
{
    return x>=0 && x<n && y>=0 && y<m;
}
int32_t main()
{
    int n,m,x;
    cin>>n>>m>>x;
    int arr[n][m];
    int cost[n];
    for(int i=0;i<n;i++)
    {
        cin>>cost[i];
        for(int j=0;j<m;j++)
            cin>>arr[i][j];
    }
 
    int mask=(1<<n);
    int maxi=1e18;
    for(int i=0;i<mask;i++)
    {
        int tot=0;
        vector<int> brr(m,0);
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                for(int k=0;k<m;k++)
                    brr[k]+=arr[j][k];
                tot+=cost[j];
            }
            bool fg=true;
            for(int k=0;k<m;k++)
                if(brr[k]<x)
                fg=false;
            if(fg)
                maxi=min(maxi,tot);
        }
    }
    if(maxi==1e18)
        maxi=-1;
    cout<<maxi<<"\n";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
struct rcdata {
    int rr; int c;
};
vector<rcdata> m(110);
long long dp[110][110];

long long rec(int l, int r) {
    // cout << "l " << l << " r " << r << endl;
    if(dp[l][r] != 1e9) return dp[l][r];
    if(abs(l-r) <= 1) return dp[l][r] = 0;
    for(int mid = l+1; mid <= r-1; ++mid) {
        long long total = rec(l, mid)+rec(mid,r)+(m.at(l).rr*m.at(mid).rr*m.at(r-1).c);
        chmin(dp[l][r], total);
    }
    return dp[l][r];
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> m.at(i).rr >> m.at(i).c;
    }

    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= n; ++j) {
            dp[i][j] = 1e9;
        }
    }

    cout << rec(0, n) << endl;
}


Measured memory_bytes: 3168
#include<iostream>
//alds1_2_c.cpp
using namespace std;

struct Card {char suit, value;};

void bubble(struct Card A[], int N) {
	for(int i = 0; i < N; i++) {
		for(int j = N - 1; j >= i+1; j--) {
			if(A[j].value < A[j-1].value) {
				Card t = A[j]; A[j] = A[j - 1]; A[j-1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N) {
	for(int i = 0; i < N; i++) {
		int minj = i;
		for(int j = i; j < N; j++) {
			if(A[j].value < A[minj].value) minj = j;
		}
		Card t = A[i]; A[i] = A[minj]; A[minj] = t;
	}
}

void print (struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		if(i > 0) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
	for(int i = 0; i < N; i++) {
		if(C1[i].suit != C2[i].suit) return false;
	}
	return true;
}

int main() {
	Card C1[100], C2[100];
	int N;
	char ch;
	
	cin >> N;
	for (int i = 0; i < N; i++ ) {
		cin >> C1[i].suit >> C1[i].value;
	}
	
	for(int i = 0; i < N; i++) C2[i] = C1[i];
	
	bubble(C1, N);
	selection(C2, N);
	
	print(C1, N);
	cout << "Stable" << endl;
	print(C2, N);
	if(isStable(C1, C2, N)) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3084
import math
n,d = map(int,input().split())
a = [list(map(int,input().split())) for x in range(n)]
b = 0
    
for i in range(n):
    for j in range(i+1,n):
        c = 0
        for k in range(d):
            c += (a[i][k]-a[j][k])**2

        if int(math.sqrt(c))**2 == c:
            b += 1
print(b)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  for (int i = A; i <= B; ++i) {
    if (i % K == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  
  return 0;
}


Measured memory_bytes: 3640
#import<regex>
using namespace std;long h,w,a,b,c,d,D[10]={0,1,1,0,-1,1,-1,-1},t[10],i;map<long,int>m;main(){scanf("%d%d%*d",&h,&w);for(*t=(h-2)*(w-2);~scanf("%d%d",&a,&b);i=0)for(;i<9;)if((c=a+D[i])>1&(d=b+D[++i])>1&c<h&d<w)t[c=m[c*w+d]++]--,t[c+1]++;for(;i<10;)printf("%ld ",t[i++]);}

Measured memory_bytes: 56448
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int h,w;
  h=w=100;
  cout<<h<<" "<<w<<endl;
  char ma[100][100];
  for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
      if(i<50)ma[i][j]='.';
      else  ma[i][j]='#';
  for(int i=0;i/2<b-1;i+=2)ma[2*(i/100)][i%100]='#';
  for(int i=0;i/2<a-1;i+=2)ma[2*(i/100)+50][i%100]='.';
  for(int i=0;i<50;i++){
    for(int j=0;j<100;j++){
      cout<<ma[i][j];
    }
    cout<<endl;
  }
   for(int i=99;i>=50;i--){
    for(int j=0;j<100;j++){
      cout<<ma[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n=int(input())
yakusu=make_divisors(n)
yakusu=sorted(yakusu)
ngs=len(yakusu)
if len(yakusu)%2==0:
    #print(yakusu[int(ngs//2)], yakusu[int(ngs//2)-1])
    print(yakusu[int(ngs//2)]+yakusu[int(ngs//2)-1]-2)
else:
    #print(yakusu[int(ngs//2)])
    print(yakusu[int(ngs//2)]+yakusu[int(ngs//2)]-2)

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

int main(){
    int N,x,y,M,l;
    char d;
    map<char,int> D;
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    D['E']=0; D['W']=1; D['N']=2; D['S']=3;
    while(cin>>N,N){
        bool a[21][21]={};
        rep(i,N){
            cin>>x>>y;
            a[x][y]=true;
        }
        x=y=10;
        cin>>M;
        rep(i,M){
            cin>>d>>l;
            while(l--){
                if(a[x+=dx[D[d]]][y+=dy[D[d]]]){
                    a[x][y]=false;
                    N--;
                }
            }
        }
        cout<<(N?"No":"Yes")<<endl;
    }
    return 0;
}

Measured memory_bytes: 1192
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 17:27:11 2019
//
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	fmt.Println((n - 1) * (m - 1))
}


Measured memory_bytes: 512
#include <stdio.h>
#define H 14

int main(void){
	int b[H][H];
	int x, y, s;
	int w=0, h=0;
	for(int i=0; i<H; ++i){
		for(int j=0; j<H; ++j){
			b[i][j] = 0;
		}
	}

	while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
		x += 2;
		y += 2;
		switch(s){
		case 3:
			b[x][y-2]++;
			b[x-2][y]++;
			b[x+2][y]++;
			b[x][y+2]++;
		case 2:
			b[x-1][y-1]++;
			b[x+1][y-1]++;
			b[x-1][y+1]++;
			b[x+1][y+1]++;
		case 1:
			b[x][y-1]++;
			b[x-1][y]++;
			b[x][y]++;
			b[x+1][y]++;
			b[x][y+1]++;
			break;
		}
	}

	for(int i=2; i< H-2; ++i){
		for(int j=2; j<H-2; ++j){
			if(b[i][j] == 0){
				w++;
			}else if(h < b[i][j]){
				h = b[i][j];
			}
		}
	}
	printf("%d\n%d\n", w, h);

	return 0;
}

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

int main(){
  int N;  cin >> N;
  vector<long long>A(N);
  long long ans = 1;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    if(A.at(i) == 0){
      cout << '0' << endl;
      return 0;
    }
    ans *= A.at(i);
  }
  long long n = ans;
  for(int i=0;i<N;i++){
    n /= A.at(i);
  }
  if(n != 1 || ans > 1000000000000000000) cout << "-1" << endl;
  else  cout << ans << endl;
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int B[100];
  for (int i = 0; i < M; i++) cin >> B[i];
  int A[100][100];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x = C;
    for (int j = 0; j < M; j++) {
      x += A[i][j] * B[j];
    }
    if (x > 0) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

struct Elem {
    int l, r, id;
    Elem () {}
    Elem (int a, int b, int i) : l(a), r(b), id(i) {}
};

vector<int> occD, occC;
signed main() {
    int N; cin >> N;
    string s; cin >> s;
    N = s.length();
    for(int i=0; i<N; i++) {
        if(s[i] == 'D') occD.push_back(i);
        if(s[i] == 'C') occC.push_back(i);
    }

    int Q; cin >> Q;
    while(Q--) {
        int K; cin >> K;
        vector<Elem> info;
        int idx = 0, jdx = 0;
        for(auto x : occC) {
            while(idx < occD.size() and occD[idx] <= x-K) idx++;
            while(jdx < occD.size() and occD[jdx] <= x  ) jdx++;
            info.push_back(Elem(idx, jdx, x));
        }
        
        int ans = 0;
        int sub = 0;
        vector<int> imos(N+1);
        for(auto x : info) {
            imos[x.l]++;
            imos[x.r]--;
        }
        
        // いもす
        for(int i=0; i<N; i++) {
            imos[i+1] += imos[i];
        }
        // 累積和
        for(int i=0; i<N; i++) {
            imos[i+1] += imos[i];
        }

        /*
        for(int i=0; i<=occD.size(); i++) {
            fprintf(stderr, "%lld ", imos[i]);
        }
        fprintf(stderr, "\n");
        */
        
        idx = 0;
        jdx = 0;
        for(int i=0; i<N; i++) {
            for(; idx<info.size() and info[idx].id<=i; idx++) {
                sub += info[idx].r - info[idx].l;
            }

            if(s[i] == 'M') {
                while(jdx < occD.size() and occD[jdx] <= i) jdx++;
                // int jdx = lower_bound(occD.begin(), occD.end(), i) - occD.begin();
                // fprintf(stderr, "i = %lld, jdx = %lld, query = %lld\n", i, jdx, val.query(0, jdx));
                // fprintf(stderr, "i = %lld, jdx = %lld, imos = %lld, sub = %lld\n", i, imos[jdx], sub);
                ans += (jdx == 0 ? 0 : imos[jdx - 1]) - sub;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

string S;

int main() {
    cin >> S;

    if (regex_match(S, regex("(dream|dreamer|erase|eraser)*"))) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }   
    
    return 0;
}


Measured memory_bytes: 39808
#include<iostream>
#include<cstdio>
#include<string>
#define mian main
using namespace std;
string s;
int l;
int mian()
{
    cin>>s;
    l=s.size();
    for(register int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(register int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

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

#define int long long

const int N = 5e3 + 10;

int n , k , p[N] , w[N] , vis[N] , ans = -1e18 , upd , Rt;
int dpe[N] , siz[N] , sum[N] , cnt;

void dfs(int u){
	if(vis[u]) return;
	vis[u] = true , dpe[u] = cnt;
	siz[cnt]++ , sum[cnt] += w[u] , dfs(p[u]);
}

void Updata(int u , int step){
	if(step == 0) return;
	upd += w[p[u]] , Rt = max(Rt , upd);
	Updata(p[u] , step - 1);
}

signed main(){
	scanf("%lld %lld" , &n , &k);
	for(int i = 1; i <= n; i++) scanf("%lld" , &p[i]);
	for(int i = 1; i <= n; i++) scanf("%lld" , &w[i]);
	for(int i = 1; i <= n; i++) if(!vis[i]) cnt++ , dfs(i);
	for(int i = 1; i <= n; i++){
		int step = k % siz[dpe[i]] , Re = k / siz[dpe[i]];
		if(Re) step += siz[dpe[i]] , Re--;
		upd = 0 , Rt = -1e18 , Updata(i , step);
		ans = max(ans , max(Rt , Rt + sum[dpe[i]] * Re));
	}
	printf("%lld" , ans);
	return 0;
} 

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, vT, vA;
  cin >> n >> vT >> vA;
  vT--, vA--;
  vvi to(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vi dA(n);
  deque<P> q;
  vector<int> used(n);
  q.push_back(P(vA, 0));
  while (!q.empty()) {
    int u, d;
    tie(u, d) = q.front();
    q.pop_front();
    if (used[u]) continue;
    used[u] = 1;
    dA[u] = d;
    for (auto& v : to[u]) {
      q.push_back(P(v, d + 1));
    }
  }
  dump(dA);
  vi dT(n, -INF);
  used.clear();
  used.resize(n, 0);
  dump(used);
  q.push_back(P(vT, 0));
  while (!q.empty()) {
    int u, d;
    tie(u, d) = q.front();
    q.pop_front();
    if (used[u]) continue;
    used[u] = 1;
    if (dA[u] <= d) continue;
    dT[u] = d;
    dump(u, d);
    for (auto& v : to[u]) {
      q.push_back(P(v, d + 1));
    }
  }
  dump(dT);
  // int mx = 0;
  // rep(i, n) maxs(mx, dT[i]);
  // int ans = 0;
  // rep(i, n) {
  //   if (dT[i] == mx) maxs(ans, dA[i] - 1);
  // }
  int ans = 0;
  rep(i, n) {
    if (dT[i] >= 0 && dT[i] < dA[i]) maxs(ans, dA[i] - 1);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

int mask[55];
ll dp[55][1<<20];

vector<vector<P>> v(55);

bool dfs(int now, int goal, int pre, int query_id){
	if(now == goal)return true;
	bool flag = false;
	REP(i, v[now].size()){
		int aite = v[now][i].FI;
		int edge_id = v[now][i].SE;
		if(aite == pre)continue;
		if(dfs(aite, goal, now, query_id)){
			mask[edge_id] |= (1 << query_id);
			flag = true;
		}
	}
	return flag;
}

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

	ll n, m;cin >> n;
	REP(i, n-1){
		ll a, b;cin >> a >> b;
		a--;b--;
		v[a].EB(b, i);
		v[b].EB(a, i);
	}
	cin >> m;
	REP(i, m){
		ll a, b;cin >> a >> b;
		a--;b--;
		dfs(a, b, -1, i);
	}

	dp[0][0] = 1;
	REP(i, n-1){
		REP(j, (1<<m))if(dp[i][j]){
			dp[i+1][j | mask[i]] += dp[i][j];
			dp[i+1][j] += dp[i][j];
		}
	}

	cout << dp[n-1][(1<<m)-1] << endl;

	return 0;
}


Measured memory_bytes: 362752
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
const int SIZE=5+3*1e5;
const int INF=10+1e9;
const LL p =7+1e9;
LL A[SIZE];
VI edges[SIZE];
LL reached[SIZE];
bool isUsed[SIZE];
LL maxim[SIZE];
LL sum[SIZE];
VI results;
bool solve(){
	int N,a,b;
	cin.tie(0);
	cin >> N;
	FOR(i,1,N+1) cin >> A[i];
	REP(i,N-1){
		cin >> a >> b;
		edges[a].PB(b);
		edges[b].PB(a);
	}
	queue<int> qu;
	FOR(i,1,N+1){
		if(edges[i].size()==1) {
			isUsed[i]=true;
			qu.push(i);
		}
	}
	while(!qu.empty()){
		int now=qu.front();
		qu.pop();
		if(A[now]>sum[now] && edges[now].size()!=1) return false;
		if(A[now]*2<sum[now]) return false;
		if(A[now]<maxim[now]) return false;
		if(edges[now].size()!=1) A[now]-=sum[now]-A[now];
		results.PB(A[now]);
		REP(i,edges[now].size()){
			int next=edges[now][i];
			if(isUsed[next]) continue;
			reached[next]++;
			sum[next]+=A[now];
			maxim[next]=max(maxim[next],A[now]);
			if(reached[next]==edges[next].size()-1){
				isUsed[next]=true;
				qu.push(next);
			}
		}
	}
	return results[N-1]==results[N-2];
}
int main(){
	if(solve()) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 15736
# include <iostream>
using namespace std;
typedef long long ll;

int main () {

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) cout << k << "\n";
    else if (k > a && k - a <= b) cout << a << "\n";
    else cout << a - (k - a - b)  << "\n";
    return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
int main(void){
  int P;
  int Q;
  int R;
  int min=0;
  scanf("%d",&P);
  scanf("%d",&Q);
  scanf("%d",&R);
  min=P+Q;
  if(Q+R<min){
    min=Q+R;
  }
  if(P+R<min){
    min=P+R;
  }
  printf("%d",min);
}

Measured memory_bytes: 128
#include<cstdio>
using namespace std;
int main(){
	int a,b;
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");              
    else if(b>=0)puts("Zero");   
    else if((a&1)^(b&1))puts("Positive");  
    else puts("Negative");
    return 0;
}

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

int main(){
    long long test, n, min = 1000000, max = -1000000, i, sum = 0;
    cin >> n;
    for (i = 0; i < n; i++){
        cin >> test;
        if (test < min) min = test;
        if (test > max) max = test;
        sum += test;
    }
    cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 3092
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	int ans = arr[0];
	for(int i = 1; i < n; i++)
		ans ^= arr[i];
	for(auto ele : arr)
		cout << (ans ^ ele) << " ";
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a<=c && c<=b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n = sc.read();
    println!("{}", solve(n));
}

fn solve(n: i128) -> i128 {
    let mut c = vec![];
    for i in 1.. {
        if i * i > (2 * n) {
            break;
        }
        if (2 * n) % i == 0 {
            let j = (2 * n) / i;
            c.push((i, j));
        }
    }

    let mut ans = 2 * n;
    for (x, y) in c {
        if y > 1 {
            let m = vec![x, y];
            let b = vec![0, y - 1];
            if let Some((k, _)) = chinese_remainder_theorem(&b, &m) {
                assert_eq!(k % x, 0);
                assert_eq!(k % y, y - 1);
                assert_eq!((k * (k + 1) / 2) % n, 0);
                assert!(k > 0);
                ans = min(ans, k);
            }
        }
        let (y, x) = (x, y);
        if y > 1 {
            let m = vec![x, y];
            let b = vec![0, y - 1];
            if let Some((k, _)) = chinese_remainder_theorem(&b, &m) {
                assert_eq!(k % x, 0);
                assert_eq!(k % y, y - 1);
                assert_eq!((k * (k + 1) / 2) % n, 0);
                assert!(k > 0);
                ans = min(ans, k);
            }
        }
    }
    ans
}

pub fn extended_gcd(a: i128, b: i128, p: &mut i128, q: &mut i128) -> i128 {
    if b == 0 {
        *p = 1;
        *q = 0;
        a
    } else {
        let d = extended_gcd(b, a % b, q, p);
        *q -= a / b * *p;
        d
    }
}

pub fn chinese_remainder_theorem(b: &[i128], modulo: &[i128]) -> Option<(i128, i128)> {
    let (mut result, mut m) = (0, 1);
    for i in 0..b.len() {
        let (mut p, mut q) = (0, 0);
        let d = extended_gcd(m, modulo[i], &mut p, &mut q);
        if (b[i] - result) % d != 0 {
            return None;
        }
        let tmp = ((b[i] - result) / d * p) % (modulo[i] / d);
        result += m * tmp;
        m *= modulo[i] / d;
    }
    Some(((result % m + m) % m, m))
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> vec(n),ans(n);
  rep(i,n){
    cin >> vec.at(i);
  }
  int64_t answer=0;
  for(int64_t x: vec){
    if(x>n){
      answer++;
      continue;
    }
    ans.at(x-1)++;
  }
  rep(i,n){
    if(ans.at(i)>=i+1){
      answer+=ans.at(i)-i-1;
    }else{
      answer+=ans.at(i);
    }
  }
  cout << answer;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
b = a[::-1]
for i in range(1, n):
  if b[i] - b[i-1] > 1:
    print("No")
    exit()
  elif b[i] - b[i-1] == 1:
    b[i] -= 1
else:
  print("Yes")

Measured memory_bytes: 63984