akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, k, a[N], sum[N];
unordered_map <int,int> cnt;
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1;i<=n;i++) 
 	{
 		cin >> a[i];
 		a[i] %= k;
 		sum[i] = (sum[i-1] + a[i])%k;
 	}
 	for(int i=0;i<=n;i++) 
	{
		sum[i] = (sum[i]-i+k)%k;
		sum[i] = (sum[i]+k)%k;
	}
 	for(int i=0;i<=min(n,k-1);i++) 
 		cnt[sum[i]]++;
 	ll ans = 0;
 	for(int i=0;i<=n;i++)
 	{
 		cnt[sum[i]]--;
 		ans += cnt[sum[i]];
 		if(i+k<=n) cnt[sum[i+k]]++;
 	}
 	cout << ans;
	return 0;
}


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

int main() {
  string ss;
  cin >> ss;
  
  int count=0;
  for(int i=0; i<ss.size(); i++){
    if(ss.at(i) == '1'){
      count++;
    }
  }
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    if(n%2==0)cout<<n<<endl;
    else{cout<<n*2<<endl;}


    return 0;
}


Measured memory_bytes: 256
import fractions

a, b, c, d = map(int, input().split())
lcm = c*d//fractions.gcd(c, d)

c_num = b//c - (a-1)//c
d_num = b//d - (a-1)//d
lcm_num = b//lcm - (a-1)//lcm

ans = c_num + d_num - lcm_num

print(b-a+1-ans)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
int n, a, b, ans;
int cnt(int x)
{
    int ans = 0;
    while (x)
        ans += x % 10, x /= 10;
    return ans;
}
int main()
{
    scanf("%d %d %d", &n, &a, &b);
    for (int i = 1; i <= n; i++)
        if (cnt(i) >= a && cnt(i) <= b)
            ans += i;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    
    if(a<b){printf("a < b\n");}
    if(a>b){printf("a > b\n");}
    if(a==b){printf("a == b\n");}
    
}



Measured memory_bytes: 2144
#!/usr/bin/env python3
H, W = map(int, input().split())
a = [''] * H
cnt = 0
for i in range(H):
    a[i] = list(input())
    cnt += len(list(filter(lambda x: x == '#', a[i])))

ans = False
if cnt == H + W - 1:
    y, x = 0, 0
    d = [1, 0, 1]
    for i in range(cnt):
        if y == H - 1 and x == W - 1:
            ans = True
            break
        for j in range(2):
            ny = y + d[j]
            nx = x + d[j + 1]
            if ny < H and nx < W and a[ny][nx] == '#':
                y, x = ny, nx
                break



print('Possible' if (ans) else 'Impossible')


Measured memory_bytes: 3188
DP = Array.new(101) { {} }

readlines.tap do |nw, *rest|
  N, W = nw.split.map(&:to_i)
  ws, vs = rest.map { |line| line.split.map(&:to_i) }.transpose

  solve = ->i, v {
    DP[i][v] =
      case
      when DP[i][v]
        DP[i][v]
      when i == N
        0
      when v < ws[i]
        solve.(i+1, v)
      else
        [solve.(i+1, v), solve.(i+1, v - ws[i]) + vs[i]].max
      end
  }

  puts solve.(0, W)
end

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

#define rep(i,n) for(int i=0;i<n;i++)

string str;
int ans;

class dice{
public:
	int n[6];
	void E(){
		int t = n[0];
		n[0] = n[3];
		n[3] = n[5];
		n[5] = n[2];
		n[2] = t;
	}
	void W(){
		int t = n[0];
		n[0] = n[2];
		n[2] = n[5];
		n[5] = n[3];
		n[3] = t;
	}
	void S(){
		int t = n[0];
		n[0] = n[4];
		n[4] = n[5];
		n[5] = n[1];
		n[1] = t;
	}
	void N(){
		int t = n[0];
		n[0] = n[1];
		n[1] = n[5];
		n[5] = n[4];
		n[4] = t;
	}
};


int main(){
	dice d;
	rep(i, 6) cin >> d.n[i];
	cin >> str;
	ans = d.n[0];
	rep(i, str.length()){
		switch (str[i])
		{
		case 'E':
			d.E();
			break;
		case 'W':
			d.W();
			break;
		case 'S':
			d.S();
			break;
		case 'N':
			d.N();
			break;
		default:
			break;
		}
	}
	cout << d.n[0] << endl;
	return 0;
}

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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}
char grid[200][200];
int check[200][200];
int main()
{
    int h, w;
    cin >> h >> w;

    Rep(i, 1, h) { Rep(j, 1, w) cin >> grid[i][j]; }
    //mem(check, 1e9);
    Rep(i, 1, h)
    {
        Rep(j, 1, w) check[i][j] = 1e9;
    }

    if (grid[1][1] == '#')
        check[1][1] = 1;
    else
        check[1][1] = 0;

    Rep(i, 1, h)
    {
        Rep(j, 1, w)
        {

            if (i + 1 <= h)
            {
                check[i + 1][j] = min(check[i + 1][j], check[i][j] + (int)(grid[i][j] != grid[i + 1][j]));
            }
            if (j + 1 <= w)
            {

                check[i][j + 1] = min(check[i][j + 1], check[i][j] + (int)(grid[i][j] != grid[i][j + 1]));
            }
        }
    }
/*
    Rep(i, 1, h)
    {
        Rep(j, 1, w) cout << check[i][j] << " ";
        cout << "\n";
    }*/
    cout << (check[h][w] + 1) / 2;
    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
class finite_field {
  const int md;
  const int sz;
  vector<int> fct, fnv;
  void init () {
    if (sz) {
      fct[0] = 1;
      for (int i = 1; i < sz; i++) fct[i] = prod(fct[i - 1], i);
      fnv[sz - 1] = inv(fct[sz - 1]);
      for (int i = sz - 1; i >= 1; i--) fnv[i - 1] = prod(fnv[i], i);
    }
  }
  public:
    finite_field(
        const int md,
        const int init_factorial_size = 0,
        const int init_power_size = 0
      ) :
      md(md), sz(init_factorial_size),
      fct(sz), fnv(sz)
      {
        init();
      }
    inline void add (int& a, const int b) const {
      a += b;
      if (a >= md) a -= md;
    }
    inline void sub (int& a, const int b) const {
      a -= b;
      if (a < 0) a += md;
    }
    template<class... A> inline int sum (A... args) const {
      int ret = 0;
      for (int a : initializer_list<int>{args...}) {
        add(ret, a);
      }
      return ret;
    }
    inline int dif (int a, int b) const {
      sub(a, b);
      return a;
    }
    inline int prod (int a, int b) const {
      return (long long)a * b % md;
    }
    template <typename... Args>
    inline int prod (Args... args) const {
      long long ret = 1;
      for (int a : initializer_list<int>{args...}) {
        ret *= a;
        ret %= md;
      }
      return (int)ret;
    }
    void mul (int& a, int b) const {
      a = prod(a, b);
    }
    inline int inv (int a) const {
      a %= md; if (a < 0) a += md;
      int b = md, u = 0, v = 1;
      while (a) {
        int t = b / a;
        b -= a * t; swap(a, b);
        u -= v * t; swap(u, v);
      }
      assert(b == 1);
      if(u < 0) u += md;
      return u;
    }
    inline int quat (int a, int b) const {
      return prod(a, inv(b));
    }
    inline void div (int& a, int b) const {
      a = quat(a, b);
    }
    inline int pow (int a, long long b) {
      int ret = 1;
      for (; b; b >>= 1) {
        if (b & 1) mul(ret, a);
        a = prod(a, a);
      }
      return ret;
    }
    inline int binom (int n, int k) const {
      assert(0 <= n && n < sz);
      if (k < 0 || n < k) return 0;
      return prod(fct[n], fnv[k], fnv[n - k]);
    }
};
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> dp(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = a[i] > a[j] ? 1 : 0;
    }
  }
  finite_field fld(1e9 + 7);
  int inv2 = fld.inv(2);
  int coeff = fld.pow(2, q);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    auto half = [&] (int& a, int& b) -> void {
      fld.add(a, b);
      a = b = fld.prod(a, inv2);
    };
    half(dp[x][y], dp[y][x]);
    for (int z = 0; z < n; z++) if (z != x && z != y) {
      half(dp[x][z], dp[y][z]);
      half(dp[z][x], dp[z][y]);
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      fld.mul(dp[i][j], coeff);
      fld.add(ret, dp[i][j]);
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b==c+d) cout<<"Balanced"<<endl;
     if(a+b<c+d) cout<<"Right"<<endl;
     if(a+b>c+d) cout<<"Left"<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define N 1000000
#define ar array
#define mod 1000000007
#define ld long double
#define pb push_back
#define f first
#define s second
typedef long long int ll;
using namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	ll n,k,ans=0,i;
	cin>>n>>k;
	ll p[n+2]={0};
	ll s[n+2]={0};
	p[1]=0;
	s[n+1]=n;
	for(i=2;i<=n+1;i++){
		p[i]=p[i-1]+i-1;
		p[i]%=mod;
	}
	for(i=n-1;i>=0;i--){
		s[i+1]=s[i+2]+i;
		s[i]%=mod;
	} 
	for(i=k;i<=n+1;i++){
		if(s[n-i+2]>=p[i])
		ans+=s[n-i+2]-p[i]+1;
		ans%=mod;
	}
	cout<<ans;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n;
	string A, B, C;
	cin >> n >> A >> B >> C;
	int ans = 0;
	FOR(i, 0, n)
	{
		set<char> S{A[i], B[i], C[i]};
		ans += SZ(S) - 1;
	}
	cout << ans;
	return 0;
}

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

const int inf=1<<25;
int N,M,H,K,s,t;

struct node{int to,cost,hour,num;};
vector<node> graph[100];

typedef tuple<int,int,int> state;

int dijkstra(int mask){
	int dist[100][25];
	rep(i,N)rep(j,H+1) dist[i][j]=inf;
	dist[s][0]=0;
	priority_queue<state,vector<state>,greater<state>> q;
	q.push(state(0,s,0));
	while(!q.empty()){
		int c,v,t;tie(c,v,t)=q.top();q.pop();
		for(auto &e:graph[v]){
			int nc=c; if(~mask&(1<<e.num)) nc+=e.cost;
			int nv=e.to;
			int nt=t+e.hour; if(nt>H) continue;
			if(dist[nv][nt]>nc){
				dist[nv][nt]=nc;
				q.push(state(nc,nv,nt));
			}
		}
	}
	int res=inf;
	rep(i,H+1) res=min(res,dist[t][i]);
	return res;
}

int main(void){
	while(cin >> N >> M >> H >> K,N){
		rep(i,N) graph[i].clear();
		rep(i,M){
			int a,b,c,h,r;
			cin >> a >> b >> c >> h >> r;
			a--,b--,r--;
			graph[a].push_back({b,c,h,r});
			graph[b].push_back({a,c,h,r});
		}
		cin >> s >> t; s--,t--;
		int P; cin >> P;
		int dp[1<<8];
		rep(i,1<<K) dp[i]=inf;
		dp[0]=0;
		rep(i,P){
			int l,d;
			cin >> l >> d;
			int mask=0;
			rep(j,l){
				int k; cin >> k; k--;
				mask|=(1<<k);
			}
			dp[mask]=d;
		}
		rep(i,1<<K)rep(j,1<<K) if((i|j)!=i) dp[i|j]=min(dp[i|j],dp[i]+dp[j]);
		int ans=inf;
		rep(i,1<<K) ans=min(ans,dp[i]+dijkstra(i));
		cout << ((ans==inf)?-1:ans) << endl;
	}
	return 0;
}

Measured memory_bytes: 1396
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string s;
	cin >> s;
	s.at(5) = ' ';
	s.at(13) = ' ';
	cout << s << endl;
} 

Measured memory_bytes: 3628
from bisect import bisect_left
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
def f(x, s, t):
  result = float('inf')
  i = bisect_left(s, x)
  if i > 0:
    j = bisect_left(t, s[i - 1])
    if j > 0:
      result = min(result, (x - s[i - 1]) + (s[i - 1] - t[j - 1]))
    if j < len(t):
      result = min(result, (x - s[i - 1]) + (t[j] - s[i - 1]))
  if i < len(s):
    j = bisect_left(t, s[i])
    if j > 0:
      result = min(result, (s[i] - x) + (s[i] - t[j - 1]))
    if j < len(t):
      result = min(result, (s[i] - x) + (t[j] - s[i]))
  return result
for i in range(q):
  x = int(input())
  print(min(f(x, s, t), f(x, t, s)))


Measured memory_bytes: 12092
p=[[list(raw_input()) for i in range(8)],[],[],[]]
for r in range(3):
	print 90*(r+1)
	for j in range(8):
		p[r+1].append([p[r][i][j] for i in range(7,-1,-1)])
		print "".join(p[r+1][j])

Measured memory_bytes: 4216
def main():
    A, B, K = map(int, input().split())
    CDD = []
    maxi = max(A,B)
    mini = min(A,B)
    for i in reversed(range(1, mini + 1)):
        if mini % i == 0:
            if maxi % i == 0:
                CDD.append(i)
    print(CDD[K - 1])
main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
const ll MOD=1e9+7;
ll mod(ll x)
{
   return (x%MOD+MOD)%MOD;
   // works for neg and pos values of x.
}
void solve()
{
    bool x;
    cin>>x;
    cout<<!x;

}
int main()
{

//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

ll poww(long long a, long long n, long long m)
{
        long long ans = 1;
        long long mul = a;
        while (n != 0)
        {
                if (n % 2)
                {
                        ans = (ans * mul) % m;
                }
                mul = (mul * mul) % m;
                n /= 2;
        }
        return ans;
}
/* 
Fermat's little theorem: 
1) (a/b)%mod= (a*(poww(b,mod-2,mod)))%mod iff a%b==0
2) (a^b)%mod= (a^(b%(mod-1)))%mod iff mod is prime
*/
const int SZ=5e5+100;
ll factorial[SZ];
ll iv[SZ];
void precompute()
{
	factorial[0]=1;
    iv[0]=1;
	for(int i=1;i<SZ;i++)
	{
		factorial[i]=(factorial[i-1]*i)%MOD;
	    iv[i]=poww(factorial[i],MOD-2,MOD);
    }
}
ll InverseEuler(ll n, ll m)
{
    return poww(n, m - 2, m);
}
ll C(ll n, ll r,int m)
{
	if(r>n || r<0)return 0;
    return (factorial[n] * ((iv[r] * iv[n-r]) % m)) % m;
}
int32_t main()
{
	fastio();
	precompute();
	int n,m;
	cin>>n>>m;
	int ans=0;
	int flag=1;
	for(int i=0;i<=n;i++)
	{	
		int tmp=C(n,i,MOD);	
		tmp*=C(m,i,MOD);
		tmp%=MOD;
		int t2=C(m-i,n-i,MOD);
		t2*=t2;
		t2%=MOD;
		tmp*=t2;
		tmp%=MOD;
		tmp*=factorial[i];
		tmp%=MOD;
		tmp*=factorial[n-i];
		tmp%=MOD;
		tmp*=factorial[n-i];
		tmp%=MOD;
		ans+=flag*tmp;
		// tr(i,flag*tmp);
		ans%=MOD;
		if(ans<0)ans+=MOD;
		flag=-flag;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11400
mod = 10**9+7

N = int(input())

X = [1, 1, 1]
Y = [1, 2, 3]
for i in range(3, N+2):
    x = (X[-1] + Y[i-3]) % mod
    X.append(x)
    Y.append((Y[-1]+x)%mod)

ans = ((Y[N-2] * (N-2) + (Y[N-1])) * (N-1) + (N-1) * Y[N-2] + 1) % mod
print(ans)


# from itertools import product

# A = product(range(1, N+1), repeat=N)
# P = []
# for B in A:
#     ok = True
#     B = list(B) + [B[-1]]*(N+1)
#     for i in range(N):
#         b = B[i]
#         if len(set(B[i+1:i+1+b])) != 1:
#             ok = False
#             break
#     if ok:
#         P.append(B)
# print(len(P))
# for B in P:
#     print(B)

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

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

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

int main() {
    ll i, j, k;
    ll N;
    cin >> N;
    vll A(N), B(N);
    for(auto &e : A)
        cin >> e;
    for(auto &e : B)
        cin >> e;
    ll ok = false;
    ll update = false;
    ll ans = 0;
    while(!ok) {
        update = false;
        for(i = 0; i < N; i++) {
            ll le = i - 1;
            if(le < 0)
                le = N - 1;
            ll ri = i + 1;
            if(ri >= N)
                ri = 0;
            if(B[i] > A[i] && B[i] > (B[le] + B[ri])) {
                ll m = (B[i] - A[i]) / (B[le] + B[ri]);
                ans += m;
                if(m > 0)
                    update = true;
                B[i] -= m * (B[le] + B[ri]);
            }
        }
        if(update)
            continue;
        for(i = 0; i < N; i++) {
            if(A[i] != B[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
        ok = true;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxN = 1e5 + 5;
int N, e;
ll L, ans;
char s[maxN];

struct DD{
	DD* x[2];
	ll dep, idx;
	void init() {
		x[0] = x[1] = 0; idx = e;
	}
}dd[maxN]; 

struct Trie{
	DD* root; 
	DD* alloc_() {dd[e].init(); return &dd[e++];}
	void init() {e = 0; root = alloc_(); root -> dep = L;}
	void insert() {
		int len = strlen(s); DD* p = root;
		for(int i = 0, d; i < len; ++i) {
			d = s[i] - '0';
			if(p -> x[d] == 0) p -> x[d] = alloc_(), p -> x[d] -> dep = p -> dep - 1;
			p = p -> x[d];
		}
	}
}trie;

ll lowbit(ll num) {
	return num & -(num);
}

void dfs(DD* p) {
	if((p -> x[0] == 0) && (p -> x[1] == 0)) return;
	if((p -> x[0] != 0) && (p -> x[1] != 0)) {
		dfs(p -> x[0]), dfs(p -> x[1]); return;
	}
	for(int i = 0; i < 2; ++i) {
		if(p -> x[i] != 0) dfs(p -> x[i]);
		else ans ^= lowbit(p -> dep);
		//cout << lowbit(p -> dep) << ' ' << p -> idx << ' ' << p -> dep << ' ' << L << endl;
	}
}

int main() {
	scanf("%d%lld", &N, &L); trie.init(); 
	for(int i = 1; i <= N; ++i) {
		scanf("%s", s); trie.insert();
	}
	dfs(trie.root);
	if(ans != 0) printf("Alice\n");
	else printf("Bob\n");
	//while(L % 2 == 0) L /= 2;
	//cout << L << endl;
	return 0;
}

Measured memory_bytes: 4224
from collections import defaultdict as dd

n = int(input())
A = list(map(int, input().split()))
odd_ac = dd(int)
even_ac = dd(int)
for i, a in enumerate(A):
    if i % 2 == 0:
        even_ac[i] = even_ac[i-2] + a
    else:
        odd_ac[i] = odd_ac[i-2] + a
#print(odd_ac)
#print(even_ac)

ans = []
for dam in range(n):
    is_odd = dam % 2
    total = 0
    if is_odd:
        total += odd_ac[n-2] - odd_ac[dam-2]
        total -= even_ac[n-1] - even_ac[dam-1]
        total += even_ac[dam-1]
        total -= odd_ac[dam-2]
    else:
        total += even_ac[n-1] - even_ac[dam-2]
        total -= odd_ac[n-2] - odd_ac[dam-1]
        total -= even_ac[dam-2]
        total += odd_ac[dam-1]

    ans.append(total)

print(*ans, sep=" ")

Measured memory_bytes: 106080
a,b,c,d=map(float,input().split())
c-=a;d-=b
for _ in [0]*int(input()):
    x,y=map(float,input().split())
    x-=a;y-=b
    z=(c*x+d*y)/(c*c+d*d)
    print(a+c*z,b+d*z)

Measured memory_bytes: 7624
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(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;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,i;
    cin >> n >> i;
    PRINT(n-i+1);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

int main(void)
{
    //歳入力
    int N;
    cin>>N;

    //条件分岐
    if(N==2)
    {
        //2歳
        int A=0, B=0;
        cin>>A;
        cin>>B;
        cout<<A+B<<endl;
        return 0;
    }
    else if(N==1)
    {
        //1歳
        cout<<"Hello World"<<endl;
        return 0;
    }
    else
    {
        //一応その他
        return 0;
    }

    return -1;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,a[555555],b[555555];
map<int,int> M;
int main(){
	cin>>n;
	FOR(i,1,n) getint(a[i]),b[i]=a[i];
	sort(a+1,a+n+1);
	FOR(i,1,n){
		if (i-1>=(n-1)/2+1) M[a[i]]=a[(n-1)/2+1];
		else M[a[i]]=a[n-((n-1)/2+1)+1];
	}
	FOR(i,1,n) printf("%d\n",M[b[i]]);
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int n;
ll ans=1e18,X,x[N],sum[N];
int main(){
	n=read(),X=read();
	for(int i=1;i<=n;++i)sum[i]=(x[i]=read())+sum[i-1];
	for(int k=1;k<=n;++k){
		ll tmp=0;
		for(int j=1,l=0,r=n;r&&tmp+k*X<ans;++j,r=l-1){
			l=max(r-k+1,1);
			tmp+=(j==1?5:(j<<1)+1)*(sum[r]-sum[l-1]);
		}
		ans=min(ans,tmp+k*X);
	}
	printf("%lld",ans+n*X);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000003
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define input(a) for(int i=0;i<a.size();i++) cin>>a[i];
#define test int t; cin>>t; while(t--)
#define vi vector<int>
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define ff first
#define ss second
using namespace std;

void solve(){
	int n; cin>>n;
	int a=0,b=0,c=0,d=0;

	for(int i=0;i<n;i++){
		string s; cin>>s;
		if(s=="AC") a++;
		if(s=="WA") b++;
		if(s=="TLE") c++;
		if(s=="RE") d++;
	}	

	// for(int i=0;i<4;i++)
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<b<<endl;
	cout<<"TLE x "<<c<<endl;
	cout<<"RE x "<<d<<endl;
}

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

Measured memory_bytes: 3624
S = gets.chomp
yes = false
0.upto(S.size - 1) do |i|
  (i+1).upto(S.size - 1) do |j|
    if (S[0..i] + S[j..-1]) == "keyence"
      yes = true
    end
  end
end
puts yes ? "YES" : "NO"

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

template <typename T> T gcd(T a, T b) {
    if(a > b) gcd(b, a);
    T r;
    while(r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m = -1;
    ll t = 0;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    sort(all(A));
    rep(i, n - 1) {
        t += A[i];
        if(t * 2 < A[i + 1]) m = i;
    }
    cout << n - m - 1 << endl;
}

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

long long n, m, q;
long long s[100005] = {0};
long long l[100005] = {0};
long long ans[100005] = {0};
long long cnt[100005] = {0};
vector<long long> dis;

void solve();

int main() {
  cin >> n >> m;
  for(long long i = 0; i < m; ++i) cin >> s[i];
  cin >> q;
  for(long long i = 0; i < q; ++i) cin >> l[i];
  solve();
  for(long long i = 0; i < q; ++i) {
    int nowans =
        lower_bound(ans + 1, ans + n + 1, l[i] - s[0] + 1,
                    greater<long long>()) -
        ans;
    if(ans[nowans] + s[0] - 1 > l[i]) nowans = -1;
    cout << nowans << endl;
  }
  return 0;
}

void solve() {
  for(int i = 1; i < m; ++i) {
    dis.push_back(s[i] - s[i - 1] - 1);
    ans[1] += dis[i - 1];
  }
  dis.push_back(n - s[m - 1]);
  ans[1] += n - s[m - 1];
  sort(dis.begin(), dis.end());
  for(int i = 1; i <= n; ++i) {
    auto it = lower_bound(dis.begin(), dis.end(), i - 1);
    cnt[i] = dis.end() - it;
  }
  for(int i = 2; i <= n; ++i) ans[i] = ans[i - 1] - cnt[i];
}


Measured memory_bytes: 6800
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,cnt,tot,fst[100004],pnt[100004<<1],nxt[100004<<1],ans[100004],dp[100004][12];
void add(int x,int y){
	pnt[++tot]=y;
	nxt[tot]=fst[x];
	fst[x]=tot;
}
int main(){
	cin>>n>>m;
	int i,j,x,y;
	for (i=1;i<=m;i++){
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	cin>>cnt;
	for (i=1;i<=cnt;i++){
		cin>>x>>y>>ans[i];
		dp[x][y]=i;
	}
	for (i=9;i>=0;i--)
		for (x=1;x<=n;x++){
			dp[x][i]=max(dp[x][i],dp[x][i+1]);
			for (j=fst[x];j;j=nxt[j])
				dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);
			}
	for (i=1;i<=n;i++) cout<<ans[dp[i][0]]<<endl;
	return 0;
}

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

const int MOD = 1e9 + 7;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    map<Pll, ll> fish;
    int N; cin >> N;
    int alone = 0;
    for (int i = 0; i < N; i++) {
        ll A, B; cin >> A >> B;
        if (A == 0 && B == 0) {
            alone++;
        } else {
            if (A == 0 || B == 0) {
                A = abs(A);
                B = abs(B);
            } else if (A < 0) {
                A *= -1;
                B *= -1;
            }
            ll g = gcd(A, B);
            A /= g;
            B /= g;
            fish[Pll(A, B)]++;
        }
    }
    vector<Pll> bad_naka;
    ll free = 0;
    for (auto x : fish) {
        ll a, b; tie(a, b) = x.first;
        if (x.second == 0) continue;
        ll oa, ob;
        if (a == 0) {
            oa = 1, ob = 0;
        } else if (b == 0) {
            oa = 0, ob = 1;
        } else if (b < 0) {
            oa = b * -1;
            ob = a;
        } else {
            oa = b;
            ob = a * -1;
        }
        if (fish[Pll(oa, ob)] > 0) {
            bad_naka.push_back(Pll(x.second, fish[Pll(oa, ob)]));
            fish[Pll(oa, ob)] = 0;
        } else {
            free += x.second;
        }
    }
    ll ans = modpow(2, free);
    for (auto x : bad_naka) {
        ans *= ((MOD + modpow(2, x.first) + modpow(2, x.second) - 1) % MOD);
        ans %= MOD;
    }
    cout << (MOD + ans - 1 + alone) % MOD << endl;
}

Measured memory_bytes: 28580
n = gets.to_i
wordlist = []
lastChara =""
n.times do |i|
  word = gets.chomp
  if wordlist.include?(word)
    puts "No"
    exit
  end
  wordlist << word
  if i > 0
    if lastChara != word[0]
      puts "No"
      exit
    end
  end
  lastChara = word[-1]
end
puts "Yes"


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

int b[1005][1005];

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

  int n;
  cin >> n;

  int cnt4 = 0;
  int cntFk = 0;

  rep(i, n) {
    int a;
    cin >> a;
    if(a%4==0) {
      cnt4++;
    } else if(a%2) {
      cntFk++;
    }
  }

  bool res = true;
  if (cnt4>=cntFk || (cnt4+1==cntFk && cnt4+cntFk==n)) {

  } else {
    res = false;
  }

  cout << (res?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,m = map(int, input().split())
k = [list(map(int,input().split())) for i in range(n)]

ans = [0]*m

for i in range(n):
    for j in range(1, k[i][0]+1):
        #print(k[i][j] -1)
        ans[ k[i][j] -1] += 1

#print(ans)
print(ans.count(n))






Measured memory_bytes: 8868
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int d,th=0,h,te,o;
    long long a,bb;
    string b;
    cin>>a>>b;
    d=b.size();
    if(d==5){
        th=b[0]-'0';
    }
    h=b[d-4]-'0';
    te=b[d-2]-'0';
    o=b[d-1]-'0';
    bb=th*1000+h*100+te*10+o;
    a*=bb;
    a/=100;
    cout<<a;
	return 0;
}


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

// int c[1000][1000];

int lcs(string x, string y){
  int m = x.size();
  int n = y.size();

  int c[1001][1001];
  for(int i=1;i<=m;i++) c[i][0] = 0;
  for(int j=1;j<=n;j++) c[0][j] = 0;
  x = ' ' + x;
  y = ' ' + y;

  int maxl = 0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(x[i] == y[j]) c[i][j] = c[i-1][j-1] + 1;
      else c[i][j] = max(c[i-1][j], c[i][j-1]);
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main(){
  int q;
  cin >> q;
  string s1, s2;
  for(int i=0;i<q;i++){
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}



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

using namespace std;

typedef long long ll;

const int MOD = 1000000007;
const int MAX = 2010101;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i=2; i<MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll G(int r, int c) {
	ll ret = 0;
	for (int j=1; j<c+2; j++) {
		ret += COM(r + j, j);
		ret %= MOD;
	}
	return ret;
}

int main(int, char**) {
	COMinit();
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	ll ret = (((G(r2, c2) 
			+ (MOD - G(r2, c1 - 1))) % MOD
			+ (MOD - G(r1 - 1, c2))) % MOD
			+ G(r1 - 1, c1 - 1))%MOD;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 47360
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}


void Main()
{
    int n; cin>>n;
    VVI v(n);
    vector<map<int,int>> vc(n);
    vector<PII> v_ori(n-1);

    VI count(n);

    REP(i,n-1){
        int a,b; cin>>a>>b;
        a--;
        b--;
        v[a].PB(b);
        v[b].PB(a);

        v_ori[i] = MP(a,b);
        count[a]++;
        count[b]++;
    }

    int max_color=0;
    for(const auto x : count){
        max_color = max(max_color, x);
    }

    queue<PII> q;

    REP(i,SIZE(v[0])){
        int j=v[0][i]; 
        q.push(MP(0,j));
        vc[0][j] = i+1;
        vc[j][0] = i+1;
    }

    while(!q.empty()){
        PII e = q.front(); q.pop();
        int prev = e.first;
        int now = e.second;
        int now_color = vc[prev][now];
        //if(color != 0){
        //    continue;
        //}

        int color=1;
        REP(i,SIZE(v[now])){
            int next = v[now][i];
            if(next == prev){
                continue;
            }
            if(color == now_color){
                color++;
            }
            vc[now][next] = color;
            vc[next][now] = color;
            q.push(MP(now,next));
            color++;
        }
    
    }
    cout << max_color << endl;

    for(const auto& e : v_ori){
        cout << vc[e.first][e.second] << endl;
    }

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 21248
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

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

	int cnt = 1;
	int target = 7%k;
	while (cnt <= k) {
		if (target == 0) {
			cout << cnt << endl;
			return 0;
		}
		target = (target * 10 + 7) % k;
		cnt++;
	}
	cout << -1 << endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN=1e5;

int main()
{
    int x;
    cin >> x;
    if(x==1)
        cout << 0;
    else
        cout << 1;
}

Measured memory_bytes: 3616
#include<stdio.h>

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  long N,K,n=0;
  cin >> N >> K;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  sort(H.begin(),H.end());
  for(int i=N-K-1;i>=0;i--){
    n += H[i];
  }
  cout << n;

}

Measured memory_bytes: 1024
#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();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    ll N;
    cin>>N;
    unordered_map<string,ll> ma;
    for(ll i=0;i<N;i++)
    {
        string s;
        cin>>s;
        ma[s]++;
    }
    cout<<ma.size()<<endl;
}

Measured memory_bytes: 17648
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

vector<LL> t;
vector<LL> v, a, h;

void update_value(LL v, LL tl, LL tr, LL pos, LL val)
{
   // debug(v);
    if (tl == tr)
    {
        t[v] = val;
    }
    else
    {
        LL tm = (tl + tr) / 2;
        if (pos <= tm)
        {
            update_value(2 * v, tl, tm, pos, val);
        }
        else
        {
            update_value(2 * v + 1, tm + 1, tr, pos, val);
        }
        t[v] = max(t[2 * v], t[2 * v + 1]);
    }
}

LL query(LL v, LL tl, LL tr, LL left, LL right)
{
   // debug(v);
    
    if (right < left)
    {
        return -100000000000;
    }
    else if (tl == left && tr == right)
    {
        return t[v];
    }
    else
    {
        LL tm = (tl + tr) / 2;
        LL a1 = query(2 * v, tl, tm, left, min(right, tm));
        LL a2 = query(2 * v + 1, tm + 1, tr, max(tm + 1, left), right);
        return max(a1, a2);
    }
}

int main()
{
    fastinput;
    LL n, i, j, k,  temp;
    cin >> n;

    v.resize(n);
    a.resize(n);
    h.resize(n);

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

    set<LL> s(all(h));
    v.assign(all(s));
    LL sz = v.size();
    LL ans=-1;
    t.assign(4 * sz + 1,0);
    
    for(i=0;i<n;i++)
    {
        LL pos=lower_bound(all(v),h[i])-v.begin();
        LL maxima=query(1,0,sz-1,0,pos-1);
        LL prev=max(maxima,0LL);
        update_value(1,0,sz-1,pos,prev+a[i]);
        ans=max(ans,prev+a[i]);
       // debug(i);
       // debug(pos);
       // debug(maxima);
       // debug(prev);
       // part;
        //return 0;

    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 20608
N,M=map(int,input().split())
import math
MOD=10**9+7
if abs(N-M)>=2:
  print(0)
else:
  if N==M:
    ans=(((math.factorial(N))%MOD)**2)*2
    print(ans%MOD)
  else:
    ans=((math.factorial(N))%MOD)*((math.factorial(M))%MOD) 
    print(ans%MOD)

Measured memory_bytes: 4096
#include <iostream>
using namespace std;
char a[102][102];
int main() {
	int A, B;cin >> A >> B;
	int x = 0, y = 0;
	for (int i = 0;i < 50;i++) {
		for (int k = 0;k < 100;k++) {
			a[i][k] = '.';
			a[i+50][k] = '#';
		}
	}
	for (int w = 2; w <= B;w++) {
		x = (w * 2 - 3) % 100;
		y = ((w * 2 - 3) / 50)*2;
		a[y][x] = '#';
	}
	for (int b = 2; b <= A;b++) {
		x = (b * 2 - 3) % 100;
		y = 99-((b * 2 - 3) / 50)*2;
		a[y][x] = '.';
	}
	cout << "100 100\n";
	for (int h = 0;h < 100;h++) {
		for (int w = 0; w < 100; w++) {
			cout << a[h][w];
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = list(map(lambda x: int(x) ,input().split(" ")))
li = []
p = list(map(lambda x: int(x) ,input().split(" ")))
q = list(map(lambda x: int(x) ,input().split(" ")))
r = list(map(lambda x: int(x) ,input().split(" ")))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:X]
q = q[:Y]
r.extend(p)
r.extend(q)
r.sort(reverse=True)
print(sum(r[:X+Y]))

Measured memory_bytes: 23328
/**
 * File    : F.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-5-12 22:17:51
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <chrono>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int x[100010];
int y[100010];
string S;
vector<int> T[100010];
vector<int> V[100010];
int root = -1;
int parent[100010];
int parent2[100010];
bool need[100010];
bool del[100010];
int maxi = 0;

int dfs(int v)
{
  int ans = (need[v] ? 1 : 0);
  vector<int> X;
  for (auto e : V[v])
  {
    if (e == parent[v])
    {
      continue;
    }
    else
    {
      parent[e] = v;
      X.push_back(dfs(e));
    }
  }
  if ((int)X.size() == 0)
  {
    return ans;
  }
  else if ((int)X.size() == 1)
  {
    ans += X[0];
    maxi = max(maxi, ans);
    return ans;
  }
  else
  {
    sort(X.begin(), X.end());
    reverse(X.begin(), X.end());
    ans += X[0] + X[1];
    maxi = max(maxi, ans);
    return ans - X[1];
  }
}

bool dfs2(int v)
{
  // cerr << "v = " << v << endl;
  bool ans = (S[v] == 'B');
  for (auto e : T[v])
  {
    if (e == parent2[v])
    {
      continue;
    }
    else
    {
      parent2[e] = v;
      ans = (dfs2(e) & ans);
    }
  }
  del[v] = ans;
  return ans;
}

int main()
{
  int N;
  cin >> N;
  for (auto i = 0; i < N - 1; i++)
  {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    T[x[i]].push_back(y[i]);
    T[y[i]].push_back(x[i]);
  }
  cin >> S;
  bool allb = true;
  for (auto i = 0; i < N; i++)
  {
    if (S[i] == 'W')
    {
      allb = false;
      break;
    }
  }
  if (allb)
  {
    cout << 0 << endl;
    return 0;
  }
  for (auto i = 0; i < N; i++)
  {
    if (S[i] == 'W')
    {
      root = i;
      break;
    }
  }
  assert(root >= 0);
  parent2[root] = -1;
  dfs2(root);
  int M = 0;
  for (auto i = 0; i < N - 1; i++)
  {
    if (!del[x[i]] && !del[y[i]])
    {
      V[x[i]].push_back(y[i]);
      V[y[i]].push_back(x[i]);
      M++;
    }
  }
  M++;
  int cost = 0;
  fill(need, need + 100010, false);
  for (auto i = 0; i < N; i++)
  {
    if (del[i])
    {
      continue;
    }
    if ((((int)V[i].size()) % 2 == 0) ^ (S[i] == 'B'))
    {
      cost++;
      need[i] = true;
    }
  }
  // cerr << "cost = " << cost << endl;
  for (auto i = 0; i < N; i++)
  {
    if (!del[i] && S[i] == 'W')
    {
      root = i;
      break;
    }
  }
  assert(root >= 0);
  parent[root] = -1;
  dfs(root);
  cout << 2 * (M - 1) + cost - maxi * 2 << endl;
}

Measured memory_bytes: 22400
main = do
  s <- getLine
  print $ solve 0 s (reverse s) 
 
solve n [] [] = div n 2
solve n (x:xs) []
  | x == 'x' = solve (n + 1) xs []
  | otherwise = -1
solve n [] (y:ys)
  | y == 'x' = solve (n + 1) [] ys
  | otherwise = -1
solve n (x:xs) (y:ys)
  | x == y = solve n xs ys
  | x == 'x' = solve (n + 1) xs (y:ys)
  | y == 'x' = solve (n + 1) (x:xs) ys
  | otherwise = -1

Measured memory_bytes: 15740