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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){
  int N;cin >> N;
  string S; cin>>S;
  int siro[N+1];
  int kuro[N+1];
  int num_kuro = 0;
  int num_siro = 0;
  kuro[0] = 0;
  siro[N] = 0;
  rep(i, N+1){
    if (S[i] == '#') num_kuro++;
    if (S[N-1-i] == '.') num_siro++;
    kuro[i+1] = num_kuro;
    siro[N-1-i] = num_siro;
  }
  int ans = N*10;
  rep(i, N+1){
    //cout << kuro[i] << " " <<siro[i] <<endl; 
    ans = min(ans, kuro[i] + siro[i]);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 5300
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();  
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N,M,K;
        cin>>N;
        M=0;
        K=100;
        while(K<N)
        {
            K=K+K/100;
            M++;
        }
        cout<<M<<endl;
    }
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P) {
  int i = 0;
  for ( int j = 0; j < k; j++ ) {
    llong s = 0;
    while( s + T[i] <= P) {
      s += T[i];
      i++;
      if ( i == n ) return n;
    }
  }
  return i;
}

int solve() {
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while ( right - left > 1 ) {
    mid = (left + right) / 2;
    int v = check(mid);
    if ( v >= n ) right = mid;
    else left = mid;
  }

  return right;
}

int main() {
  cin >> n >> k;
  for ( int i = 0; i < n; i++ ) cin >> T[i];
  llong ans = solve();
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3880
#include <stdio.h>

int func(int,int);

int n,A[100];
int main()
{
  int i,m,l;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      scanf("%d",&l);
      if(func(0,l)) printf("yes\n");
      else printf("no\n");
    }
  return 0;
}

int func(int i,int j)
{
  if(j==0) return 1;
  if(i>=n) return 0;
  if(func(i+1,j)||func(i+1,j-A[i])) return 1;
}
  

Measured memory_bytes: 2660
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 #include <iomanip>
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int n,m;
void solve(istream& cin, ostream& cout) {
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll sum = 0;
	sum += min(a, k);
	k -= min(a,k);
	k -= min(b,k);
	sum -= min(c, k);
	k -= min(c,k);
	cout << sum <<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 3164
N=2*10**6+1
mod=10**9+7
fac=[1]*(N+1)
for i in range(1,N+1):
    fac[i]=fac[i-1]*i%mod
inv_fac=[1]*(N+1)
inv_fac[N]=pow(fac[N],mod-2,mod)
for i in range(N-1,0,-1):
    inv_fac[i]=inv_fac[i+1]*(i+1)%mod
def nCr(n,r):
    if n<=0 or r<0 or r>n:
        return 0
    return fac[n]*inv_fac[r]%mod*inv_fac[n-r]%mod

r1,c1,r2,c2=map(int,input().split())
w=r2-r1
h=c2-c1
ans=nCr(r1+c1,r1)
for i in range(r1+1,r2+1):
    ans=(ans+(nCr(i+c1,i)*nCr(r2-i+1+h,h)%mod))%mod
for i in range(c1+1,c2+1):
    ans=(ans+(nCr(i+r1,i)*nCr(c2-i+1+w,w)%mod))%mod
print(ans)

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

using namespace std;

int main()
{
    map<int, int> mp;
    int n, x;
    int c = 0;

    cin >> n;

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

    for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        if (itr->second % 2 == 1)
            c++;
    }
    cout << c << endl;
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> w(n);
  for (int& e: w) cin >> e;
  int ans = 1e+9;
  for (int i = 0; i < n; i++) {
    int s_start = 0, s_end = 0;
    for (int j = 0; j < i; j++) {
      s_start += w.at(j);
    }
    for (int j = i; j < n; j++) {
      s_end += w.at(j);
    }
    ans = min(ans, abs(s_start - s_end));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// 解き直し.
// https://img.atcoder.jp/cf17-final/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAX = 202020;
char c[MAX];
int d[MAX], connection[MAX];

struct UnionFind{
    vector<int> parent, rank, sub;
    UnionFind(int n = 1){
        parent.resize(n + 1); rank.resize(n + 1); sub.resize(n + 1);
        rep(i, n + 1) parent[i] = i, rank[i] = 0, sub[i] = 1;
    }
    int root(int x){
        if(parent[x] == x) return x;
        else               return parent[x] = root(parent[x]);
    }
    bool isSame(int x, int y){
        return root(x) == root(y);
    }
    bool merge(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) ++rank[x];
        parent[y] = x;
        sub[x] += sub[y];
        return true;
    }
    int size(int x){
        return sub[root(x)];
    }
};

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%s %d", c, &N);
    string S(c);
    S.pb('a');
    S.insert(0, "a");
    // printf("%s\n", S.c_str());
    
    // 2. 隣接の差を配列に保存.
    // ex.
    // bixzja
    // -> abixzjaa
    // -> d[7] = {1, 7, 15, 2, 10, 17, 0}
    int s = S.size();
    rep(i, s - 1) d[i] = 26 + (S[i + 1] - 'a') - (S[i] - 'a'), d[i] %= 26;
    // rep(i, s - 1) printf("%d ", d[i]);
    // printf("\n");
    
    // 3. Union-Find木 に 頂点情報 を 保存.
    UnionFind uf(MAX);
    // 入力で与えられた区間.
    int l, r;
    rep(i, N){
        scanf("%d %d", &l, &r);
        // 解説通りになるが, 差を取る前の数列 {0, 0, 0, 0} -> {0, 1, 1, 1} は,
        // 差の列で考えると, {0, 0, 0, 0, 0} -> {0, 1, 0, 0, -1} と見るので,
        // 右側 の index が, 1 増えることに注意, なので, l-- だけを残す形に修正.
        // l--, r--;
        l--;
        uf.merge(l, r);
    }
    // 回文判定のための区間.
    rep(i, s / 2) uf.merge(i, s - 2 - i);
    
    // 4. 各連結成分内の和を確認.
    // -> 各部分木の頂点で, 連結性を識別.
    int v;
    rep(i, s - 1){
        v = uf.root(i);
        connection[v] += d[i];
        connection[v] %= 26;
        // printf("v=%d i=%d\n", v, i);
    }
    
    // 5. 回文判定.
    int ok = 0;
    rep(i, s) ok += connection[i];
    // rep(i, s) printf("%d ", connection[i]);
    // printf("\n");
    
    // 6. 出力.
    if(!ok) puts("YES");
    else    puts("NO");
    return 0;
    
}

Measured memory_bytes: 3584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static ArrayList<Item> items;

	public static void main(String[] args) throws Exception {
		while (true) {
			int N = sc.nextInt();
			int U = sc.nextInt();
			if (N == 0 && U == 0) break;
			items = new ArrayList<Item>();
			ArrayList<ArrayList<Integer>> c = new ArrayList<ArrayList<Integer>>();
			for (int i = 0; i < N; ++i) {
				Item item = new Item(sc.nextInt());
				items.add(item);
				ArrayList<Integer> cs = new ArrayList<Integer>();
				int k = sc.nextInt();
				for (int j = 0; j < k; ++j) {
					int r = sc.nextInt();
					cs.add(r);
				}
				c.add(cs);
			}
			for (int i = 0; i < N; ++i) {
				for (int j : c.get(i)) {
					items.get(i).parent.add(items.get(j));
					items.get(j).child.add(items.get(i));
				}
			}
			ArrayList<Item> sorted = sort();
			for (int i = 0; i < N; ++i) {
				sorted.get(i).index = i;
			}
			int ans = N;
			int[] units = new int[1 << N];
			Arrays.fill(units, -1);
			units[0] = 0;
			for (int i = 0; i < N; ++i) {
				int mask = sorted.get(i).mask() - (1 << i);
				for (int j = 0; j < (1 << i); ++j) {
					if (units[j] == -1 || (j & mask) != mask) continue;
					int newUnits = units[j] + sorted.get(i).unit;
					units[j + (1 << i)] = newUnits;
					int count = Integer.bitCount(j) + 1;
					if (newUnits >= U && count < ans) {
						ans = count;
					}
				}
			}
			System.out.println(ans);
		}
	}

	static ArrayList<Item> sort() {
		ArrayList<Item> sorted = new ArrayList<Item>();
		for (int i = 0; i < items.size(); ++i) {
			dfs(sorted, items.get(i));
		}
		Collections.reverse(sorted);
		return sorted;
	}

	static void dfs(ArrayList<Item> sorted, Item cur) {
		if (cur.visited) return;
		cur.visited = true;
		for (Item c : cur.child) {
			dfs(sorted, c);
		}
		sorted.add(cur);
	}

	static class Item {
		int unit;
		ArrayList<Item> child = new ArrayList<Item>();
		ArrayList<Item> parent = new ArrayList<Item>();
		boolean visited = false;
		int index;

		Item(int c) {
			this.unit = c;
		}

		int mask() {
			int ret = 1 << index;
			for (Item p : parent) {
				ret |= p.mask();
			}
			return ret;
		}

		public String toString() {
			return this.index + " " + this.unit + " " + this.child;
		}

	}

}

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m;
    a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2, HELL)
#define size(a) (int) a.size()

vector<int> getFactors(int n) {
    vector<int> factors = { 1 };
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            factors.push_back(i);
            if (i * i != n) {
                factors.push_back(n / i);
            }
        }
    }
    return factors;
}

int32_t main() { fastio;
	int n, k;
	cin >> n >> k;
	vector<int> arr(k + 1);
	for (int i = 1; i <= k; i++) {
		arr[i] = fastpow(k / i, n, HELL);
	}
	for (int i = k; i >= 2; i--) {
		vector<int> facts = getFactors(i);
		for (auto f : facts) {
			arr[f] = (arr[f] - arr[i] + HELL) % HELL;
		}
	}
	int res = 0;
	for (int i = 1; i <= k; i++) {
		res = (arr[i] * i + res) % HELL;
	}
	cout << res << endl;
    return 0;
}


Measured memory_bytes: 3992
#include<stdio.h>
int main()
{
    int n,a,b,c;
    scanf("%d%d",&n,&a);
    c=n%500;
    if(c==0||a>=n||c<a)
    {
        printf("Yes");

    }
    else

        {
            printf("No");
        }
    return 0;


}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_H 50
#define MAX_W 50
#define MAX_S 10
 
struct State{
    int d,x,y,s,f;
    State(int d,int x,int y,int s,int f) :
	d(d),x(x),y(y),s(s),f(f) {}
};
 
char M[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W][1<<MAX_S][2];
 
int getFloor(int x,int y,int f){
    if(M[y][x] == '|') return f;
    if(M[y][x] == '_' || islower(M[y][x])){
	return 0;
    }
    return 1;
}
 
int main(){
    int H,W,sx,sy,gx,gy,S;
    char MS[MAX_H][MAX_W][MAX_S];
    cin >> W >> H;
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    cin >> M[i][j];
	    if(M[i][j] == '%'){
		M[i][j] = '_';
		sx = j; sy = i;
	    }
	    if(M[i][j] == '&'){
		M[i][j] = '_';
		gx = j; gy = i;
	    }
	}
    }
    cin >> S;
    for(int i = 0 ; i < S ; i++){
	for(int j = 0 ; j < H ; j++){
	    for(int k = 0 ; k < W ; k++){
		cin >> MS[j][k][i];
	    }
	}
    }
    int ans = -1;
    memset(visited,false,sizeof(visited));
    visited[sy][sx][0][0] = true;
    const int dx[] = {-1,0,1,0};
    const int dy[] = {0,-1,0,1};
    queue<State> Q;
    Q.push(State(0,sx,sy,0,0));
    while(!Q.empty()){
	State s = Q.front(); Q.pop();
	int x = s.x, y = s.y;
	if(x == gx && y == gy){
	    ans = s.d;
	    break;
	}
	if(islower(M[y][x])){
	    int sw = M[y][x] - 'a';
	    int next = s.s ^ (1<<sw);
	    int nf = s.f;
	    if(MS[y][x][sw] == '*'){
		nf = 1-nf;
	    }
	    if(!visited[y][x][next][nf]){
		visited[y][x][next][nf] = true;
		Q.push(State(s.d+1,x,y,next,nf));
	    }
	}
	if(isupper(M[y][x])){
	    int sw = M[y][x] - 'A';
	    int next = s.s ^ (1<<sw);
	    int nf = s.f;
	    if(MS[y][x][sw] == '*'){
		nf = 1-nf;
	    }
	    if(!visited[y][x][next][nf]){
		visited[y][x][next][nf] = true;
		Q.push(State(s.d+1,x,y,next,nf));
	    }
	}
	if(M[y][x] == '|'){
	    int next = 1-s.f;
	    if(!visited[y][x][s.s][next]){
		visited[y][x][s.s][next] = true;
		Q.push(State(s.d+1,x,y,s.s,next));
	    }
	}
	for(int i = 0 ; i < 4 ; i++){
	    int nx = x + dx[i];
	    int ny = y + dy[i];
	    int f = s.f;
	    if(0 > nx || W <= nx || 0 > ny || H <= ny){
		continue;
	    }
	    if(M[ny][nx] == '#') continue;
	    int nf = getFloor(nx,ny,f);
	    for(int j = 0 ; j < S ; j++){
		if((s.s >> j) & 1){
		    if(MS[ny][nx][j] == '*'){
			nf = 1 - nf;
		    }
		}
	    }
	    if(f == nf && !visited[ny][nx][s.s][nf]){
		visited[ny][nx][s.s][nf] = true;
		Q.push(State(s.d+1,nx,ny,s.s,nf));
	    }
	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n],b[n];
    f(i,0,n){
        cin >> a[i] >> b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    if(n&1){
        int id = (n)/2;
        cout << b[id] - a[id] + 1;
    }
    else{
        int id = (n-1)/2;
        cout << b[id] + b[id+1] - a[id] - a[id+1] + 1;
    }
    return 0;
}
 

Measured memory_bytes: 6776
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    int x;
    String e, str;
    int card[] = new int[52];
    for (int i = 0; i < 52; i++) {
      card[i] = 0;
    }
    int n = Integer.parseInt(buf.readLine());
    for (int i = 0;i < n; i++) {
      str = buf.readLine();
      e = str.split(" ", 0)[0];
      x = Integer.parseInt(str.split(" ", 0)[1]);
      if (e.equals("S")) {
        card[x-1] = 1;
      } else if (e.equals("H")) {
        card[x+12] = 1;
      } else if (e.equals("C")) {
        card[x+25] = 1;
      } else {
        card[x+38] = 1;
      }
    }
    for (int i = 0; i < 52; i++) {
      if (card[i] == 0) {
        if (i < 13) {
          str = String.valueOf(i+1);
          System.out.println("S "+str);
        } else if (i < 26) {
          str = String.valueOf(i-12);
          System.out.println("H "+str);
        } else if (i < 39) {
          str = String.valueOf(i-25);
          System.out.println("C "+str);
        } else {
          str = String.valueOf(i-38);
          System.out.println("D "+str);
        }
      }
    }
  }
}

Measured memory_bytes: 24392
#include<iostream>
#include<cmath>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#include<time.h>
#include<stack>
#define inf 0x3f3f3f3f
#define maxn 20000001
#define inp(x, y) scanf("%d%d", &x, &y)
#define in(x) scanf("%d", &x)
#define ins(str) scanf("%s", str)
#define ind(x) scanf("%lf", &x)
#define out(x) printf("%d\n", x)
#define outp(x, y) printf("%d %d\n", x, y)
#define mem(x, v) memset(x, v, sizeof(x))
#define rep(i, a, b) for(i = a; i <= b; i++)
#define repd(i, a, b) for(i = a; i >= b; i--)
#define gc getchar()
#define pii pair<ll, ll>
#define vi vector<ll>
#define inl(x) scanf("%lld", &x)
#define outl(x) printf("%lld\n", x)
#define inull(x) scanf("%llu", &x)
#define outull(x) printf("%llu\n", x)
#define eps 1e-10
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct edge
{
    int v, w;
    edge(int v, int w)
    {
        this->v = v;
        this->w = w;
    }
};
vector<edge> eg[100005];
ll dis[100005];
int vis[100005];
void dfs(int id)
{
    vis[id] = 1;
    for (int i = 0; i < eg[id].size(); i++)
    {
        int v = eg[id][i].v;
        int w = eg[id][i].w;
        if (!vis[v])
        {
            dis[v] = dis[id] + w;
            dfs(v);
        }
    }
}
int main()
{
    int n;
    in(n);
    mem(dis, 0);
    mem(vis, 0);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v, c;
        inp(u, v);
        in(c);
        eg[u].push_back(edge(v, c));
        eg[v].push_back(edge(u, c));
    }
    int q, k;
    inp(q, k);
    dfs(k);
    for (int i = 0; i < q; i++)
    {
        int a, b;
        inp(a, b);
        cout << dis[a] + dis[b] << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll x, k, d;
  cin>>x>>k>>d;
  if(x<0){
    x=-x;
  }
  ll cnt=x/d;
  if(k<=x/d){
    cout<<x-d*k<<'\n';
    return 0;
  }
  if((k-cnt)%2==0){
    cout<<x-x/d*d<<'\n';
    return 0;
  }
  cout<<abs(x-(x/d+1)*d)<<'\n';
  return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    cin >> n >> q;
    
    string s;
    cin >> s;
    
    int prefix[200000] = {0};
    for (int i = 1; i < s.length(); i++){
        prefix[i] = prefix[i - 1];
        if (s[i] == 'C' && s[i - 1] == 'A')
            prefix[i] += 1;
    }

    for (int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << prefix[r - 1] - prefix[l - 1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 1872
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val (n, m) = readIntList()
    val res = Array(n + 1) { -1 }

    for (i in 0 until m) {
        val (s, c) = readIntList()
        if (res[s] != -1 && res[s] != c) {
            println(-1)
            return
        }
        res[s] = c
    }

    for (i in 1..n) {
        if (res[i] == -1) {
            if (i == 1 && n != 1) {
                res[i] = 1
            } else {
                res[i] = 0
            }
        }
    }

    if (res[1] == 0 && n != 1) {
        println(-1)
    } else {
        println(res.drop(1).joinToString(separator = ""))
    }
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int k;
    cin >> k;

    int ans;
    if(k%2 == 1){
        ans = (k/2+1)*(k/2);
    }
    else{
        ans = (k/2) * (k/2);
    }

    ppp(ans);

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define deb(a) cout<<#a<<" "<<a<<endl
#define WW 100000
#define INF 1000000000000000000 //1e18
#define EPS 0.000000001 //1e-9
//get<a>(t) gives ath element of tuple named t, numbering starts from 0
//max({_,......,_}) can give maximum of any number of elements. Similarly min also.
//don't forget to initialise freq arrays
//reverse(all(v)) would reverse a vector  
//pow(10.0, 2.0) can give exactly 100.0, slightly greater, or slightly less. 
//Therefore use(int)(pow(10.0,zz)+EPS)
int32_t main()
{
    IOS;
    int n; cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n+10]={};
    dp[0]=0;
    if(n==1)
        {cout<<"0"; return 0;}
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

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

int main() {
    char alpha;
    cin >> alpha;
    vector<char> S;
    vector<char> L;
    S = {'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'};
    L = {'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'};
    for (int i=0; i<26; i++) {
        if (alpha == S.at(i)) {
            cout << 'a' << endl;
            exit(0);
        }
        else if (alpha == L.at(i)) {
            cout << 'A' << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3636
N = input()
length = len(N)

count = 0
last = 0
for i in range(length-1):
    last = i
    if i % 2 == 0:
        count += 9*(10**i)

number = int(N)
if length == 1:
    count = number
elif last%2 == 1:
    count += number + 1 - 10**(last+1)
print(count)

Measured memory_bytes: 38256
#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N, L; cin >> N >> L;
  vi32 a(N); cin >> a;
  int ma = -1, in = -1;
  rep(i, N - 1) if (ma < a[i + 1] + a[i]) in = i, ma = a[i + 1] + a[i];
  if (ma >= L) {
    cout << "Possible" << '\n';
    rep(i, N - 1) if (i != in) cout << i + 1 << '\n'; else break;
    rrep(i, N - 1) if (i != in) cout << i + 1 << '\n'; else break;
    cout << in + 1 << '\n';
  } else {
    cout << "Impossible" << '\n';
  }
}


Measured memory_bytes: 1280
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d, e, f = list(map(int, input().rstrip('\n').split()))
    mt = a * 100
    ms = 0
    mn = 0
    for i in range(0, f + 1, a * 100):
        for j in range(0, f - i + 1, b * 100):
            for k in range(0, f - i - j + 1, c):
                for l in range(0, f - i - j - k + 1, d):
                    t = i + j
                    s = k + l
                    if 0 < t + s <= f:
                        if s / (t + s) <= e / (100 + e):
                            if s / (t + s) > mn:
                                mn = s / (t + s)
                                mt = t
                                ms = s
    print(mt + ms, ms)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39828
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    i64 a, b;
    cin >> a >> b;
    cout << a * b / __gcd(a, b) << endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long n,k,ans;
  scanf("%ld%ld",&n,&k);
  ans=n/k;
  ans=ans*(n/k);
ans=ans*(n/k);
long b;
if(k%2==0){
n+=k/2;
b=n/k;
b=b*(n/k);
b=b*(n/k);
ans+=b;
}
     printf("%ld\n",ans);
return 0;
} 


Measured memory_bytes: 128
n,k = map(int, input().split())
ans = 0
# a % b = k
for i in range(k+1,n+1):
    t = n // i
    s = max(n - (t*i + k) + (1 if k else 0),0)
    # print(s, t*i + k, n,  t*i)
    ans += t * (i-k) + s
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main(){
  int n, k;
  cin >> n;
  string M[n];
  int r[n];
  vector< vector<int> > V(n);
  for(int i = 0; i < n; ++i){
    cin >> k >> M[i];
    if(k) V[k-1].push_back(i);
  }
  stack< pair<int,int> > st;
  st.push(make_pair(0,0));
  while(!st.empty()){
    int d = st.top().first, t = st.top().second;
    st.pop();
    cout << string(d,'.') + M[t] << endl;
    ++d;
    for(int i = V[t].size()-1; i >= 0; --i)
      st.push(make_pair(d,V[t][i]));
  }
  return 0;
}

Measured memory_bytes: 3372
import sys

def change_10to5(x, y):
    """
    10000円札を5000円札2枚に崩す．結果的に1枚増やす.

    :param x:10000円札の枚数
    :param y:5000円札の枚数
    :return: 演算後の10000円札と5000円札の枚数
    """

    x -= 1
    y += 5

    return x, y


def change_5to1(y, z):
    """
    5000円札を1000円札に崩す.
    4枚増やす.
    """

    y -= 1
    z += 5

    return y, z


def change_1to5(z, y):
    """
    1000円札5枚を5千円札1枚にまとめる．4枚減らす．
    :param z: 1000円札の枚数．
    :param y: 5000円札の枚数．
    :return: 演算後の1000円札と5000円札の枚数．
    """

    z -= 5
    y += 1

    return z, y


def change_5to10(y, x):
    """
    5000円札2枚を10000円札にする．
    1枚減らす．
    """

    y -= 2
    x += 1

    return y, x


def main():
    n, y_input = map(int, input().split())
    cash_num = y_input // 1000
    x = 0
    y = 0
    z = cash_num

    while True:
        if cash_num > n:
            if cash_num - n >= 4 and z >= 5:
                z, y = change_1to5(z, y)
                cash_num -= 4
            elif cash_num - n >= 1 and y >= 2:
                y, x = change_5to10(y, x)
                cash_num -= 1
            else:
                print("-1 -1 -1")
                sys.exit()
        elif cash_num < n:
            if n - cash_num >= 4 and y > 0:
                y, z = change_5to1(y, z)
                cash_num += 4
            elif n - cash_num >= 1 and x > 0:
                x, y = change_10to5(x, y)
                cash_num += 1
            else:
                print("-1 -1 -1")
                sys.exit()
        else:
            if n == cash_num:
                print("{} {} {}".format(x, y, z))
                break
            else:
                print("-1 -1 -1")
                break


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000

// ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;

int main(int argc, char const *argv[])
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	printf("%s\n", (c >= a && c <= b) ? "Yes" : "No");
	return 0;
}


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

int main(){
	int n,a,b,sum = 0;
	cin >> n >> a >> b;
	for(int i = 1;i <= n;i++){
		int t = i,tmp = 0;
		while(t){
			tmp += t % 10;
			t /= 10;
		}
		if(a <= tmp && tmp <= b) sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) insert(key);
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key);
      }
    }
  }

  printList();

  return 0;
}


Measured memory_bytes: 36116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int ab = Math.min(a + b, c * 2);
		
		int ans = Math.min(x, y) * ab;
		
		if (x > y) {
			ans += (x - y) * Math.min(a, c * 2);
		} else {
			ans += (y - x) * Math.min(b, c * 2);
		}
		
		System.out.println(ans);
	}	
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    int ab, bc, ca;
    scanf("%d %d %d", &ab, &bc, &ca);
    /* ====================================== */
    int ans;
    if (ab > bc && ab > ca) {
        ans = bc * ca / 2;
    } else if (bc > ab && bc > ca) {
        ans = ab * ca / 2;
    } else {
        ans = ab * bc / 2;
    }

    cout << ans;
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 888
from itertools import accumulate

N, K = map(int, input().split())
ps = list(map(int, input().split()))

Es = [p*(p+1)/2/p for p in ps]

accEs = list(accumulate([0]+Es))

ans = 0
for i in range(N-K+1):
    e = accEs[i+K] - accEs[i]
    ans = max(ans, e)

print(ans)


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

#define int long long
const int M = 1e9 + 7;
vector<vector<int>> g, dp;

void dfs(int x, int par) {
  for (auto v : g[x]) {
    if (v == par) continue;
    dfs(v, x);
    dp[x][0] = dp[x][0] * ((dp[v][1] + dp[v][0]) % M) % M;
    dp[x][1] = dp[x][1] * dp[v][0] % M;
  }
}

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

  int n;
  cin >> n;

  g.resize(n);
  dp.assign(n, vector<int> (2, 1));
  
  if (n == 1) {
    cout << 2 << '\n';
    return 0;
  }

  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v; 
    --u; --v;

    g[u].push_back(v);
    g[v].push_back(u);
  }

  dfs(0, 0);
  cout << (dp[0][0] + dp[0][1]) % M << '\n';
}


Measured memory_bytes: 21088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // bit全探索
    ll N, M;
    cin >> N >> M;
    vector<int> S[M];
    rep(i, M) {
        ll k;
        cin >> k;
        vector<int> A(k);
        rep(i, k) cin >> A[i];
        rep(i, k) --A[i];
        S[i] = A;
    }
    vector<int> L(M);
    rep(i, M) cin >> L[i];
    ll ans = 0;        
    for (int bit = 0; bit < (1<<N); bit++) {
        vector<int> cnt(M);
        for (int i = 0; i < N; i++) {
            if ((bit>>i) & 1) {
                // i番目のスイッチがon   // 0-indexed
                for (int j = 0; j < M; j++) {
                    if (count(S[j].begin(), S[j].end(), i)) {
                        cnt[j] ^= 1;
                    }
                }
            }
        }
        ll temp = 0;
        rep(i, M) {
            if (L[i] == cnt[i]) temp++;
        }
        if (temp == M) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#define LEN 100000

typedef struct pp{
char name[100];
int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int a,int b){
  return a<b ? a:b;
}

int main(){
  int elaps=0,c;
int i,q;
P u;
scanf("%d %d",&n,&q);

for(i=1;i<=n;i++){
  scanf("%s",Q[i].name);
  scanf("%d",&Q[i].t);
}
head=1;
tail=n+1;
while(head!=tail){
  u=dequeue();
  c=min(q,u.t);
  u.t -= c;
elaps += c;
if(u.t>0)enqueue(u);
else{
  printf("%s %d\n",u.name,elaps);
}
}
return 0;
}



Measured memory_bytes: 11844
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){
	
	int n, d, x, a[100], ans=0;
	cin >> n >> d >> x;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}

	for(int i=0; i<n; i++){
		int day=1;
		while(day<=d){
			if(day<=d){
				ans++;
			}
			day+=a[i];
		}
	}
	cout << ans+x << endl;

  return 0;
}

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

int main(){
	string s,ans="";
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='0'){
			ans.push_back('0');
		}else if(s[i]=='1'){
			ans.push_back('1');
		}else if(ans.size()>0){
			ans.pop_back();
		}
	}
	cout << ans;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  ll a, b; cin >> a >> b;
  if(a > 0) cout << "Positive" << endl;
  else if(a <= 0 && b >= 0) cout << "Zero" << endl;
  else if(a < 0 && b < 0) {
    int tmp = b - a + 1;
    if(tmp % 2 == 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define f first
#define s second
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast(){cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);}
ll power(ll x,ul y,ll p){ll res = 1;x = x % p;if(x == 0)return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}

int main(){
fast();
ll x;
cin>>x;
ll sum=100;
for(ll i=1;i<10000000;i++)
{
    sum = sum + sum/100;
    if(sum>=x){
    cout<<i<<endl;
    break;
    }
}
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a + b == 15){
		cout << '+' << endl;
	} else if(a * b == 15){
		cout << '*' << endl;
	} else {
		cout << 'x' << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int hit, blow;
  int a[4], b[4];

  while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
    cin >> b[0] >> b[1] >> b[2] >> b[3];
    hit = blow = 0;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        if (a[i] == b[j]) (i == j) ? hit++ : blow++;
    cout << hit << " " << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
n = int(input())
#n = [int(i) for i in readline().split()]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 

#from collections import deque

cnt = [-1]*n
parent = [-1]*n

q = [0]
order = []
while q:
    v = q.pop()
    order.append(v)
    for c in g[v]:
        if parent[v] != c:
            parent[c] = v
            q.append(c)

MOD = 10**9+7

pow2 = [1]
for i in range(n):
    pow2.append(pow2[-1]*2%MOD)


num = [0]*n
ans = 0
for v in reversed(order):
    res = 1
    nokori = n-1
    for c in g[v]:
        if c != parent[v]:
            nc = num[c]+1
            res += pow2[nc] - 1
            num[v] += nc
            nokori -= nc
            #print(c,v,nc)
    res += pow2[nokori] - 1
    #print(res,nokori)
    ans += pow2[n-1]-res 

#print(parent)
#print(num)
#print(pow2)

R = (MOD+1)//2

print(ans*pow(R,n,MOD)%MOD)


            
            
        
    
    






Measured memory_bytes: 59296
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7,MAXL=25;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x=0,y=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=i){
			if(y!=0)
				x+=(y/2)+(y%2);
			y=0;
		}
		else
			y++;
	}
	x+=(y/2)+(y%2);
	cout<<x;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    bool ok = abs(c - a) <= d || (abs(c - b) <= d && abs(b - a) <= d);
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;


int main()
{
	int k, n;
	cin >> n>>k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];
	ll ans = 3 + 1e9;;
	sort(h.begin(), h.end());
	rep(i, n-k+1) {
		ll cn = h[i + k-1] - h[i];
		ans = min(ans, cn);
	}
	cout << ans;
}

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

int main() {
	long long n;
	cin >> n;
	vector<long long>a(n);
	rep(i, n)cin >> a[i];
	long long ans = 0;
	long long res = 0;
	rep(i, n-1) { 
		if (a[i] >= a[i + 1])++res;
		else {
			ans = max(ans, res);
			res = 0;
		}
	}
	if (res > ans)ans = res;
	cout << ans << endl;
}

Measured memory_bytes: 1024