akhauriyash/Code-Regression huggingface dataset:
N=int(input())
RED=[tuple(map(int, input().split())) for _ in range(N)]
BLUE=[tuple(map(int, input().split())) for _ in range(N)]

RED.sort(key=lambda x:x[1], reverse=True)
BLUE.sort(key=lambda x:x[0])

ans=0
r_used=[False]*N
for b in BLUE:
    for j,r in enumerate(RED):
        if r_used[j]: continue
        if r[0]<b[0] and r[1]<b[1]:
            ans+=1
            r_used[j]=True
            break
print(ans)

Measured memory_bytes: 39024
#include<stdio.h>

int main(void) {

  int d = 0;
  int n = 0;
  int k;
  long long int ans = 1;

  scanf("%d %d", &d, &n);

  if (n == 100) {
    n = 101;
  }
  for (k = 0; k < d; k++) {
    ans *= 100;
  }

  ans *= n;
  printf("%lld\n", ans);

  return 0;
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a[200010];
int main()
{
   ll t,n,i,j,k,l,mn=0, mx=0;
   sl2(n,k);
   for(int i=0; i<n; i++)
    sl(a[i]);
    sort(a, a+n);

    loop(k) mn+=a[i];
    cout<<mn;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll mul(ll x, ll y)
{
    return (x * 1ll * y) % MOD2;
}

ll fastpow(ll x, ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}
struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first > b.first;
    }
    return a.second >b.second;
  }
};
int main(int argc, char** argv)
{   sws ;
   // tcase
    {
     ll n,d,ans=0 ;
     cin>>n>>d ;
     ll u,v ;
     forn(i,n)
     {
     	cin>>u>>v ;
     	if(u*u+v*v<=d*d)
     	ans++ ;
	 }
	 cout<<ans<<"\n" ;
    }
return 0 ;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    char a[110][110] = {0};
    int h = 0, w = 0, i = 0, j = 0, num[110][110] = {0}, c = 0, x = 0;
    bool flag;
    cin >> h >> w;
    for(i = 0; i < h; i++)
    {
        for(j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }

    for(i = 0; i < h; i++)
    {
        for(j = 0; j < w; j++)
        {
            if (a[i][j] != '.')
            {
                c = 1;
            }
        }
        if(c == 1)
        {
            c = 0;
            continue;
        }
        for(j = 0; j < w; j++)
        {
             num[i][j] = 1;

        }

    }

      for(i = 0; i < w; i++)
    {

        for(j = 0; j < h; j++)
        {
            if (a[j][i] != '.')
            {
                c = 1;
            }
        }
        if(c == 1)
        {
            c = 0;
            continue;
        }
        for(j = 0; j < h; j++)
        {
             num[j][i] = 1;
        }
    }

  for(i = 0; i < h; i++)
    {
        for(j = 0; j < w; j++)
        {
            if(num[i][j] == 1)
            {
                cout << "";
                x++;
                continue;
            }
        cout << a[i][j];
        }
      if(x == w)
      {
          x = 0;
          continue;
      }
      x = 0;
      cout << endl;
    }


return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int calc(int y, int m, int d) {
    int ret = 0;
    
    const int days_normal = 20*5+19*5;
    const int days_aho = 20*10;

    ret += (y-1)/3 * days_aho;
    ret += (y-1)/3 * days_normal * 2;
    ret += (y-1)%3 * days_normal;
    if (y%3) {
        ret += (m-1)/2 * 39;
        ret += (m-1)%2 * 20;
        ret += d;
    } else {
        ret += (m-1)*20;
        ret += d;
    }
    return ret;
}

int solve(int N) {
    int ret = 0;
    for (int i = 1; i < N; i++) {
        for (int j = 2; j < 1000; j++) {
            int sum = 2 * i * j + j * j - j;
            if (sum == 2*N) ret++; 
        }
    }
    return ret;
}

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

    vector<int> ans;
    while (1) {
        int N; cin >> N;
        if (!N) break;
        ans.push_back(solve(N));
    }
    for (auto &i: ans) {
        cout << i << endl;
    }
}





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

int main() {
  
  string s;
  cin >> s;
  
  int n = s.size();
  
  for (int i = 0; i < n; i++) {
    s[i] = 'x';
  }
  
  cout << s << endl;
  
}


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

int main()
{
    char s[5],t[5],g[5],h[5];
    scanf("%s",s);
    scanf("%s",t);
    scanf("%s",g);


   h[0]=s[0];
   h[1]=t[1];
   h[2]=g[2];
          printf("%s\n",h);

}

Measured memory_bytes: 1656
//***********************
//*** writer : Alan Hu **
//***********************
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<cmath>
using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

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

int t;

struct node{
	ll a,b,c,d;
};

node a[305];

ll gcd(ll x,ll y)
{
	if (x%y==0) return y;
	else return gcd(y,x%y);
}

int main()
{
	cin>>t;
	rept(i,0,t)
	{
		cin>>a[i].a>>a[i].b>>a[i].c>>a[i].d;
		if (a[i].b>a[i].d or a[i].b>a[i].a)
		{
			cout<<"No"<<endl;
			continue;
		}
		ll p=gcd(a[i].d,a[i].b);
		a[i].a-=(a[i].a-a[i].b)/p*p+p;
		if (a[i].a>a[i].c)
		{
			cout<<"No"<<endl;
		}
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
using namespace std;
int main(){
    int m,n,x,remain;
    cin>>n>>m;
    remain=n;
    for(int i=0;i<m;i++){
        cin>>x;
        remain=remain-x;
    }if(remain<0)
        cout<<"-1";
    else
    cout<<remain;
    
    
    
    
    
    
}


Measured memory_bytes: 3632
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

long long gcd(long long a, long long b) {
	return b != 0 ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

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

	
	long long less_b = b - b / c - b / d + b / lcm(c, d);
	long long less_a = a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm(c, d);

	long long ans = less_b - less_a;

	ANS(ans);


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,num;
  scanf("%d",&n);
  num = n % 10;
  //printf( "%d\n", num );
  if(num == 2)
    printf("hon");
  else if(num == 4)
    printf("hon");
  else if(num == 5)
    printf("hon");
  else if(num == 7)
    printf("hon");
  else if(num == 9)
    printf("hon");
  
  else if(num == 0)
    printf("pon");
  else if(num == 1)
    printf("pon");
  else if(num == 6)
    printf("pon");
  else if(num == 8)
    printf("pon");
  
  else if(num == 3)
    printf("bon");
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,m;
double f[610];
vector<int> sq[610];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();m=read();
	rep(i,1,m)
	{
		int u=read(),v=read();
		sq[u].push_back(v);
	}
	double ans=maxd;
	rep(ban,1,n)
	{
		f[n]=0.0; 
		per(u,n-1,1)
		{
			int len=sq[u].size();
			double mx=0.0,sum=0.0;
			rep(i,0,len-1)
			{
				int v=sq[u][i];
				sum+=f[v];mx=max(f[v],mx);
			}
			if ((u==ban) && (len>1))
			{
				len--;sum-=mx;
			}
			f[u]=sum/len+1;
		}
		//rep(i,1,n) cout << f[i] << " ";cout << endl;
		ans=min(ans,f[1]);
	}
	printf("%0.8lf",ans);
	return 0;
}


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

deque<char> d;

int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	string str; cin >> str;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] != 'B')
			d.push_back(str[i]);
		else if (str[i] == 'B' && !d.empty())
			d.pop_back(); 
	}
	while (!d.empty()) {
		cout << d.front();
		d.pop_front();
	}
	cout << endl;


	return 0;   
}  

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

int main() {
  string s;
  cin >> s;
  int a[3] = {0};
  for (int i = 0; i < s.size(); i++) {
    int x = s[i] - 'a';
    a[x]++;
  }
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (a[i] > 0) {
      cnt++;
    }
  }
  if (cnt == 3) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define ceil(a, b) a / b + !!(a % b)
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



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

    string s;
    cin >> s;
    
    int g[200001] = {0};
    g[0] = 1;
    if (s[1] != s[0]) g[1] = 2;
    else g[1] = 1;
    
    rep3(i, 2, sz(s)) {
        if (s[i] != s[i - 1]) g[i] = g[i - 1] + 1;
        else g[i] = g[i - 3] + 2;
    }
    
    cout << g[sz(s) - 1] << endl;
    // rep(i, sz(s)) cout << g[i] << " "; cout << endl;
}


Measured memory_bytes: 1300
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      int m = sc.nextInt();
      int c = sc.nextInt();
      
      int[] b = new int[m];
      for(int i = 0; i < m; i++) {
         b[i] = sc.nextInt();
      }
      
      int count = 0;
      for(int i = 0; i < n; i++) {
         int val = c;
         for(int j = 0; j < m; j++) {
            val += b[j] * sc.nextInt();
         }
         if(val > 0)
            count++;
      }
      System.out.println(count);
   }
}

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

int main()
{
  string s;
  cin >> s;
  map<char, int> mp;
  for (int i = 0; i < s.size(); i++) {
	if (mp.find(s[i]) == mp.end()) {
	  mp.emplace(s[i], 1);
	}
	else {
	  mp[s[i]]++;
	}
  }
  for (auto i = mp.begin(); i != mp.end(); i++) {
	if (i->second % 2 == 1) {
	  cout << "No" << endl;
	  return 0;
	}
  }
  cout << "Yes" << endl;
  return 0;
}



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

#define fr(i,n) for(int i = 0; i<n; i++)
#define prin(a) cout << #a << " = " << a << endl
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

const int N = 2e5+10;
int b[N], bo[N], l[N], r[N], ido[N];
map<int,int> mp;
int n, m;
vector<pair<int,int>> g[N];
vector<int> ans;
int vis[N];

void go(int no){
	vis[no] = 1;
	for(auto &par :  g[no]){
		int it, idoi;
		tie(it,idoi) = par;
		if(!vis[it]){
			go(it);
			if(b[it]){
				b[it] = !b[it];
				b[no] = !b[no];
				ans.push_back(idoi);
			}
		}
	}
}

int main(){
	cin >> n >> m;
	
	fr(i,n){
		int xi, bi;
		scanf("%d%d", &xi, &bi);
		mp[xi] = bi;
	}		
	
	int cnt = 0;
	for(auto &it : mp){
		bo[cnt] = it.se;
		it.se = cnt++;
	}
	
	cnt = 0;
	fr(i,m){
		int li, ri;
		scanf("%d%d", &li, &ri);
		
		int nl = n;
		auto it = mp.lower_bound(li);
		if(it!=mp.end()) nl = it->se;
		
		int nr = -1;
		it = mp.upper_bound(ri);
		if(it!=mp.begin()) nr = prev(it)->se;
		
		if(li==n or li>ri) continue;
		l[cnt] = nl;
		r[cnt] = nr;
		ido[cnt++] = i+1;
	}
	m = cnt;
	
	for(int i = 0; i<=n; i++){
		int ant = 0;
		if(i) ant = bo[i-1];
		int cur = 0;
		if(i<n) cur = bo[i];
		if(ant!=cur) b[i] = 1;
	}
	n++;
	
	fr(i,m) r[i]++;
	
	fr(i,m){
		g[l[i]].emplace_back(r[i],ido[i]);
		g[r[i]].emplace_back(l[i],ido[i]);
	}
	
	fr(i,n){
		if(!vis[i]){
			go(i);
			if(b[i]){	
				puts("-1");
				return 0;
			}
		}
	}
	
	sort(all(ans));
	printf("%d\n", sz(ans));
	fr(i,sz(ans)){
		printf("%d%c", ans[i], " \n"[i==sz(ans)-1]);
	}
	
}

Measured memory_bytes: 24448
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	char c;
	cin >> c;
	
	if( c == 'A' ) cout << 'T' << endl;
	if( c == 'T' ) cout << 'A' << endl;
	if( c == 'G' ) cout << 'C' << endl;
	if( c == 'C' ) cout << 'G' << endl;
	
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	ll h,w,k;
	cin >> h >> w >> k;
	ll dp[105][10]={};
	dp[0][1] = 1;
	for (int i = 0;i < 104;i++) {
		for (int k = 0;k < pow(2,w-1);k++) {
			for (int j = 1;j < w + 1;j++) {
				bool is_ok = true;
				for (int l = w-2;l > 0;l--) {
					if ((k >> l)%2 == 1&&(k >> l-1)%2 == 1) {
						is_ok = false;
					}
				}
				if (is_ok) {
					// cout << (k >> w-j-1) << (k >> w-j+1) << endl;
					if ((k >> j-1)%2 == 1) {
						dp[i+1][j+1] += dp[i][j];
						dp[i+1][j+1] %= inf;
					} else if ((k >> j-2)%2 == 1) {
						dp[i+1][j-1] += dp[i][j];
						dp[i+1][j-1] %= inf;
					} else {
						dp[i+1][j] += dp[i][j];
						dp[i+1][j] %= inf;
					}
				}
			}
		}
	}
	// for (int i = 0;i < 104;i++) {
	// 	for (int  j = 1;j < w+1;j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << dp[h][k] << endl;
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using plglg = pair<ll, ll>;
using tlglglg = tuple<ll, ll, ll>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    string s, t; cin >> s >> t;
    int slen, tlen;
    slen = s.length();
    tlen = t.length();
    int ans = INF;
    REP(shift, slen-tlen+1) {
        int subans = 0;
        REP(i, tlen) {
            if (s[i+shift] != t[i]) subans++;
        }
        chmin(ans, subans);
    }

    print(ans);

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i, n) cin >> a[i] >> b[i];
    ll c = 0;
    REPR(i, n) {
        c += (b[i] - ((a[i] + c) % b[i])) % b[i];
    }
    cout << c << endl;
}

Measured memory_bytes: 1792
a=[]
for i in range(3):
    a1,a2,a3=map(int, input().split())
    a.append(a1)
    a.append(a2)
    a.append(a3)
n=int(input())
for i in range(n): #bingo判定
    b=int(input())
    for j in range(9):
        if b==a[j]:
            a[j]=0
            break
if a[0]==a[1]==a[2]==0 or a[3]==a[4]==a[5]==0 or a[6]==a[7]==a[8]==0:
    print('Yes')
elif a[0]==a[3]==a[6]==0 or a[1]==a[4]==a[7]==0 or a[2]==a[5]==a[8]==0:
    print('Yes')
elif a[0]==a[4]==a[8]==0 or a[2]==a[4]==a[6]==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> struct Edge { T to, cost; };
template<typename T> bool operator<(const Edge<T> &e1, const Edge<T> &e2) {
  return (e1.cost != e2.cost) ? e1.cost > e2.cost : e1.to < e2.to;
}
template<class E> using Graph = vector<vector<E>>;

template<typename T> struct Dijkstra {
  vector<T> d;
  template<class E> Dijkstra(const Graph<E> &G, T s, T INF = 1e9) {
    int N = G.size();
    priority_queue<E> pq;
    d.assign(N, INF); d[s] = 0;
    pq.push({s, 0});
    while (!pq.empty()) {
      Edge<T> e = pq.top(); pq.pop();
      T u = e.to;
      if (d[u] < e.cost) continue;
      for (auto&& v : G[u]) {
        if (d[v.to] > d[u] + v.cost) {
          d[v.to] = d[u] + v.cost;
          pq.push({v.to, d[v.to]});
        }
      }
    }
  }
};

int main() {
  int N; cin >> N;
  Graph<Edge<ll>> G(N);
  for (int i = 0; i < N - 1; ++i) {
    ll a, b, c; cin >> a >> b >> c;
    --a; --b;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  ll Q, K; cin >> Q >> K;
  --K;
  Dijkstra<ll> dijkstra(G, K, 1e18);
  while (Q--) {
    ll x, y; cin >> x >> y;
    --x; --y;
    cout << dijkstra.d[x] + dijkstra.d[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 11120
#include <stdio.h>

int main()
{
    
    int num_1;
    int num_2;
    
    int area = 0;
    int cir_len = 0;
 
    scanf("%d %d",&num_1,&num_2);
    
    area    = num_1 * num_2;
    cir_len = ((num_1*2) + (num_2*2));
    
    printf("%d %d\n",area,cir_len);


    return 0;
}

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

using namespace std;

int main(void) {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;

  if (s == u) {
    cout << a - 1 << " " << b << endl;
  } else {
    cout << a << " " << b - 1 << endl;
  }
}

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

 int main (){
     int n,b,f,r,v;
     int a[4][3][10]={0};
     cin >> n;
     for (int i=0; i< n; i++){
         cin >> b >> f >> r >> v;
         a[b-1][f-1][r-1] +=v;

     }
     for (int i= 0; i<4;i++){
         for (int j=0; j<3; j++){
             for (int k=0; k<10; k++){
                 cout <<" " << a[i][j][k];
             }
             cout << endl;
         }
         if (i!=3){
             cout << "####################" << endl;}

     }
 }



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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

ll N,K;

bool judge(ll x){
    ll sum = 0;
    int cnt = 0;
    while(x != 0 && cnt < N){
        sum += x;
        x /= 2;
        cnt++;
        if(sum > K)return false;
    }
    return true;
}

int main(){
    cin >> N >> K;
    ll r = INF;
    ll l = 1ll;
    while(r-l > 1){
        ll m = (r+l)/2;
        if(judge(m) == true){
            l = m;
        }else{
            r = m;
        }
    }
    if(judge(r) == true)cout << r << endl;
    else cout << l << endl;
    //cin >> N;
}


Measured memory_bytes: 3112
/**
 * THIS IS CFMASTER'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  map<pair<int, int>, int> mp;
  vector<vector<int>> g(n);
  vector<vector<int>> f(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    mp[make_pair(x, y)] = 1;
    mp[make_pair(y, x)] = 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    f[x].push_back(y);
    f[y].push_back(x);
  }
  vector<bool> mark(n);
  vector<int> cnt(n);
  vector<int> comp(n);
  int c = 0;
  vector<int> dfs;
  function<void(int)> Dfs = [&](int v) {
    mark[v] = true;
    dfs.push_back(v);
    for (int u : g[v]) {
      if (mark[u]) {
        continue;
      }
      Dfs(u);
    }
  };
  for (int i = 0; i < n; i++) {
    if (mark[i]) {
      continue;
    }
    dfs.clear();
    Dfs(i);
    int w = (int) dfs.size();
    ++c;
    for (int v : dfs) {
      comp[v] = c;
      cnt[v] = w;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    int tnt = 0;
    for (int u : f[i]) {
      if (comp[u] == comp[i] && !mp[make_pair(u, i)]) {
        ++tnt;
      }
    }
    cout << cnt[i] - 1 - (int) g[i].size() - tnt;
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 38008
n, m  = gets.strip.split.map(&:to_i)
as = gets.strip.split.map(&:to_i)

matched_numbers = [2,5,5,4,5,6,3,7,6].map.with_index {|e,i| [e, i+1] }.select{|_,i| as.include?(i) }.sort.to_h

#p matched_numbers

dp = Array.new(n+1)

(1..n).each do |i|
  tmp = matched_numbers[i].to_i.to_s
  matched_numbers.each do |cost, number|
    next if dp[i-cost].nil? || dp[i-cost].to_i.zero?

    a = dp[i-cost]
    b = number.to_s
    str = a>b ? (a+b) : (b+a)
    tmp = str if str.length > tmp.length || (tmp.length == str.length && str> tmp )
  end
  dp[i] = tmp
end

#p dp
p dp[n].to_i

Measured memory_bytes: 50940
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

int main(){
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF){
        if((a*b)%2==0){
            printf("Even\n");
        }
        else printf("Odd\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, k; 
    cin >> n >> k;
    int l[n];
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l, l+n, greater<int>());
    ll sum = 0;
    for (int i = 0; i < k; i++) sum += l[i];
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	ll x, y;
	cin >> x >> y;
	vll cnt(4);
	cnt[0] = y - x;
	cnt[1] = y + x + 1;
	cnt[2] = -y - x + 1;
	cnt[3] = -y + x + 2;
	rep(i, 4) {
		if (cnt[i] <= 0) cnt[i] = 1e9 + 7;
	}
	ll ans = min(cnt[0], min(cnt[1], min(cnt[2], cnt[3])));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define benfero freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mm ' '
#define nl '\n'
#define MOD 1000007
typedef unsigned long long int ull;
typedef long long int ll;
int main()
{
    //benfero
    int n;
    string s;
    cin>>n>>s;
    if(n%2){cout<<"No"<<nl; return 0;}
    int idx=n/2;
    int i;
    for(i=0;i<(n/2);i++){
        if(s[i]!=s[idx++]){cout<<"No"<<nl; return 0;}
    }
    cout<<"Yes"<<nl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
//<editor-fold desc="definitions">
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using viii = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

dbg::Debug debug;
//</editor-fold>

class DFloorFunction {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll a, b, n;
	    in >> a >> b >> n;

	    ll x = min(b-1, n);

	    out << floor((double)a*x/b) - a * floor((double)x / b) << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	DFloorFunction solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#include <string.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int MAX_S = 100000;
char S[MAX_S + 1];

void solve(const int N) {
    // dp[i][j] is position after 2^i moving from start position j.
    vector<vector<int> > dp(32, vector<int>(N));

    // move one step
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            dp[0][i] = i + 1;
        } else {
            dp[0][i] = i - 1;
        }
    }

    for (int i = 1; i < 32; i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }

    vector<int> last_positions(N, 0);
    for (int i = 0; i < N; i++) {
        last_positions[i] = i;
    }

    // 10^5 = 2^5 + 2 ^7 + 2^9 + 2^10 + 2^15 + 2^16
    vector<int> as = {5, 7, 9, 10, 15, 16};
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int) as.size(); j++) {
            last_positions[i] = dp[as[j]][last_positions[i]];
        }
    }

    vector<int> answer(N);
    for (int i = 0; i < N; i++) {
        answer[last_positions[i]]++;
    }

    cout << answer[0];
    for (int i = 1; i < N; i++) {
        cout << " " << answer[i];
    }
    cout << endl;
}

/*
 * DP solution.
 * ref. https://img.atcoder.jp/abc136/editorial.pdf
 */
int main(void) {
    cin >> S;
    int N = strlen(S);

    solve(N);

    return 0;
}


Measured memory_bytes: 13816
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = input[0];
            var P = input[1];

            Console.WriteLine((3 * A + P) / 2);
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで

int main() {
    // 入力
    int n;
    cin >> n;

    string                       restaurant;
    pair<pair<string, int>, int> p[110];

    rep(i, n) {
        int score;
        cin >> restaurant >> score;
        string tmp = restaurant;

        // 要素を追加 make_pair(キー、値)
        p[i] = make_pair(make_pair(restaurant, -score), i);
    }

    sort(p, p + n);

    // 出力
    rep(i, n) { cout << p[i].second + 1 << endl; }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long ans = 0;
		for(int i = 1 ; i <= n ; i++) {
			if(func(i, a, b)) {
				ans += i;
			}
		}
		System.out.println(ans);
	}

	public static boolean func(int value, int a, int b) {
		long ret = 0;
		while(value > 0) {
			ret += value % 10;
			value /= 10;
		}
		if(a <= ret && ret <= b) {
			return true;
		} else {
			return false;
		}
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define debug(x) //cout << #x << " = " << x << endl;
#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long ll;

ll start(const string a, const string b){
  if( a[0] == b[0] )
    return 3LL;
  else
    return 6LL;
}

ll transition(const string a, const string b, int i){
  if( a[i] == b[i] ){
    if( a[i+1] == b[i+1] ) return 2LL;
    else return 2LL;    
  }else{
    if( a[i+1] == b[i+1] ) return 1LL;
    else return 3LL;
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  
  //const ll mod = 1000000007;
  const ll mod = 1e9+7;

  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;

  ll ans = start(s1, s2);
  debug(ans);

  int i = 0;
  if( ans == 6 )
    i++;

  while( i < s1.size()-1 ){
    ll tr = transition(s1, s2, i);
    ans = (ans*tr)%mod;
    debug(ans);
    if( s1[i+1] == s2[i+1] )
      i++;
    else
      i += 2;
    if( i == s1.size()-1) break;
  }

  cout << ans << endl;

  return 0;
}

// AC
/*
  Consider every "transition" := line cutting the rectangle. ie 
  A|BB
  A|CC

  There are 4 possible transitions. For each, calculate the number of ways to paint.
  
  Also, there are 2 way to start at the left most side. Count.
  
  The ans is the product of all those numbers mod 1e9+7. 
 */


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
	int n,k;
	cin >> n >> k;
	vector<int>cost(n+ 100);
	rep(i, n)cin >> cost[i];
	ll dp[100200];
	rep(i, 100200)dp[i] = INF;
	dp[0] = 0;
	rep(i, n) {
		rep(j, k) {
			dp[i + j + 1] = min(dp[i + j + 1], (abs(cost[i] - cost[i + j + 1])) + dp[i]);
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

int N, X[1009], Y[1009], H[1009]; vector<tuple<int,int,int> >vec;

int main() {
  cin >> N; tuple<int,int,int>G = make_tuple(-1, -1, -1);
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			int V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j);  bool flag = true;
			for (int k = 1; k <= N; k++) {
			  int VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV,0);
				if (H[k] != VV) flag = false;
			}
			if (flag == true) vec.push_back(make_tuple(i, j, V));
		}
	}
	
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
	
	return 0;
}


Measured memory_bytes: 256
import numpy as np
q = int(input())
b = [True] * (10**5+1)
for i in range(2, 10**5):
    x = 2 * i
    while x <= 10**5:
        b[x] = False
        x += i
b[0] = b[1] = False
a = [False] *  (10**5+1)
for i in range(1, 10**5):
    if b[i] and b[int((i+1)/2)]:
        a[i] = True
cumsum = np.array(a).cumsum()
for _ in range(q):
    l, r = map(int, input().split())
    print(cumsum[r] - cumsum[l-1])

Measured memory_bytes: 17096
#include <bits/stdc++.h>
using namespace std;
struct undoable_dsu{
  struct dat{
    int p,sz;
  };
  int cc;
  vector<dat>t;
  vector<pair<int, dat> >hist;
  undoable_dsu(int n = 0) : cc(n), t(n, {-1, 1}) {}
  int root(int v) const{
    while (t[v].p!=-1) v=t[v].p;
    return v;
  }
  void unite(int u, int v){
    u=root(u),v=root(v);
    assert(u!=v);
    --cc;
    if (t[u].sz<t[v].sz) swap(u,v);
    hist.emplace_back(u,t[u]);
    hist.emplace_back(v,t[v]);
    t[v].p=u;
    t[u].sz+=t[v].sz;
  }
  void undo(){
    ++cc;
    for (int _=2;_--;){
      t[hist.back().first]=hist.back().second;
      hist.pop_back();
    }
  }
  bool same(int u,int v)const {return root(u)==root(v);}
  int size(int v) const {return t[root(v)].sz;}
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int>c(n);
  for (auto&&  e:c){
    cin>>e;
    --e;
  }
  vector<pair<int, int> > edges(n-1);
  vector<vector<int> >g(n);
  for (auto&& [u,v]:edges){
    cin>>u>>v;
    --u,--v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<vector<int> > seg(2 * n);
  auto add = [&](int l,int r,int i){
    for (l+=n,r+=n;l<r;l>>=1,r>>=1){
      if (l&1){
        seg[l++].push_back(i);
      }
      if (r&1){
        seg[--r].push_back(i);
      }
    }
  };
  for (int i=0;i<n-1;++i){
    auto [u, v]=edges[i];
    if (c[u]>c[v]){
      swap(u,v);
    }
    if (c[u]==c[v]){
      add(0,c[u],i);
      add(c[u]+1,n,i);
    }else{
      add(0,c[u],i);
      add(c[u]+1,c[v],i);
      add(c[v]+1,n,i);
    }
  }
  vector<vector<int> >vs(n);
  for (int v=0;v<n;++v){
    vs[c[v]].push_back(v);
  }
  undoable_dsu ud(n);
  vector res(n,(long long)n*(n+1)/2);
  for (int k=0;k<n;++k){
    if (empty(vs[k])){
      res[k]=0;
    }
  }
  auto dfs=[&](auto&& self, int k)->void{
    for (int i:seg[k]){
      ud.unite(edges[i].first,edges[i].second);
    }
    if (k<n){
      self(self,2*k);
      self(self,2*k+1);
    }else{
      set<int>se;
      for (int v:vs[k-n]){
        for (int u:g[v]){
          if (c[u]!=k-n){
            se.insert(ud.root(u));
          }
        }
      }
      long long cur=0;
      for (int v:se){
        long long sz=ud.size(v);
        cur+=sz*(sz+1)/2;
      }
      res[k-n]-=cur;
    }
    for (int i:seg[k]){
      ud.undo();
    }
  };
  dfs(dfs,1);
  for (auto e:res){
    cout<<e<<'\n';
  }
}

Measured memory_bytes: 103844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    cout << (n-1+(k-1)-1)/(k-1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, a, b;
    std::cin >> n >> a >> b;
    if (a % 2 == b % 2) {
        std::cout << (b - a) / 2 << std::endl;
    } else {
        std::cout << std::min(b + a - 1, 2 * n - b - a + 1) / 2 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int cnt[26],i;
	string s;
	bool flag = false;
	fill(cnt,cnt+26,0);
	cin >> s;
	for(i=(s.l_ength()-1); i>=0; --i){
		cnt[s[i]-'a']++;
	}
	for(i=0; i<26; ++i){
		if(!cnt[i]){
			cout << ((char)('a'+i)) << endl;
			flag = true;
			break;
		}
	}
	if(!flag){
		cout << "None" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  int A[N];
  FOR(i,0,N)cin>>A[i];
  int mask=0;
  int l=0,r=0;
  ll ans = 0;
  int same = 0;
  while(r<N){
    bool ok = true;
    FOR(i,0,21){
      if(A[r] & (1 << i)){
        if(mask & (1 << i)) {
          ok = false;
          same |= (1 << i);// 被ってる
        }
        mask |= (1 << i);
      }
    }
    //cout<<22<<endl;
    if(ok){
      r++;
    } else {
      // 戻す
      while(same != 0){
        //cout<<same<<endl;
        FOR(i,0,21){
          if(A[l] & (1 << i)){
            if(same & (1 << i)){
              same ^= (1 << i);
            } else {
              mask ^= (1 << i);
            }
          }
        }
        ans += r - l;
        l++;
      }
      r++;
    }
  }
  while(l<r&&same==0){
    ans+=r-l;
    l++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;
#define inf 100000000/*10^8*/

/////////////////////////////////


int main(){
    int n,a,b;cin>>n>>a>>b;
    if((b-a)%2==1)cout<<"Borys"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
l = {}
ans = 1

for i in range(2, n + 1):
    for j in range(2, i + 1):
        if i%j == 0:
            cnt = 0
            while i%j == 0:
                i //= j
                cnt += 1
            if j in l:
                v = l[j]
                l[j] = cnt + v
            else:
                l[j] = cnt
for i in l.values():
    ans = ans*(i + 1)%(10**9 + 7)

print(ans)

Measured memory_bytes: 9136
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct TEdge
{
    int u, v, c, f;
    TEdge *rev;
    TEdge(int u_ = 0, int v_ = 0, int c_ = 0, int f_ = 0, TEdge *rev_ = nullptr):
        u(u_), v(v_), c(c_), f(f_), rev(rev_) {}
};

const int N = 102;
const int NN = N * N * 2 + 2;
const int M = NN * 4;
const int INF = 1e9;

int h, w, nn, m, source, sink;
char a[N][N];
TEdge el[M];
vector<TEdge*> g[NN];
TEdge *pre[NN];

bool Bfs(int s, int t)
{
    fill(pre+1, pre+1+nn, nullptr);
    queue<int> q;
    q.push(s);
    while (!q.empty())
    {
        int u = q.front(); q.pop();
        for (auto e: g[u])
            if (!pre[e->v] && e->f < e->c && e->v != s) q.push(e->v), pre[e->v] = e;
    }
    return pre[t] != nullptr;
}

void AddEdge(int u, int v, int c)
{
    el[m]   = {u, v, c, 0, el+m+1};
    el[m+1] = {v, u, c, 0, el+m};
    g[u].push_back(el+m);
    g[v].push_back(el+m+1);
    m += 2;
}

int EdmondsKarp()
{
    int flow = 0;
    while (Bfs(source, sink))
    {
        int maxflow = INF;
        for (auto e = pre[sink]; e != nullptr; e = pre[e->u])
            maxflow = min(maxflow, e->c - e->f);
        for (auto e = pre[sink]; e != nullptr; e = pre[e->u])
            e->f += maxflow, e->rev->f -= maxflow;
        flow += maxflow;
    }
    return flow;
}

void Solve()
{
    source = h + w + 1, sink = h + w + 2;
    for (int i = 1; i <= h; ++i)
        for (int j = 1; j <= w; ++j)
        {
            if (a[i][j] == 'o') AddEdge(i, j + h, 1);
            if (a[i][j] == 'S')
            {
                AddEdge(source, i, INF);
                AddEdge(source, j + h, INF);
            }
            if (a[i][j] == 'T')
            {
                AddEdge(i, sink, INF);
                AddEdge(j + h, sink, INF);
            }
        }

    nn = h + w + 2;

    int mincut = EdmondsKarp();
    if (mincut >= INF) printf("-1");
    else printf("%d",mincut);
}

int main()
{
    scanf("%d %d", &h, &w);
    for (int i = 1; i <= h; ++i) scanf("%s",a[i]+1);
    Solve();
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int num[11];
bool judge(int n)
{
	while(n)
	{
		if(num[n%10])
		 return false;
		 n/=10;
	}
	return true;
}
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int b;
		memset(num,0,sizeof(num));
		for(int i=0;i<m;i++)
		{
			scanf("%d",&b);
			num[b]++;
		}
		for(int i=n;;i++)
		{
			if(judge(i))
			  {
			  	  printf("%d\n",i);
			  	  break;
			  }
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,K;
  cin>>N>>K;
  vector<pair<long long,long long>>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i].first>>A[i].second;
  }
  sort(A.begin(),A.end());
  long long count=0;
  for(int i=0;i<N;i++){
    count+=A[i].second;
    if(count>=K){
      cout<<A[i].first<<endl;
      break;
    }
  }
}
    


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

int main(){
  int A, B;
  cin >> A >> B;
  if(A != 1 && B != 1) cout << 1 << endl;
  else if(A != 2 && B != 2) cout << 2 << endl;
  else cout << 3 << endl;
}


Measured memory_bytes: 256