akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

const int maxn = 2e5 + 5;
int fac[maxn];

int fpow(int a, int b) {
  if(b == 0) return 1;
  int ret = fpow(a, b / 2);
  if(b % 2) return mul(ret, mul(ret, a));
  return mul(ret, ret);
}

int inv(int x) {
  return fpow(x, mod - 2);
}

int nck(int n, int k) {
  if(n < k) return 0;
  return mul(fac[n], inv(mul(fac[k], fac[n - k])));
}


int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  fac[0] = 1;
  for(int i = 1; i < maxn; i++) {
    fac[i] = mul(i, fac[i - 1]);
  }
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  int res = 0;
  // cout << h - 1 - a + b << endl;
  // cout << h - a + b - 2 << endl;
  // cout << h + w - 2 << endl;
  for(int i = b; i <= w; i++) {
    res = add(res, mul(nck(h - a - 1 + i, i), nck(a - 1 + w - i - 1, a - 1)));
  }
  cout << res;
}

Measured memory_bytes: 3948
A, B = map(int,input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(set(prime_factorize(A)) & set(prime_factorize(B)))+1)

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

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return

#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define repd(i,a,b) for (ll i = (a); i >= b; i--)
#define repdz(i,a) for (ll i = a; i >=0; i--)
#define trav(a, x) for (auto& a : x)

#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin >>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define full(v) v.begin(),v.end()

void solve()
{
    llin(n);
    set<string> m;
    repz(i,n)
    {
        string s;
        cin >> s;
        m.insert(s);
    }
    cout << sz(m) << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //llin(t);
    //while (t--)
    //{
        solve();
    //}
}


Measured memory_bytes: 19248
def f(n):
    x = 1
    while n*2**x<K:
        x += 1
    return x
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    if i<K:
        ans += 2**(-f(i))/N
    else:
        ans += 1/N
print(ans)

Measured memory_bytes: 39024
#include<iostream>
using namespace std;
int main()
{
  long long int n, i, x, y;
  cin>>n;
  x = n-1;
  y = n+1;
  long long int arr[x], num[y]={0};
  for(i=0; i<x; i++)
  {
      cin>>arr[i];
      num[arr[i]]++;
  }
  for(i=1; i<=n; i++)
  cout<<num[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = 1e7, OO = 0x3f3f3f3f;
int main()
{
  int l;
  scanf("%d",&l);
  printf("%d\n",l*l);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 256
n = int(input())
L = [*map(int, input().split())]
M = {}
for l in L:
    if l in M: M[l] += 1
    else: M[l] = 1
M = list(M.items())
M.sort()
m = len(M)
c = 0
for i in range(m):
    for j in range(i+1, m):
        for k in range(j+1, m):
            if M[i][0]+M[j][0] > M[k][0]:
                c += M[i][1] * M[j][1] * M[k][1]
print(c)


Measured memory_bytes: 9172
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){

int N,M;
int n[51]={};
int i=0,p=0;
while(1){
scanf("%d %d",&N,&M);
if(N==0&&M==0)break;
for(int k=0;k<51;k++)
	n[k]=0;

p=M;i=0;
while(n[i]!=M)
{
if(p==0&&n[i]>0){p=n[i];n[i]=0;}
//else if(p==0&&n[i]==0)
else if(p>0){p--;n[i]++;}
i++;i=i%N;
//if(i==N-1)i=0;
}
cout<<i<<endl;
}
return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>md;
const ll mod=1e9+7;
ll solve(ll x){
    if(md[x]!=0)
        return md[x];
    else
    return md[x]=((solve(x/2)+solve((x-1)/2)+solve((x-2)/2)))%mod;
}
ll n;
int main(){
    md[0]=1;
    md[1]=2;
    cin>>n;
    cout<<solve(n)<<"\n";
    return 0;
}

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

const int inf = 1e9;

int main()
{
    int n; cin >> n;
    string s; cin >> s;

    vector<int> w(n), e(n);
    w[0] = 0; e[n-1] = 0;
    for (int i = 1; i < n; i++) {
        w[i] = w[i-1] + (s[i-1] == 'W');
        e[n-i-1] = e[n-i] + (s[n-i] == 'E');
    }

    // debug
    for (int i= 0; i < n; i++) {
        cerr << w[i] << " " << e[i] << endl;
    }
    int ans = inf;
    for (int i = 0; i < n; i++) {
        ans = min(ans, w[i] + e[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
/*

We walked with our shoulders in line,
Laughing about things that didn't matter as we looked onward toward the same dream.
If I listen carefully, I can still hear it:
Your voice, staining this city orange.

When you're not around, I'm so bored,
But when I say I'm lonely, you just laugh at me.
I just keep counting up the things I have left,
That shine brightly and never fade away.

Like the sky after the rain lets up... like clearing up one's heart...
I remember your smile; it floats up in my mind and I can't help but smile.
Surely, just as we were that day... like innocent children,
We'll run through the passing seasons, seeing each of our many tomorrows.

Whenever I was alone and started to feel uneasy...
On nights I didn't want to sleep, we'd just go on talking.

I wonder what you'll go on to see from here,
And what I'll see right here.
I'll try to entrust my tears,
To this city where the setting sun stains everything orange.

This single love was born among a million rays of light;
Even if you never change... even if you happen to change... you're you, so I'm not worried.
Someday we'll both become adults and meet wonderful people;
At that time, I hope we can bring along our irreplaceable families and meet here again...

Like the sky after the rain lets up... like clearing up one's heart...
I remember your smile; it floats up in my mind and I can't help but smile.
This single love was born among a million rays of light...
We run through the passing seasons, seeing each of our many tomorrows;
Choosing from each of our many dreams.

*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int bit[N], n;
char s[N];

int find(int i) {
  int ret = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) ret += bit[i];
  return ret;
}

void add(int i, int v) {
  for (; i < N; i |= i + 1) bit[i] += v;
}

bool can(int d) {
  memset(bit, 0, sizeof(bit));
  for (int i = 1; i + d - 1 <= n; i++) {
    int now = (s[i] - '0' + find(i)) % 2;
    if (now) {
      add(i, 1);
    }
  }
  int ada = 0;
  for (int i = 1; i <= n; i++) {
    int now = (s[i] - '0' + find(i)) % 2;
    if (now) {
      break;
    } else {
      ada++;
    }
  }
  return ada >= d;
}

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (can(mid)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 768
s=list(input())
t=list(input())

s.sort()
t.sort()
t = t[::-1]

ss = ''
tt = ''
for i in range(len(s)):
    ss += s[i]
for i in range(len(t)):
    tt += t[i]

if ss < tt:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import math

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

Pro = 0

for i in range(1, N+1):
    try:
        count = math.ceil(math.log2(K / i))
        if count < 0:
            count = 0

    except ValueError:
        count = 0

    Pro += ((0.5) ** count) / N

print(Pro)

Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, usize);
    let X = read![[i64]];

    let mut mi = std::i64::MAX;
    for r in K..N + 1 {
        let lx = X[r - K];
        let rx = X[r - 1];

        if lx >= 0 {
            mi = min(mi, rx);
        } else if rx <= 0 {
            mi = min(mi, -lx);
        } else {
            mi = min(mi, min(2 * rx - lx, rx - 2 * lx));
        }
    }

    println!("{}", mi)
}


Measured memory_bytes: 8444
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int>pii;
typedef long long ll;
vector<pii>pat[100000];
int col[100000];
bool flag[100000];
bool isok;
bool cont;
ll cnt[3];
int ec;
void dfs(int node, int c)
{
	if (flag[node])
	{
		if (col[node] != c)cont = true;
		return;
	}
	flag[node] = true;
	col[node] = c;
	cnt[c]++;
	int f1 = 0, f2 = 0;
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (pat[node][i].second == 1)f1++;
		else f2++;
		dfs(pat[node][i].first, (c + pat[node][i].second) % 3);
	}
	ec += pat[node].size();
	if (f1 > 0 && f2 > 0)isok = true;
}
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(make_pair(zb, 1));
		pat[zb].push_back(make_pair(za, 2));
	}
	ll ans = 0;
	for (int i = 0; i < num; i++)
	{
		if (!flag[i])
		{
			isok = cont = false;
			cnt[0] = cnt[1] = cnt[2] = 0;
			ec = 0;
			dfs(i, 0);
			if (!isok)ans += ec / 2;
			else
			{
				if (!cont)ans += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];
				else ans += (cnt[0] + cnt[1] + cnt[2])*(cnt[0] + cnt[1] + cnt[2]);
			}
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 12416
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())


int mem[1000000];
int ans[1000000];

int main(int argc, char const *argv[])
{
	int max_num = 1000000;
	int loop_max = sqrt(1000000);
	memset(mem, 0, 1000000);
	for (int i = 2; i < loop_max; i++)
	{
		int c = i * i;
		while(c < max_num)
		{
			mem[c] = 1;
			c+= i;
		}
	}
	int n;
	int sum = 0;
	ans[0] = ans[1] = 0;
	for (int i = 2; i < max_num; i++)
	{
		sum += mem[i] ? 0 : 1;
		ans[i] = sum;
	}
	while(scanf("%d", &n) != EOF)
	{
		printf("%d\n", ans[n]);
	}
	return 0;
}

Measured memory_bytes: 10992
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
    int n,m;
    cin >> n>> m;

    long double p = 1.0/modpow(2,m);
    long double miss = 1-p;
    
    int time = (n-m)*100 + m*1900;

    double ans = 0;
    int i = 1;
    
    while(1){
       // P(ans);
        if((time*i)*p <= 0)break;
        
        ans += (time*i)*p;
        
        p *= miss;
        i++;
    }

    P(ans);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> vec1(M);
  vector<int> vec2(M);
  
  for(int h=0;h<M;h++) {
    cin >> vec1.at(h);
  }
  
  for(int h=0;h<M;h++) {
    cin >> vec2.at(h);
  }
  
  vector<int> road(N,0);
  
  for(int i=0;i<M;i++) {
    road.at(vec1.at(i)-1)++;
    road.at(vec2.at(i)-1)++;
  }
    
    
    for(int i=0;i<N;i++) {
    cout << road.at(i) << endl;
   }
}

Measured memory_bytes: 256
#include <stdio.h>

int x[200010];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++) scanf("%d",&x[i]);
	x[b+1] = a+x[1];
	
	int ans = x[2]-x[1];
	for(int i=2;i<=b;i++) ans = ans>x[i+1]-x[i]?ans:x[i+1]-x[i];
	printf("%d",a-ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  
 int a;
cin >>a;
  
long long int x[110],y[110],h[110];

  
for (int i=0;i<a;i++){
cin >>x[i] >>y[i] >> h[i];
}
for (int posx=0;posx<=100;posx++){
  
      for (int posy=0;posy<=100;posy++){
            for ( int nh=(h[0]-250);nh<=h[0]+250;nh++){
              
    bool abcd=true;
              
         for ( int i=0;i<a;i++){
           
long long int k=0;
if(h[i]!=max(nh-abs(posx-x[i])-abs(posy-y[i]),k)) abcd=false;
}
if (abcd==true) 
  cout <<posx <<" "<< posy <<" "<<nh <<endl;
           }
      }
}
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
namespace SOLVE {
	VI parent;

	int find_parent(int a) {
		if (parent[a] == a) {
			return a;
		}
		parent[a] = find_parent(parent[a]);
		return parent[a];
	}

	void unite(int a, int b) {
		int parenta = find_parent(a);
		int parentb = find_parent(b);
		if (parenta == parentb) {
			return;
		}
		parent[parenta] = parentb;
	}

	int same(int a, int b) {
		return find_parent(a) == find_parent(b);
	}

	void main() {
		int n, q;
		int a, b, c;
		cin >> n >> q;
		parent.resize(n);
		REP(i, 0, n) {
			parent[i] = i;
		}
		REP(i, 0, q) {
			cin >> a >> b >> c;
			if (a == 0) {
				unite(b, c);
			}
			else {
				cout << same(b, c) << endl;
			}
		}
	}
}


signed main() {

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
long long n,a[100002],z,zs;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
      cin>>a[i];
    sort(a+1,a+n+1);
    z=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])z=(z+1)%2;
        else zs+=z,z=1;
    }
    if(z%2)zs++;
    cout<<zs<<endl;
    return 0;
}

Measured memory_bytes: 1152
a,b,c,x = 4.times.map{gets.to_i}

ans = 0
(a+1).times{|i|
  (b+1).times{|j|
    (c+1).times{|k|
      ans += 1 if i*500+j*100+k*50 == x
    }
  }
}
p ans

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

int main(){    
    int N,K;
    cin >> N >> K;
    if(K == 1) cout << 0;
    else cout << N-K;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  string str = readString();

  int ans = 0, tmp = 0;
  REP(i, str.length()) {
    if (str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T') {
      ++tmp;
    } else {
      chmax(ans, tmp);
      tmp = 0;
    }
  }
  chmax(ans, tmp);
  print(ans);
}


Measured memory_bytes: 2304
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def ceil(a,b):
    return a//b + int(a%b != 0)

N,X,T = LI()

print(ceil(N,X)*T)

Measured memory_bytes: 65328
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 300005;
ll T,n,mm;
struct node{
	int a,b;
}num[maxn];

bool cmp(node q,node p){
	if(q.a==p.a){
		return q.b>p.b;
	}
	else 
		return q.a<p.a;
}
priority_queue<vector<int> > q;
vector<int> m[maxn];
int main() {
	cin>>n>>mm;
	for(int i=0;i<n;i++)
		cin>>num[i].a>>num[i].b;
	sort(num,num+n,cmp);
	int cnt = 1;
	for(int i=0;i<n;i++){
		m[num[i].a].push_back(num[i].b);
	}
	ll sum = 0;
	for(int i=1;i<=mm;i++){
		if(m[i].size()==0&&q.empty())
			continue;
		if(m[i].size()!=0) q.push(m[i]);
		vector<int> t;
		t = q.top();	
		q.pop();
		sum+=t[0];
    	vector<int>::iterator k = t.begin();
		t.erase(k);
		if(t.size()!=0)
			q.push(t);
	}
	cout<<sum<<endl;
}



Measured memory_bytes: 11648
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=10001,maxm=40001;
struct Edge{
    int from,to,cost,dist,next;
};
struct node{
    int d,c,v;
    node(){}
    node(int d,int c,int v):d(d),c(c),v(v){}
};
bool operator <(node a,node b){
    if(a.d==b.d) return a.c>=b.c;
    else return a.d>=b.d;
}
Edge edge[maxm];
int head[maxn];
bool mark[maxn];
int n,m,cnt;
void init(){
    memset(head,-1,sizeof(head));
    memset(mark,false,sizeof(mark));
    cnt=0;
}
void adde(int from,int to,int dist,int cost){
    edge[cnt].from=from;
    edge[cnt].to=to;
    edge[cnt].dist=dist;
    edge[cnt].cost=cost;
    edge[cnt].next=head[from];
    head[from]=cnt++;
}
int main(void){
    //freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&m)&&n!=0){
        init();
        int a,b,c,d,ans=0;
        for(int i=0;i<m;i++){
            scanf("%d%d%d%d",&a,&b,&c,&d);
            adde(a,b,c,d);
            adde(b,a,c,d);
        }
        priority_queue<node> pq;
        pq.push(node(0,0,1));
        while(!pq.empty()){
            node ongo=pq.top();
            pq.pop();
            if(mark[ongo.v]) continue;
            mark[ongo.v]=true;
            ans+=ongo.c;
            for(int i=head[ongo.v];~i;i=edge[i].next){
                Edge& e=edge[i];
                if(mark[e.to]==false)
                    pq.push(node(ongo.d+e.dist,e.cost,e.to));
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    if (k*2>=b-a+1)
        for (int i = a ; i <=b ; i++)
            cout<<i<<endl;
    else{
        for (int i = a ; i<a+k ; i++)
            cout<<i<<endl;
        for (int i = b-k+1 ; i<=b ; i++)
            cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 200000 + 5;
int n, x[N], y[N];
int mn = 1e9 + 10, mx = -1;

ll get(int s, int e, int v) {
	if (v <= s) return s - v;
	return v - e;
}

ll calc1() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn1 = mn;
	vector<pair<int, int> > v, u;
	for (int i = 0; i < n; ++i) {
		if (x[i] == mn) {
			mx2 = max(mx2, y[i]);
			mn2 = min(mn2, y[i]);
		}
		else if (y[i] == mx) {
			mx2 = max(mx2, x[i]);
			mn2 = min(mn2, x[i]);
		}
		else {
			v.push_back(make_pair(x[i], y[i]));
		}
	}
	int xd, yd;
	int mn3 = 1e9 + 10, mx3 = -1;
	bool ok = true;
	u.clear();
	for (int i = 0; i < v.size(); ++i) {
		xd = v[i].X, yd = v[i].Y;
		if (xd > yd) swap(xd, yd);
		if (xd >= mn2) mx2 = max(mx2, xd);
		else if (yd <= mx2) mn2 = min(mn2, yd);
		else u.push_back(make_pair(xd, yd));

	}
	u.swap(v);
	int xdd, ydd;
	for (int i = 0; i < v.size(); ++i) {
		xd = v[i].X, yd = v[i].Y;

		xdd = get(mn2, mx2, xd);
		ydd = get(mn2, mx2, yd);

		if (xdd < ydd) {
			mx2 = max(mx2, xd);
			mn2 = min(mn2, xd);
		}
		else {
			mx2 = max(mx2, yd);
			mn2 = min(mn2, yd);
		}
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

ll calc2() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn2 = mn;
	for (int i = 0; i < n; ++i) {
		mn1 = min(mn1, y[i]);
		mx2 = max(mx2, x[i]);
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", x + i, y + i);
		mn = min(mn, min(x[i], y[i]));
		mx = max(mx, max(x[i], y[i]));
	}

	if (mn == mx) return puts("0"), 0;
	for (int i = 0; i < n; ++i)
		if (x[i] > y[i])
			swap(x[i], y[i]);

	printf("%lld\n", min(calc1(), calc2()));
	return 0;
}

Measured memory_bytes: 4084
#include <stdio.h>
#include <stdlib.h>
#define MAX_V 100
#define INF_COST (1LL << 62)

static void warshall_floyd(long long g[MAX_V][MAX_V], int size) {
  int i, j, k;
  long long cost;

  for (k = 0; k < size; ++k) {
    for (i = 0; i < size; ++i) {
      if (g[i][k] == INF_COST) continue;
      for (j = 0; j < size; ++j) {
        if (g[k][j] == INF_COST) continue;
        cost = g[i][k] + g[k][j];
        if (cost < g[i][j]) g[i][j] = cost;
      }
    }
  }
}

int main(int argc, char **argv) {
  int v, e, i, j, s, t, d;
  long long g[MAX_V][MAX_V];

  for (i = 0; i < MAX_V; ++i) {
    for (j = 0; j < MAX_V; ++j) g[i][j] = i == j ? 0LL : INF_COST;
  }
  scanf("%d %d", &v, &e);
  for(i = 0; i < e; ++i) {
    scanf("%d %d %d", &s, &t, &d);
    g[s][t] = d;
  }
  warshall_floyd(g, v);
  for (i = 0; i < v; ++i) {
    if (g[i][i] < 0) {
      printf("NEGATIVE CYCLE\n");
      exit(0);
    }
  }
  for (i = 0; i < v; ++i) {
    for (j = 0; j < v; ++j) {
      if (j > 0) printf(" ");
      if (g[i][j] == INF_COST) {
        printf("INF");
      } else {
        printf("%lld", g[i][j]);
      }
    }
    printf("\n");
  }
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(int i=(a);i<(int)(b);i++)
#define repi(i,n) fori(i,0,n)
#define forr(i,a,b) for(int i=int(b-1);i>=int(a);i--)
#define repr(i,n) forr(i,0,n)
#define all(x) (x).begin(),(x).end()
#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
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;}

void solve(ll n){
    if(n%2==1){
        cout<<0<<endl;
        return;
    }
    n/=2;
    ll ans=0;
    ll base=5;
    while(base<=n){
        ll tmp=n/base;
        ans+=tmp;
        base*=5;
    }
    cout<<ans<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    solve(n);
    return 0;
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
l = [int(input()) for i in range(q)]

points = [k - q] * n
for i in range(q):
    points[l[i] - 1] += 1
for i in points:
    if i <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 10472
#include <iostream>
#include <algorithm>

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

using namespace std;
int main(){
	int n;
	cin >> n;
	while(n != 0){

		int bit = 1 << n;
		int t[20][20];
		int dp[100000];
		
		rep(i, n){
			rep(j, n + 1){
				cin >> t[i][j];
			}
		}


		rep(i, bit + 2) dp[i] = 1 << 20;
		dp[0] = 0;

		rep(i, bit){
			if(dp[i] == 1 << 20) continue;
			rep(next, n){
				// ステージ攻略状況
				if((i & (1 << next)) != 0) continue;
				int minCost = t[next][0];
				// すでに攻略済みのステージアイテムからの最小タイムを求める
				rep(j, n){
					if((i & (1 << j)) != 0){
						minCost = min(minCost, t[next][j+1]);
					}
				}
				
				int a = (i | (1 << next));
				dp[a] = min(dp[a], dp[i] + minCost);
			}
		}
		cout << dp[bit -1] << endl;
		cin >> n;
	}
	return 0;
}

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

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

using namespace std;

int sum[2][100000];

int main() {
  int n,m;
  cin>>n>>m;
  vector<tuple<int,int>> ss;
  REP(i,n){
    int s,t;
    cin>>s>>t;
    ss.emplace_back(s,t);
  }
  vector<int> p(m+1, 0);
  sum[0][0] = sum[1][0] = 0;
  REP(i,m) {
    cin>>p[i+1];
  }
  sort(begin(p),end(p));
  REP(i,m) {
    sum[i&1][i/2+1] = p[i+1] - p[i];
    sum[i&1][i/2+1] += sum[i&1][i/2];
  }
  int64_t ans = 0;
  REP(i,n){
    int s,t;
    tie(s,t)=ss[i];
    int inds = lower_bound(begin(p),end(p),s) - begin(p);
    int indt = lower_bound(begin(p),end(p),t) - begin(p);
    if (inds == indt) {
      ans += max(s,t) - min(s,t);
      continue;
    }
    if (s > t) {
      ans += s - p[inds - 1];
      if (((inds + indt) % 2) == 0)
        ans += p[indt] - t;
      if ((inds % 2) == 1)
        ans += sum[0][inds/2] - sum[0][(indt+1)/2];
      else
        ans += sum[1][(inds-1)/2] - sum[1][indt/2];
    } else {
      ans += p[inds] - s;
      if (((inds + indt) % 2) == 0)
        ans += t - p[indt - 1];
      if ((inds % 2) == 1)
        ans += sum[0][indt/2] - sum[0][(inds+1)/2];
      else
        ans += sum[1][(indt-1)/2] - sum[1][inds/2];
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

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

int main()
{
	int a, b;
	
	cin >> a >> b;
	
	if(a > b)
		cout << "a > b" << endl;
	else if(a < b)
		cout << "a < b" << endl;
	else
		cout << "a == b" << endl;
	
	return 0;
}



Measured memory_bytes: 3080
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+4;
int n;
ll m;
double a[N];
double l=1e9,r=0;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
template <class T> inline void smax(T &x,T y) {
	x=x<y?y:x;
}
template <class T> inline void smin(T &x,T y) {
	x=x>y?y:x;
}
inline bool ok(double x) {
	ll cnt=0;
	for (register int i=1;i<=n;++i) {
		cnt+=(ll)ceil(a[i]/x)-1;
		if (cnt>m) return false;
	}
	return true;
}
int main() {
	n=read(),m=read();
	for (register int i=1;i<=n;++i) {
		scanf("%lf",&a[i]);
		smax(r,a[i]);
		smin(l,a[i]/(m+1));
	}
	while (r-l>1e-2) {
		double mid=(l+r)/2;
		if (ok(mid)) r=mid;
		else l=mid;
	}
	cout<<(ll)ceil(l)<<endl;
	return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    ll N;
    cin >> N;
    for (ll h = 1; h <= 3500; ++h) {
        for (ll n = 1; n <=3500 ; ++n) {
            ll bunsi = N*h*n,bunbo = 4*h*n-N*n-N*h;
            if(bunbo > 0 && bunsi%bunbo == 0){
                cout << h << ' ' << n << ' ' << (bunsi/bunbo) << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main(){
	int s;
	scanf("%d",&s);
	int sec=s%60;
	int hour=floor(s/3600);
	int min=((s-sec-hour*3600)/60);
	printf("%d:%d:%d\n",hour,min,sec);
	return 0;
}

Measured memory_bytes: 2760
N = int(input())
lists = []
flag = 0
for i in range(N):
    W = str(input())
    lists.append(W)
    if i == 0:
        last = W[-1]
    else:
        if W[0] == last:
            last = W[-1]
        else:
            flag = 1
    
if flag == 1:
    print("No")
    exit()
for i in range(N):
    for j in range(N):
        if i != j:
            if lists[i] == lists[j]:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3064
//BISMILLAHIR RAHMANIR RAHIM
//ALLAH HU AKABR
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  string s;
  cin>>s;
  string t,k;
 int n=s.size();
 int m=(n+3)/2;
  t=s.substr(0,(n-1)/2);
  k=s.substr(m-1,n);
  string s1,s2,s3;
  s1=s;
  s2=t;
  s3=k;
  reverse(s1.begin(),s1.end());
  reverse(s2.begin(),s2.end());
  reverse(s3.begin(),s3.end());
  if(s1==s && s2==t && s3==k)
  {
      cout<<"Yes"<<endl;
  }
else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    int a=0;
    for(int i=0;i<3;i++)
    {
        int f=0;
        for(int j=i;j<3;j++)
        {
            f=0;
            for(int k=i;k<=j;k++){
            if(s[k]!='R')
            {
                f=1;
                break;
            }}
            if(f==0)
        a=max(a, j-i+1);
        }
    }
    cout<<a;
}

Measured memory_bytes: 3616
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

vector<vector<int>> v(200100);
vector<int> res(200100);

void dfs(int now, int p)
{
	for (int next : v[now])
	{
		if (next == p)continue;
		res[next] += res[now];
		dfs(next, now);
	}
}

int main()
{
	int n, q; cin >> n >> q;
	rep(i, n - 1)
	{
		int a, b; cin >> a >> b;
		--a, --b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	rep(i, q)
	{
		int p, x; cin >> p >> x;
		--p;
		res[p] += x;
	}
	dfs(0, -1);
	rep(i, n)cout << res[i] << " ";
}

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

int main(){
  int n,x,y;
  cin >> n >> x >> y;
  vi ans(n,0);
  int diff;
  for(int i=1; i<=n-1; i++){
    for(int j=i+1; j<=n; j++){ 
      if(j-i > abs(x-i) + 1 + abs(y-j)) diff = abs(x-i) + 1 + abs(y-j);
      else diff = j-i;
      ans[diff] ++;
    }
   
  }
  for(int i=1; i<n; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 3524
class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

import sys
input=sys.stdin.readline
n=int(input())
UF=UF(2*10**5)
for i in range(n):
  x,y=map(int,input().split())
  UF.unite(x-1+10**5,y-1)
UF.groupnum()
ct=[[0,0] for i in range(2*10**5)]
for i in range(2*10**5):
  if i<10**5:
    ct[UF._parent[i]][0]+=1
  else:
    ct[UF._parent[i]][1]+=1
ans=0
for i in range(2*10**5):
  ans+=ct[i][0]*ct[i][1]
print(ans-n)

Measured memory_bytes: 93772
#include <cstdio>

long long cnt[10][10];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		int tail = i % 10;
		int head = i;
		while (head >= 10) head /= 10;
		cnt[head][tail]++;
	}
	long long ans = 0;
	for (int i = 1; i <= 9; ++i)
	{
		for (int j = 1; j <= 9; ++j)
		{
			ans += cnt[i][j] * cnt[j][i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define SIZE 100
#define GOLD 100
int main()
{
  int n,m,p;
  int i;
  int x,num;
  int sum;
  while(1)
    {
      scanf("%d%d%d",&n,&m,&p);
      if((n==0)&&(m==0)&&(p==0)) break;
      sum=0;
      for(i=1;i<=n;i++)
	{
	  scanf("%d",&x);
	  sum+=x;
	  if(i==m) num=x;
	}
      if(num==0) printf("0\n");
      else printf("%d\n",sum*(100-p)*GOLD/(100*num));
    }
  return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,x,t;
    cin>>n>>x>>t;
    cout<<((n-1)/x+1)*t;
}

Measured memory_bytes: 3632
from bisect import bisect_left as b;n,q=map(int,input().split());w=sorted([list(map(int,input().split()))[::-1]for _ in[0]*n]);p=[int(input())for _ in[0]*q];a=[-1]*q;o=[-1]*q
for x,t,s in w:
  l,r=b(p,s-x),b(p,t-x)
  while l<r:
    if o[l]+1:l=o[l]
    else:a[l],o[l]=x,r;l+=1
print(*a)

Measured memory_bytes: 62508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

int main(void){
    int a,b;
    cin>>a>>b;
    cout<<((a<=8 && b<=8) ? "Yay!" : ":(")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
	int size, signal=0;
	cin>>size;
	string a;
	cin>>a;
	for (int i=0; i<size/2; i++){
		if (a[i]!=a[size/2+i]){
			signal=1; break;
		}
	}
	if (signal==1||size%2==1) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
from collections import defaultdict


def solve():
    s = input()
    t = input()

    n = len(s)
    index = defaultdict(list)
    for i, char in enumerate(s):
        index[char] += [i]
    
    cur, orbit = -1, 0
    for char in t:
        target = index[char]
        if not target:
            print(-1)
            exit()
        
        i = bisect_left(target, cur + 1)
        if i < len(target):
            cur = target[i]
        else:
            cur = target[0]
            orbit += 1
    print(n*orbit + cur + 1)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 7924
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 



void solve()
{
	string t ; 
	cin>>t;
	rep(i  ,t.size()){
		if(t[i]=='?'){
			t[i] = 'D' ;
		}
	}
	cout<<t<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3908
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//






//BFS式のトポロジカルソート
//
int N, M;
vector<vector<int>> G;
vector<int> deg; //各頂点の入次数

int dp[100100];
int main(){
        cin >> N >> M;
        G.assign(N, vector<int>());
        deg.assign(N,0);

        for(int i = 0; i < M; i++){
                int x,y;
                cin >> x >> y;
                x--;
                y--;
                G[x].push_back(y);
                deg[y]++;
        }

        //他の頂点から辺が入ってきていない頂点を入れる
        queue<int> que;
        for(int v = 0; v < N; v++) if(deg[v] == 0) que.push(v);

        //BFS
        while(!que.empty()){
                int v = que.front(); 
                que.pop();
                for(auto nv : G[v]){
                        deg[nv]--;
                        if(deg[nv] == 0){
                                que.push(nv);
                                chmax(dp[nv], dp[v]+1);
                        }
                }
        }

        int res = 0;
        for(int v = 0; v < N; v++) chmax(res, dp[v]);
        cout << res << endl;
        return 0;


}









































Measured memory_bytes: 6528