akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const ll MOD = 1000000;
int n;
char bytes[1100][20];
ll memo[1100][4][2];

ll calc(int depth, int rest, int exist) {
  if (memo[depth][rest][exist] != -1) { return memo[depth][rest][exist]; }
  ll ret = 0;
  if (depth == n) {
    if (rest == 0) { ret = 1; }
    return memo[depth][rest][exist] = ret;
  }
  for (int i = 0; i < (1 <<  8); i++) {
    int nrest = rest - 1;
    int nexist = 1;
    REP(j, 8) {
      if (bytes[depth][7 - j] != 'x' && bytes[depth][7 - j] - '0' != ((i >> j) & 1)) { goto next; }
    }
    if (rest == 0) {
      if (!(i & (1 << 7))) { nrest = 0; }
      else if (!(i & (1 << 6))) { goto next; }
      else if (!(i & (1 << 5))) { nrest = 1; }
      else if (!(i & (1 << 4))) { nrest = 2; }
      else if (!(i & (1 << 3))) { nrest = 3; }
      else { goto next; }
      if (nrest == 1) {
        if (!(i & (2 + 4 + 8 + 16))) { goto next; }
      } else if (nrest == 2) {
        if (!(i & (1 + 2 + 4 + 8))) { nexist = 0; }
      } else if (nrest == 3) {
        if (!(i & (1 + 2 + 4))) { nexist = 0; }
      }
    } else {
      if (!(i & (1 << 7))) { goto next; }
      if (i & (1 << 6)) { goto next; }
      if (!exist) {
        if (rest == 2) {
          if (!(i & 32)) { goto next; }
        } else if (rest == 3) {
          if (!(i & (16 + 32))) { goto next; }
        } else {
          assert(false);
        }
      }
    }
    ret = (ret + calc(depth + 1, nrest, nexist)) % MOD;
next:;
  }
  return memo[depth][rest][exist] = ret;
}

int main() {
  while (scanf("%d", &n), n) {
  REP(i, n) {
    scanf("%s", bytes[i]);
  }
  MEMSET(memo, -1);
  printf("%lld\n", calc(0, 0, 1));
  }
}

Measured memory_bytes: 1044
#include <stdio.h>

int main() {

    int i,j,k,n,x,count;

    while(1){
        count=0;
        scanf("%d %d",&n,&x);
        if(n==0&&x==0)
            break;
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                for(k=1;k<=n;k++){
                    if(i+j+k==x && i!=j && j!=k && k!=i)
                            count++;
                    
                }
            }
        }
    
printf("%d\n",count/6);

}

return 0;

}

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

int main(){
    map<int, int> store;
    int N, t;
    cin >> N;
    while(cin>>t){
        if(store.count(t)){
            cout << "NO" << endl;
            return 0;
        }
        store[t]++;
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 9600
#二部グラフで連結判定
N,M = map(int,input().split())
KL = [list(map(int,input().split())) for _ in [0]*N]

E = [[] for _ in [0]*(N+M)] #E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語
for i,kl in enumerate(KL):
    for l in kl[1:]:
        E[i].append(N+l-1)
        E[N+l-1].append(i)

def dist_bfs(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        qq = []
        for i in q:
            di = d[i]
            for j in E[i]:
                if d[j]!=-1:continue
                d[j] = di+1
                q.append(j)
        q = qq
    return d

d = dist_bfs(N+M,E,0)
ans = d[:N].count(-1)==0
print("YES" if ans else "NO")

Measured memory_bytes: 48648
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct Edge {
	int from,to,w;
	Edge(){}
	Edge(int u,int v,int d):from(u),to(v),w(d){}
}e[2*maxn];
struct A {
	int d, u;
	A(int d,int u):d(d),u(u){}
	A(){}
	bool operator < (const A& ot) const {
		return d > ot.d;
	}
};
bool vis[maxn];
int d[maxn];
vector<int>G[maxn];

void dijkstra(int s){
	priority_queue<A> Q;
	Q.push(A(0,1));
	memset(vis,0,sizeof(vis));
	d[s]=0;
	while(!Q.empty()) {
		A p=Q.top();Q.pop();
		int u=p.u;
		if(vis[u])continue;
		for(int i=0;i<G[u].size();i++) {
			Edge es = e[G[u][i]];
			if(d[es.to]>es.w+d[u]) {
				d[es.to]=es.w+d[u];
				Q.push(A(d[es.to],es.to));
			}
		}
	}
}

int main() {
	int k;
	scanf("%d",&k);
	int s = 1, l = 1;
	for(int i=1;i<=k;i++) {
		G[i].push_back(l++);
		e[l-1]=Edge(i,(i+1)%k,1);
		G[i].push_back(l++);
		e[l-1]=Edge(i,i*10%k,0);
	}
	memset(d,0x3f,sizeof(d));
	dijkstra(1);
	printf("%d\n", d[0]+1);
} 

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	const Int MOD = 1e9 + 7;
	int N;
	cin >> N;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	int n = 60;
	vector<Int> b(n);
	b[0] = 1;
	for (int i = 1; i < n; ++i) {
		b[i] = (b[i - 1] * 2) % MOD;
	}

	Int ans = 0;
	vector<vector<Int>> memo(n, vector<Int>(2, 0));
	for (int i = 0; i < N; ++i) {
		Int tmp = a[i];
		for (int j = 0; j < n; ++j) {
			if (tmp & 1) {
				ans += (memo[j][0] * b[j]) % MOD;
				ans %= MOD;
				memo[j][1] = (memo[j][1] + 1) % MOD;
			} else {
				ans += (memo[j][1] * b[j]) % MOD;
				ans %= MOD;
				memo[j][0] = (memo[j][0] + 1) % MOD;
			}
			tmp /= 2;
		}
	}
	cout << ans % MOD << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

using namespace std;

int combi(int n, int s, vector<int> usedNum){
	int combiCount = 0;
	int tmp;
	bool usedFlag = false;

	n--;
	for(int i = 0; i <= 9; i++){
		for(int j = 0; j < usedNum.size(); j++){
			if(usedNum[j] == i) usedFlag = true; 
		}
		if(usedFlag){
			usedFlag = false;
			continue;
		}

		tmp = s - i;
		
		if(n != 0){
			usedNum.push_back(i);
			combiCount += combi(n, tmp, usedNum);
		}
		else if(n == 0 && tmp == 0){
			usedNum.pop_back();
			return ++combiCount;
		}
	}

	usedNum.pop_back();
	return combiCount;
}


int main(){
	int n, s;
	int combiCount = 0;
	vector<int> usedNum;
	while(cin >> n >> s && (n != 0 || s != 0)){
		combiCount = combi(n, s, usedNum);
		cout << combiCount << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
// --------------
// Tejas Pandey  |
// 13 - 09 - 20  |
// Atcoder BC 178|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x;
  cin >> x;
  cout << abs(x - 1) << "\n";
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 2e9, mod = 998244353;
char other(char a, char b){
    if(a != 'R' && b != 'R') return 'R';
    if(a != 'G' && b != 'G') return 'G';
    if(a != 'B' && b != 'B') return 'B';
}
int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n, sum = 1; cin >> n;
    string s; cin >> s;
    pair<char, int> c1(s[0],1),c2(' ',0);
    for(int i=1;i<3*n;i++){
        if(s[i] == c2.x){
            sum = sum * c2.y % mod;
            --c2.y;
            if(c2.y == 0) c2.x = ' ';
            continue;
        }
        if(c1.x == ' ' || s[i] == c1.x){
            c1.x = s[i];
            c1.y++;
            continue;
        }
        sum = sum * c1.y % mod;
        c1.y--;
        c2.x = other(s[i], c1.x);
        c2.y++;
        if(c1.y == 0) c1.x = ' ';
    }
    int fact = 1;
    for(int i=1;i<=n;i++) fact = fact * i % mod;
    cout << sum * fact % mod;
    return 0;
}


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



void solve() {
  ll a, b, c; cin >> a >> b >> c;
  ll k; cin >> k;
  ll ans = min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  ans -= min(c, k);
  cout<<ans<<endl;
}

int main() {
  int t; t = 1;
  while(t--) solve();
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		sc.close();
		int N = S.length();
		//回文であるかチェック
		checkPalindrome(S, (N - 1) / 2, 0, N - 1);
		checkPalindrome(S, (N - 1) / 4, 0, (N - 3) / 2);
		checkPalindrome(S, (N - 1) / 4, (N + 1) / 2, N - 1);
		System.out.println("Yes");
	}

	public static void checkPalindrome(String S, int num1, int num2, int num3) {
		for (int i = 0; i < num1; i++) {
			if (S.charAt(num2 + i) != S.charAt(num3 - i)) {
				System.out.println("No");
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  int n;
  cin >> n;
  while(n>0) {
    n -= 1000;
  }
  cout << -n << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

ll n, m;
string a, b;
vector<ll> location[26];
ll ans = -1;

int main(){
    cin >> a >> b;
    n = (ll)a.size(), m = (ll)b.size();
    for(ll i=0; i<n; i++){
        location[a[i]-'a'].push_back(i);
        location[a[i]-'a'].push_back(i+n);
    }

    for(ll i=0; i<26; i++){
        sort(location[i].begin(), location[i].end());
    }

    for(ll i=0; i<m; i++){
//        printf("get %c: ", b[i]);
//        for(auto &x: location[b[i]-'a']) printf("%d ", x);
//        puts("");
        if(location[b[i]-'a'].empty()){
            printf("-1");
            return 0;
        }
        ll it = *upper_bound(location[b[i]-'a'].begin(), location[b[i]-'a'].end(),
                             ans%n);
        ans += (it - ans%n);
    }
    printf("%lld", ans+1);
}


Measured memory_bytes: 2800
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


class SegTree:
    """
    Segment Tree
    """

    def __init__(self, init_val, segfunc, ide_ele):
        """
        初期化

        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新 O(N)

        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る O(logN)

        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


def main():
    N, K = map(int, input().split())
    A = []
    MAX = 300005
    for i in range(N):
        A.append(int(input()))

    ide_ele = 0

    dp = SegTree([0] * MAX, segfunc=max, ide_ele=ide_ele)

    for i in range(N):
        a = A[i]
        l = max(0, a - K)
        r = min(MAX, a + K + 1)
        now = dp.query(l, r) + 1
        dp.update(a, now)

    print(dp.query(0, MAX))


if __name__ == "__main__":
    main()


Measured memory_bytes: 93024
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define ll long long
#define test(a) cout << "*" << a << endl;
int main (){
  int i;
  int N,T,A;
  ll H[1001];
  double dlt;
  double dltMin = 1000000000;
  int iMin;
  
  cin >> N >> T >> A;
  
  rep1(i,N){
    cin >> H[i];
    dlt =  abs( (T - H[i]*0.006) - A );
    if(dlt<dltMin){
      dltMin = dlt;
      iMin = i; 
    }
  }
  //test(dltMin);
    cout << iMin << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  int N;
  cin >> N;
  int a[N];
  rep(i,N) cin >> a[i];
  sort(a,a+N,greater<int>());
  cout << a[N/2-1] - a[N/2] << endl;
  
  return 0;
}


Measured memory_bytes: 640
#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(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    int n,k;
    cin >> n >> k;
    int ans = 1;
    rep(i,n){
        if (ans > k) ans += k;
        else ans *= 2;
    }
    PRINT(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    string S;
    cin >> S;
    bool tmp[26] = {};
    for(int i=0; i<S.size(); i++){
        tmp[S[i]-'a'] = true;
    }
    for(int i=0; i<26; i++){
        if(tmp[i] == false){
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>

using namespace std;


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

	double x[n];
    string v[n];

	double sum = 0.0;

	for (int i = 0; i < n; i++) {
		cin >> x[i] ;
        cin>>v[i];
		if (v[i] == "JPY") {
			sum += x[i];
		}
		if(v[i]=="BTC"){
			sum +=x[i]*380000;
		}
	}
  
  cout<<setprecision(10)<<sum<<endl;

	return 0;
}

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

int main(){
  int n;
  cin >>n;
  vector<double>x(n);
  vector<string>u(n);
  for (int i = 0;  i < n; i++){
    cin>> x.at(i)>> u.at(i);
  }
  double s=0.0000;
  for (int i = 0; i < n; i++){
    if (u.at(i) == "JPY"){
      s+= x.at(i);
    }
    
    else
      s+= x.at(i) * 380000.0;
  }
  cout << s << endl;
}

    
      
  
      
      
   

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

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    ll h; cin >> h;
    ll multi = 1;
    ll ans = 1;
    for (ll i = h; i != 1; i /= 2){
        multi *= 2;
        ans += multi;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
using namespace std;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX 100000
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int a,b;
char s[12];
bool C(char c){
  if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9'){
    return true;
  }
  else return false;
}
int main(){
  scan(a);scan(b);
  rep(i,a+b+1)scan(s[i]);
  bool f=true;
  rep(i,a){
    if(!C(s[i]))f=false;
  }
  if(s[a]!='-')f=false;
  rep(i,b){
    if(!C(s[i+a+1]))f=false;
  }
  if(f)prin("Yes");
  else prin("No");
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
} 
const int Mod = 1e9 + 7; 
const int MAX_N = 5005; 
struct Graph { int to, next; } e[MAX_N << 1]; 
int fir[MAX_N], e_cnt; 
void clearGraph() { memset(fir, -1, sizeof(fir)); e_cnt = 0; } 
void Add_Edge(int u, int v) { e[e_cnt] = (Graph){v, fir[u]}, fir[u] = e_cnt++; } 
int N, f[MAX_N][MAX_N], g[MAX_N], t[MAX_N], sz[MAX_N]; 
void dfs(int x, int fa) { 
	f[x][1] = 1, sz[x] = 1; 
	for (int i = fir[x]; ~i; i = e[i].next) {
		int v = e[i].to; if (v == fa) continue; 
		dfs(v, x); 
		for (int j = 0; j <= sz[x] + sz[v]; j++) t[j] = 0; 
		for (int j = 1; j <= sz[x]; j++) 
			for (int k = 0; k <= sz[v]; k++) 
				t[j + k] = (t[j + k] + 1ll * f[x][j] * f[v][k]) % Mod;
		sz[x] += sz[v]; 
		for (int j = 1; j <= sz[x]; j++) f[x][j] = t[j]; 
	} 
	for (int i = 2; i <= sz[x]; i += 2) 
		f[x][0] = (f[x][0] + Mod - 1ll * f[x][i] * g[i] % Mod) % Mod; 
} 
int main () { 
	clearGraph(); 
	N = gi(); 
	for (int i = 1; i < N; i++) { 
		int u = gi(), v = gi(); 
		Add_Edge(u, v), Add_Edge(v, u); 
	} 
	g[0] = 1; for (int i = 2; i <= N; i += 2) g[i] = 1ll * g[i - 2] * (i - 1) % Mod; 
	dfs(1, 0); 
	printf("%d\n", Mod - f[1][0]); 
    return 0; 
} 

Measured memory_bytes: 58416
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  ll mn = A;
  if (B < mn)
    mn = B;
  if (C < mn)
    mn = C;
  if (D < mn)
    mn = D;
  if (E < mn)
    mn = E;
  cout << ((N + mn - 1) / mn) + 4 << endl;
  return 0;
}


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

int n,k;
bool dp[100005];
int a[100005];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n>>k;
	
	for(int i=0;i<n;i++) cin>>a[i];
	
	for(int i=a[0];i<=k;i++){
		bool hnhn = false;
		for(int j=0;j<n;j++){
			if(i-a[j] < 0)break;
			if(!dp[i-a[j]]){
				hnhn = true;
				break;
			}
		}
		dp[i] = hnhn;
	}
	
	if(dp[k]) cout<<"First";
	else cout<<"Second";
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll x;cin>>x;
    for(ll a=-500;a<=500;a++){
        for(ll b=-500;b<=500;b++){
            ll bufa=a*a*a*a*a,bufb=b*b*b*b*b;
            if(bufa-bufb==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3552
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
int sw[300000+1];
void solve(long long N, string S){
	for(int i=0; i<N; ++i) {
		if (i>0)
		sw[i]=sw[i-1];
		if (S[i]=='W') {
			++sw[i];
		} 
	}	
	int s=0;
	int ans=INT_MAX;
	for(int i=N; i>=0; --i) {
		if (S[i]=='E') {
			++s;
		}
		if (i==0) {
			ans=min(ans,s);
		} else 
		ans=min(ans,sw[i-1]+s);
	}
	cout<<ans<<endl;
}

int main(){	
	string S;
	long long N;
	scanf("%lld",&N);
	cin >> S;
	solve(N, S);
	return 0;
}



Measured memory_bytes: 2180
#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N,M = inpl()
aa = inpl()
ans = 0

ed = [0]
SUM_L = defaultdict(int)
SUM_R = defaultdict(int)
SUM_L[0] += 1
SUM_R[0] += 1
SUM = sum(aa) % M

tmpL = tmpR = 0
for i in range(N):
	tmpL += aa[i]
	tmpL %= M
	if SUM_L[tmpL] == 0:
		ed.append(tmpL)
	SUM_L[tmpL] += 1

	tmpR += aa[N-i-1]
	tmpR %= M
	SUM_R[tmpR] += 1

ans = 0
for l in ed:
	numL = SUM_L[l]
	r = (SUM - l) % M
	numR = SUM_R[r]
	ans += numL * (numR-1)

print(ans//2)


Measured memory_bytes: 20504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;


int main() {
    int a; cin >> a;
    cout << (1+(1+a)*a)*a << endl;
}

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

int main(){
  string s;
  cin >> s;
  int lens = s.size();
  if (lens == 2){
    if (s[0] == s[1]){
      cout << 1 << ' ' << 2 << endl;
      return 0;
    }
  }
  for (int i=0; i<lens-2; i++){
    string subs = s.substr(i,3);
    set<char> st;
    for (int j=0; j<3; j++) st.insert(subs[j]);
    if ((int)st.size() < 3){
      cout << i+1 << ' ' << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

// cl /EHsc xxxx.c
int main(int arc, char *argv[])
{
	int a, b, c;
	int i;
	int count = 0;

	scanf("%d %d %d", &a, &b, &c);
	
	for (i = a; i <= b; i++) {
		if (c % i == 0) {
			count++;
		}
	}
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 596
import itertools

n = int(input())
a = ''.join(input().split())
b = ''.join(input().split())

nn=[]
ss=[]

for i in range(1,n+1):
  nn.append(i)

for i in itertools.permutations(nn):
    ss.append(''.join(map(str,list(i))))

ss.sort()

ai=ss.index(a)+1
bi=ss.index(b)+1

print(abs(ai-bi))

Measured memory_bytes: 6040
#include <iostream>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <sstream>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

template <class T1, class T2, class Pred = less<T2> >
struct sort_pair_second {
  bool operator()(const pair<T1, T2>&left, const pair<T1, T2>&right) {
    Pred p;
    return p(left.second, right.second);
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> v(M);
  vector<int> Y(M);
  REP(i, M) {
    cin >> v[i].first >> v[i].second;
    Y[i] = v[i].second;
  }
  sort(v.begin(), v.end());
  vector<int> p_count(N, 1);
  map<int, string> ans;
  REP(i, M) {
    ostringstream sout1, sout2;
    sout1 << setfill('0') << setw(6) << v[i].first;
    sout2 << setfill('0') << setw(6) << p_count[v[i].first-1];
    string s = sout1.str() + sout2.str();
    ans[v[i].second] = s;
    p_count[v[i].first-1]++;
  }
  REP(i, M) {
    cout << ans[Y[i]] << endl;
  }
  return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }

    auto c = make_vec<int>(H, W);
    int now = 0;
    for (int i = 0; i < H; i++) {
        if (i % 2 == 0) {
            for (int j = 0; j < W; j++) {
                if (a[now] == 0) now++;
                c[i][j] = now + 1;
                a[now]--;
            }
        } else {
            for (int j = W - 1; j >= 0; j--) {
                if (a[now] == 0) now++;
                c[i][j] = now + 1;
                a[now]--;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << c[i][j];
            if (j != W - 1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 384
N, M = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(M)]

INF = - 10 ** 20
d = [INF for _ in range(N)]
d[0] = 0

for i in range(2 * N):
  f = True
  rel = d[-1]
  for j in range(M):
    a, b, c = abc[j]
    a -= 1
    b -= 1
    if d[b] < d[a] + c:
      d[b] = d[a] + c
      f = False
  if f:
    break
else:
  if rel != d[-1]:
    print("inf")
    exit()

print(d[-1])

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n;cin>>n;
  int ans=0;
  int c=1;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    if(a==c){
      c++;
    }else{
      ans++;
    }
  }
  if(ans==n){
    cout<<-1<<endl;
  }else
    cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3608
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    X = LI()
    X = sorted(X)
    pos_q, neg_q = [], []
    cur_i = N - 1
    for x in X:
        if x < 0:
            neg_q.append(x)
        elif x == 0:
            K -= 1
        else:
            pos_q.append(x)
    if K == 0:
        print(0)
        return
    ans = inf
    pos_q = sorted(pos_q)
    neg_q = sorted(neg_q)[::-1]
    
    for ix, p in enumerate(pos_q):
        if K - ix - 1 > 0: # if still remains
            nokori = K - ix - 1
            if 0 <= nokori - 1 < len(neg_q):
                ans = min(abs(neg_q[nokori-1] - p - p), ans)
        else:
            ans = min(p, ans)

    for ix, n in enumerate(neg_q):
        if K - ix - 1 > 0:
            nokori = K - ix -1
            if 0 <= nokori - 1 < len(pos_q):
                ans = min(pos_q[nokori-1] + abs(n) + abs(n), ans)
        else:
            ans = min(abs(n), ans)
    print(ans)

main()



Measured memory_bytes: 16656
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main() {
    int x;
    cin>>x;
    cout<<(x<1200?"ABC":"ARC")<<endl;
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()
if E[0][0]!=O[0][0]:
    print(n-E[0][1]-O[0][1])
else:
    if E[0][1]==O[0][1]==n//2:
        print(E[0][1])
    else:
        print(min(n-E[1][1]-O[0][1],n-E[0][1]-O[1][1]))

Measured memory_bytes: 20700
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let s = (read string).ToCharArray()
    let t = (read string).ToCharArray()
    Array.zip s t
    |> Array.fold (fun s (a, b) -> if a = b then s + 1 else s) 0
    |> printfn "%i"
    0

Measured memory_bytes: 12112
#include <iostream>
using namespace std;
long long ans[100005],fa[100005],sz[100005];
inline int ff(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=ff(fa[x]);
}
pair <int,int> a[100005];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	long long qwq=0;
	for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++)
		cin >> a[i].first >> a[i].second;
	for(int i=m;i>=1;i--)
	{
		ans[i]=(long long)n*(n-1)/2-qwq;
		if(ff(a[i].first)!=ff(a[i].second))
		{
			qwq+=sz[ff(a[i].first)]*sz[ff(a[i].second)];
			sz[ff(a[i].second)]+=sz[ff(a[i].first)];
			fa[ff(a[i].first)]=ff(a[i].second);
		}
	}
	for(int i=1;i<=m;i++)
		cout << ans[i] << "\n";
	return 0;
}

Measured memory_bytes: 4480
#include <stdio.h>

void merge_sort(long long x[], int n)
{
	static long long y[100001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

long long recursion(int a[], int N)
{
	if (N == 0) return 0;
	else if (N == 1) {
		if (a[0] >= 0) return 1;
		else return 0;
	}
	
	int i, j;
	static long long sur[2][100001];
	long long ans = recursion(&(a[0]), N / 2) + recursion(&(a[N/2]), (N + 1) / 2);
	for (i = N / 2 - 1, sur[0][N/2] = 0; i >= 0; i--) sur[0][i] = sur[0][i+1] + a[i];
	for (i = 0, sur[1][0] = 0; i <= (N + 1) / 2 - 1; i++) sur[1][i+1] = sur[1][i] + a[i+N/2];
	sur[1][0] = sur[1][(N+1)/2];
	merge_sort(sur[0], N / 2);
	merge_sort(sur[1], (N + 1) / 2);
	for (i = 0; i < N / 2 && sur[0][i] + sur[1][(N+1)/2-1] < 0; i++);
	for (j = (N + 1) / 2 - 1; i < N / 2; i++) {
		for (; j >= 0 && sur[0][i] + sur[1][j] >= 0; j--);
		if (j < 0) break;
		ans += (N + 1) / 2 - j - 1;
	}
	ans += (long long)(N / 2 - i) * ((N + 1) / 2);
	return ans;
}

int main()
{
	int i, N, K, a[200001];
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++) scanf("%d", &(a[i]));
	for (i = 0; i < N; i++) a[i] -= K;
	printf("%lld\n", recursion(a, N));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4848
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] num = new int[s.length()];
        for (int i=0;i<s.length();i++){
            num[i]=s.charAt(i)-'1'+1;
        }
        long ans = 0;
        for (int i=0;i<Math.pow(2,s.length()-1);i++){
            String index = Integer.toBinaryString(i);
            while (index.length()<s.length()-1)index="0"+index;
            long count=0;
            long instance=num[0];
            for (int j=1;j<s.length();j++){
                if (index.charAt(j-1)=='0'){
                    instance*=10;
                    instance+=num[j];
                }else {
                    count+=instance;
                    instance=num[j];
                }
            }
            ans += count+instance;
        }
        System.out.println(ans);
    }
 
}

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define LL long long
#define MAXN 100000
char str[MAXN+5];

int main(){
    int cnt=0,N=read();
    scanf("%s",str+1);
    for(int i=1;i<=N;i++)
        if(str[i]!=str[i-1])
            cnt++;
    printf("%d",cnt);
}


Measured memory_bytes: 384
import numpy as np
from collections import Counter


len_arr = int(input())
arr = list(map(int, input().split(' ')))
counter = Counter(arr)
x_max = max(counter.keys())

dp = np.empty(x_max+1, dtype=np.bool_)
dp[:] = True

ans = 0

for x, count in sorted(counter.items()):
    multi = [x*y for y in range(1, x_max//x+1)]
    if count == 1 and dp[x]:
        ans += 1
    dp[multi] = False

print(ans)


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

using namespace std;

int main() {
  array<string, 3> a;
  char c;
  int iter = 0;
  while (cin >> c) {
    if (c == ',') {
      ++iter;
    } else {
      a[iter] += c;
    }
  }
  for (int i = 0; i < 3; ++i) {
    cout << a[i] << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
s = input()
while s:
    if s[:11] == "dreameraser":
        s = s[11:]
    elif s[:10] == "dreamerase":
        s = s[10:]
    elif s[:7] == "dreamer":
        s = s[7:]
    elif s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "dream":
        s = s[5:]
    elif s[:5] == "erase":
        s = s[5:]
    else:
        print("NO")
        quit()
print("YES")
"""

#D
def root(x,par,rank):
    if x == par[x]:
        return x
    par[x] = root(par[x],par,rank)
    return par[x]
def unite(x,y,par,rank):
    x = root(x,par,rank)
    y = root(y,par,rank)
    if x == y:return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
n,k,l = LI()
par1 = [i for i in range(n)]
rank1 = [0 for i in range(n)]
par2 = [i for i in range(n)]
rank2 = [0 for i in range(n)]
for i in range(k):
    p,q = LI()
    p -= 1
    q -= 1
    unite(p,q,par1,rank1)
for i in range(l):
    p,q = LI()
    p -= 1
    q -= 1
    unite(p,q,par2,rank2)
d = {}
for i in range(n):
    k = (root(i,par1,rank1),root(i,par2,rank2))
    if k in d:
        d[k] += 1
    else:
        d[k] = 1
ans = []
for i in range(n):
    k = (root(i,par1,rank1),root(i,par2,rank2))
    ans.append(d[k])
print(*ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 56732
#include <string>
#include <iostream>
#include <cmath>

using namespace std;

int f(string A, string B){
    return A.length() > B.length() ? A.length() : B.length();
}

int main(){
    long long N;
    cin >> N;
    long long sqrt_N = sqrt(N);

    int ans = 1000;
    for(int A=1;A<=sqrt_N;A++){
        if(N%A != 0) continue;

        int B = N/A;
        string str_A = to_string(A);
        string str_B = to_string(B);

        ans = min(ans, f(str_A, str_B));
    }

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

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

using namespace std;

int adj[101][101];
long long min_val;
bool visited[N];

void dfs(int node, long long sum) {
    if (node == 1)
        min_val = min(min_val, sum);
    visited[node] = true;
    for (int i = 0; i < 10; i += 1) {
        if (!visited[i]) {
            dfs(i, sum + adj[node][i]);
        }
    }
    visited[node] = false;
}


int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 10; i += 1) {
        for (int j = 0; j < 10; ++j)
        {
            cin >> adj[i][j];
        }
    }
    
    int min_cost[N] = {0};
    for (int i = 0; i < 10; ++i)
    {
        min_val = adj[i][1];
        dfs(i, 0);
        // cout << min_val << endl;
        for (int j = 0; j < 12; ++j)
            visited[j] = false;
        min_cost[i] = min_val;
    }

    
    long long ans = 0;
    for (int i = 1; i <= n; i += 1) {
        for (int j = 1; j <= m; ++j)
        {
            int x;
            cin >> x;
            if (x != -1)
                ans += min_cost[x];
        }
    }

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define  FIO        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  all(v)     v.begin(),v.end()
#define  rall(v)    v.rbegin(),v.rend()
#define  MEM(a,x)   memset(a,x,sizeof(a))
#define  pi         acos(-1.0)
#define  ll     long long
#define  pb     push_back
#define  mp     make_pair
#define  pii    pair< int,int >
#define  pll    pair< ll,ll >
#define  vii    vector< int >
#define  vll    vector< ll >
#define  vpi    vector< pii >
#define  vpl    vector<pll>
#define  MX     100005
#define  EPS    1e-12
#define  ss     second
#define  ff     first
int cases=1;
#ifdef ppqq
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<"  ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************
int main()
{
   //freopen ("output.txt","w",stdout);
   //freopen ("input.txt","r",stdin);
    FIO;
    int n,m,x,sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>n) cout<<-1;
    else cout<<n-sum;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int A[n][n-1];
    REP(i,n){
        REP(j,n-1){
            scanf("%lld",&A[i][j]);
            A[i][j] --;
        }
    }





    int vis[n];
    REP(i,n) vis[i] = 0;
    int siaisuu = 0;
    int ans = 0;
    int jun[n];
    REP(i,n) jun[i] = 0;
    while(siaisuu < n * (n-1) / 2){
        ans ++;
        int flag = true;
        REP(i,n){
            if(vis[i] != ans and jun[i] < n-1){
                int aite = A[i][jun[i]];
                if(A[ aite ][jun[aite]] == i and vis[aite] != ans and jun[aite] < n-1){
                    vis[aite] = ans;
                    vis[i] = ans;
                    siaisuu ++;
                    flag = false;
                    jun[i] ++;
                    jun[aite] ++;
                    //debug(i);
                    //debug(aite);
                    
                }
            }
        }
        if(flag){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;



}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int h,w,k;
    cin >> h >> w >> k;
    string s[h];
    REP(i,h) cin >> s[i];

    int ans[h][w];
    REP(i,h) REP(j,w) ans[i][j] = - 1;
    
    int id = 0;
    REP(i,h){
        int bef = 0;
        REP(j,w){
            if(s[i][j] == '#'){
                if(bef == 0){
                id ++;
                FOR(k,bef,j+1) ans[i][k] = id;
                bef = 1;
                }
                else{
                    id++;
                    ans[i][j] = id;
                }
            }
            else{
                if(bef !=0) ans[i][j] = id;
            }
        }
    }


    /*
    REP(i,h){
        REP(j,w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    cout  << endl;
    */
    int hoge = 0;
    REP(i,h){
        if(ans[i][0] != -1){
            FOR(j,hoge,i){
                REP(k,w){
                    ans[j][k] = ans[i][k];
                }
            }
            hoge = i + 1;
        }
    }
    if(hoge != h){
        FOR(j,hoge,h){
            REP(k,w){
                ans[j][k] = ans[hoge - 1][k];
            }
        }
    }

    REP(i,h){
        REP(j,w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
int main() {
  while(1){
    int n;
    cin >> n;
    if (!n) break;
    vector<int> v(86400);
    for (int i = 0; i < n; ++i) {
      int h[2],m[2],s[2];
      scanf("%d:%d:%d",&h[0],&m[0],&s[0]);
      scanf("%d:%d:%d",&h[1],&m[1],&s[1]);
      int bg = h[0]*3600 + m[0]*60 + s[0];
      int ed = h[1]*3600 + m[1]*60 + s[1];
      ++v[bg];
      --v[ed];
    }
    for (int i = 1; i < 86400; ++i) {
      v[i] += v[i-1];
    }
    cout << *max_element(begin(v), end(v)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1572
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>

#pragma GCC optimize(2)
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量，a为初始值，n为界限值，递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量， a为初始值，n为界限值，递减。

using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll<<60;
const int mod=1e9+7;

ll read()//快读
{
	ll w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';    ch = getchar(); }
	return s * w;
}


int main(){
	int n;
	cin>>n;
	int a[110],b[110];
	int cnt=0;
	int f=0;
	rep(i,1,n){
		cin>>a[i]>>b[i];
	}
	rep(i,1,n){
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
			f=1;
		}
	}
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}


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

ll v[200005], n;

ll solve(ll x){
    ll sum = 0;
    for(ll i = 0; i < n; i++)
        sum += abs(v[i]-x);
    return sum;
}

int main(){

    cin >> n;

    for(ll i = 0; i < n; i++){
        cin >> v[i];
        v[i] = v[i] - i - 1;
    }

    sort(v, v+n);
    if(n%2 == 1){
        ll x = v[n/2];
        ll sum = 0;
        for(int i = 0; i < n; i++)
            sum += abs(v[i]-x);
        cout << sum << endl;
    }
    else{
        ll x1 = v[n/2-1], sum1 = 0;
        ll x2 = v[n/2], sum2 = 0;
        for(int i = 0; i < n; i++) sum1 += abs(v[i]-x1);
        for(int i = 0; i < n; i++) sum2 += abs(v[i]-x2);
        cout << min(sum1,sum2) << endl;
    }



    // for(int i = 0; i < n; i++)
    //     cout << v[i] << " ";
    // cout << endl;

    // for(ll j = 0; j < 5; j++){
    //     ll aux = solve(j);
    //     cout << j << " " << aux << endl;
    // }

    
	return 0;
}


Measured memory_bytes: 1792