akhauriyash/Code-Regression huggingface dataset:
inputs = gets.chomp.split.map(&:to_i)
n = inputs[0]
m = inputs[1]
x = inputs[2]
y = inputs[3]
xs = gets.chomp.split.map(&:to_i).sort
ys = gets.chomp.split.map(&:to_i).sort

nums = (-100..100).to_a
nums.reject!{ |num| num <= x || y < num }
nums.reject!{ |num| num <= xs[n-1] }
nums.reject!{ |num| ys[0] < num }

if nums.count != 0
  puts 'No War'
else
   puts 'War'
end


Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    if (n % 1000 == 0)
        printf("0\n");
    else
        printf("%d\n", 1000 - n % 1000);
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a[5];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<a[0]<<' '<<a[1]<<' '<<a[2]<<'\n';
  return(0);
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct UF
{
  vector<int> par;
  vector<int> sz;
  vector<int> rank;
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int n){return sz[find(n)];}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  vector<pair<ll,ll>>pll(m);
  for(int i=0;i<m;i++){
    cin>>pll[i].F>>pll[i].S;
    pll[i].F--;pll[i].S--;
  }
  ll ans = 0;
  for(int i=0;i<m;i++){
    UF uni(n);
    for(int j=0;j<m;j++){
      if(i==j)continue;
      uni.merge(pll[j].F,pll[j].S);
    }
    if(uni.size(0) != n)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
list = list(map(int, input().split()))

counter, i = 0, 0
new_list = []
while(True):
    if list[i] % 2 != 0:
        print(counter)
        break
    else:
        new_list.append(list[i] / 2)
        i += 1

    if i == n:
        list.clear()
        for e in new_list:
            list.append(e)
        new_list.clear()
        counter += 1
        i = 0

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  string W;
  char p,l;
  bool flag = true;
  set<string> S;
  rep(i,N){
    cin >> W;
    if (S.count(W)) flag = false;
    S.insert(W);
    p = W[0];
    if (i>0 && l!=p) flag = false; 
    l = W[W.size()-1];
    
  }
  cout << (flag? "Yes" : "No") << endl;


  // cout << fixed << setprecision(6);
  return 0;
}


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

int main()
{
    int i, j, k,a=0;
    char s[4],t[4];
    scanf("%s %s", s,t);
    for (i = 0; i < 3;i++)
    {
        if(s[i]==t[i])
            a++;
    }
        printf("%d",a);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long int n, S;
long long int  a[3030], dp[3030][3030];
long long int solve(int i, int j){

    if(dp[i][j] != -1)
        return dp[i][j];

    if(i > j)
        return 0LL;

    return dp[i][j] = max(a[i] + min(solve(i + 2, j), solve(i + 1, j - 1)),
                          a[j] + min(solve(i + 1, j - 1), solve(i, j - 2)));
}
int main(){
    //freopen("test.in", "r+", stdin);
    memset(dp, -1, sizeof dp);

    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i], S += a[i];
    cout<<2 * solve(0, n - 1) - S<<endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    int p = vec.at(0);
    long long num = 10000000;
    int sum = 0;
    while( p <= vec.at(n-1)){
        for(int j = 0; j < n; j++){
            sum += (vec.at(j) - p)*(vec.at(j) - p);
        }
        if(sum < num){
            num = sum;
        }
        p++;
        sum = 0;
    }
    cout << num <<endl;
}


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

int main(){
  string s;
  cin>>s;
  int kk=s.length();
  int t=(kk-1)/2;
  for(int i=0;i<t;i++){
    if(s[i]!=s[i+t+1]){printf("No\n");return 0;}
  }
  for(int i=0;i<t/2+1;i++){
    if(s[i]!=s[t-1-i]){printf("No\n");return 0;}
  }
  printf("Yes\n");
}


Measured memory_bytes: 3616
//ABC0118A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

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

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<string> W(N);
	for(int i=0;i<N;i++){
		cin>>W[i];
	}
	char head=W[0][W[0].size()-1];
	for(int i=1;i<N;i++){
		if(W[i][0]!=head){
			cout<<"No"<<endl;
			return 0;
		}
		for(int j=0;j<N;j++){
			if(j==i){
				continue;
			}
			if(W[j]==W[i]){
				cout<<"No"<<endl;
				return 0;
			}
		}
		head=W[i][W[i].size()-1];
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b;

int main(){
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }else if(6 <= a && a  <= 12){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
INF = 100 * 40 + 1

N, Ma, Mb = gets.split.map( &:to_i )
A, B, C = Array.new( N ) do
	gets.split.map( &:to_i )
end.transpose

dp = Array.new( 64 ) do ||
	Array.new( 512 ) do ||
	Array.new( 512, INF )
	end
end
dp[0][0][0] = 0;

N.times do |i|
	512.times do |j|
		512.times do|k|
			next if dp[i][j][k] == INF

			if dp[i][j][k] < dp[ i + 1 ][j][k] then
				dp[ i + 1 ][j][k] = dp[i][j][k]
			end
			if dp[i][j][k] + C[i] < dp[ i + 1 ][ j + A[i] ][ k + B[i] ] then
				dp[ i + 1 ][ j + A[i] ][ k + B[i] ] = dp[i][j][k] + C[i]
			end
		end
	end
end

res = INF
512.times do |j|
	512.times do |k|
		res = dp[N][j][k] if 0 < j && 0 < k && Ma * k == j * Mb && dp[N][j][k] < res
	end
end

puts res == INF ? -1 : res


Measured memory_bytes: 136956
def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum += c[i]*(d-last_d[i])
        
    return (score - sum)

def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    #print(c)

    #print(s)

    last_d = [0 for i in range(26)]
    
    ans = []
    
    score = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * ((i+1)-last_d[j])):
                max = s[i][j] + c[j] * ((i+1)-last_d[j])
                idx = j
        last_d[idx] = i+1
        score += s[i][j]
        down_score(i+1,c,last_d,score)
        
        ans.append(idx)

    for i in range(D):
        print(ans[i]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9520
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var s = o.a(1);
  var r = 0, b = 0;
  for(var i = 0; i < n; i++){
    if(s[i] === "R")r++;
    else b++;
  }
  return r > b ? "Yes" : "No";
}

Measured memory_bytes: 21064
x, k, d = map(int, input().split())

xdivd=x//d

if abs(xdivd)+1>k:
    # print('a')
    print(abs(abs(x)-d*k))
elif (k-abs(xdivd))%2==0:
    # print('b')
    print(abs(x-d*xdivd))
else:
    # print('c',xdivd)
    print(abs(x-(xdivd+1)*d))

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  int r;
  cin>>r;
  cout<<r*r<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll t[1010],a[1010];

int main(void){
	int i;

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

	int N;
	cin >> N;
	for(i=1;i<=N;i++){
		cin >> t[i] >> a[i];
	}

	for(i=2;i<=N;i++){
		ll x=(t[i-1]+t[i]-1)/t[i],y=(a[i-1]+a[i]-1)/a[i];
		ll d=max(x,y);
		t[i]=d*t[i];
		a[i]=d*a[i];
	}

	cout << t[N]+a[N] << endl;

	return 0;
}


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

typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<ll>A(n), B(n), C(n);
    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < n; i++) cin >> B[i];
    for (int i = 0; i < n; i++) cin >> C[i];
    sort(B.begin(),B.end()); sort(C.begin(),C.end());
    vector<ll>a_lower(n), b_lower(n);
    for (int i = 0; i < n; i++){
        a_lower[i] = B.end() - upper_bound(B.begin(), B.end(), A[i]);
    }
    for (int i = 0; i < n; i++){
        b_lower[i] = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    }
    vector<ll>b_sum(n+1);
    for (int i = 1; i <= n; i++){
        b_sum[i] = b_sum[i-1] + b_lower[n-i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        ans += b_sum[a_lower[i]];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4992
s = input()
n = len(s)-1
ans = 0
for bit in range(1<<n):
    op = bin(bit)[2:].zfill(n)
    formula = ''
    for i in range(n):
        formula += s[i]
        if op[i] == '1':
            formula += '+'
    else:
        formula += s[len(s)-1]
        ans += eval(formula)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans,temp;
int a[11111111];
int main()
{
      cin>>n;
      for(int i=1;i<n;i++)
      {
      	cin>>temp;
      	a[temp]++;
      }
      for(int i=1;i<=n;i++)
      {
      	cout<<a[i]<<endl;
      }
} 

Measured memory_bytes: 4416
n,ma,mb = map(int,input().split())
L = []
sa = 0
sb = 0
for i in range(n):
    a,b,c = map(int,input().split())
    sa += a
    sb += b
    L.append([a,b,c])
dp = [[[10000 for i in range(sb+1)] for i in range(sa+1)] for i in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    a = L[i][0]
    b = L[i][1]
    c = L[i][2]
    for j in range(sa+1):
        for k in range(sb+1):
            if j-a >= 0 and k-b >= 0:
                dp[i+1][j][k] = min(dp[i][j-a][k-b]+c,dp[i+1][j][k],dp[i][j][k])
            else:
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k])
k = max(ma,mb)
t = min(sa,sb)
cur = 1
ans = 10000
while k*cur <= t:
    ans = min(ans,dp[n][ma*cur][mb*cur])
    cur += 1
if ans == 10000:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 63836
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

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

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b,a[li],k,flag;
lo cev;
string s;
vector<lo> v;

void solve(){
	scanf("%lld %lld %lld",&n,&m,&k);
	cev=min(n+m,m+k);
	cev=min(cev,n+k);
	printf("%lld\n",cev);
}

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


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = 0
maxi = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        ans += 1
    else:
        maxi = max(ans,maxi)
        ans = 0
print(max(maxi,ans))

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define MOD 1000000007
#define int long long
int MAX(int C,int D){
  if(C>D) swap(C,D);
  while(1){if(D%C==0){return C; break;} //前提
           int X=C;
           C=D%C;
           D=X;
  }
}
int MIN(int C,int D){
  return C*D/MAX(C,D);
}
int Fact(int X){
  int ans=1;
  rep(i,2,X+1) ans*=i;
  return ans;
}
int FIB(int X){
  if(X<=0) return 0;
  else if(X<=2) return X;
  else{
  int a=1,b=2;
  rep(i,2,X){int c=a;
             a=b;
             b+=c;
             a%=MOD;
             b%=MOD;
            }
  return b;
  }
}
//Librury
signed main(){
  int N,M;
  cin>>N>>M;
  int X=-1,Y;
  int ans=1;
  if(M>=1){
  cin>>Y;
  if(Y==1) X=Y;
  else{
  ans*=FIB(Y-X-2);
  X=Y;
  ans%=MOD;
  }
  rep(i,1,M){cin>>Y;
             if(Y-X!=2)
            ans*=FIB(Y-X-2);
             X=Y;
             ans%=MOD;
             //cout<<ans<<endl;
    }
  }
  if(X+1!=N)
  ans*=FIB(N-X-1);
  cout<<ans%MOD<<endl;
}

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

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

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


//------------------------------------------
struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N,-1) {} 

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

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

    bool same(int x, int y) { 
        return root(x) == root(y);
    }
    
    int size(int x){
      return -par[root(x)];
    }
};
//------------------------------------------

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int n,m;
  cin >> n >> m;
  LL ans[m];
  //VI l(N);
  ans[0]=(LL)n*(n-1)/2;
  UnionFind tree(n);
  int a[m],b[m];
  REP(i,m){
    cin >> a[m-i-1] >> b[m-i-1];
    a[m-i-1]--;
    b[m-i-1]--;
  }
  REP(i,m){
    ans[i+1]=ans[i];
    if(!tree.same(a[i],b[i])){
      ans[i+1]-=(LL)tree.size(a[i])*tree.size(b[i]);
      tree.unite(a[i],b[i]);
    }
  }
  REP(i,m) cout << ans[m-i-1] << endl;
  return 0;
}


Measured memory_bytes: 3328
S = input()
T = input()

ls = [0] * 26
lt = [0] * 26
for s in S:
    ls[ord(s) - 97] += 1
for t in T:
    lt[ord(t) - 97] += 1
ls.sort()
lt.sort()
if ls == lt:
    print('Yes')
else:
    print('No')


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

//thanks to pyf ...
//thanks to qhl ...

int main()
{
	int a,b,c;
	while(cin >> a >> b >> c)
	{
		int sum  = a + b  + c;
		cout << sum - max(a,max(b,c)) << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

vector<int> par, sz;

    void init(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i =0; i < n; i++)
            par[i] = i, sz[i] = 0;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else 
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);

        if (x == y) return ;

        else if (sz[x] < sz[y])
            par[x] = y;
        else {
            par[y] = x;
            if (sz[x] == sz[y])
                sz[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

int main() {
    int n, m;   cin >> n >> m;
    init(n);
    for (int i = 0; i < m; i++) {
        int a, b;   cin >> a >> b;
        unite(a-1, b-1);
    }

    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        mp[find(i)]++;
    }

    int ans = 0;
    for (auto ite = mp.begin(); ite != mp.end(); ite++)
        ans = max(ans, (*ite).second);

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; i++) cin >> X.at(i);
  sort(X.begin(), X.end());
  vector<int> D(M-1);
  for (int i = 0; i < M-1; i++) D.at(i) = X.at(i+1) - X.at(i);
  sort(D.begin(), D.end());
  long long ans = 0;
  for (int i = 0; i < M-N; i++) ans += D.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
bool mark[100005];vi prime;
void seive(ll N){for(int i=2;i<=N;i++){if(mark[i]==false){prime.pb(i);for(int j=i+i;j<N;j+=i)mark[j]=true;}}}
//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int k,x;
   cin>>k>>x;
   int xx=x+1;
   k--;
   vector<int>v;
   v.pb(x);
   for(int i=0;i<k&&xx<=1000000;i++,xx++)
    v.pb(xx);
    xx=x-1;
   for(int i=0;i<k&&xx>=-1000000;i++,xx--)
    v.pb(xx);

    sort(all(v));
    for(int i=0;i<v.sz;i++) {
        cout<<v[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, raw_input().split() )
TimeStamp = 0
Stamp = "&Stamp&"
while N+M:
    not_found = {}
    Root = {}
    Root[Stamp] = TimeStamp
    TimeStamp+=1
    not_found[Stamp] = TimeStamp
    TimeStamp+=1
    Root["."] = Root
    Root[".."] = not_found 
    for i in range(N):
        url = raw_input()
        content = url.split('/');
        content.pop(0)
        cur = Root
        for x in content:
            if x not in cur:
                cur[x] = {}
                cur[x]['..'] = cur
                cur[x]['.'] = cur[x]
                cur[x][Stamp] = TimeStamp
                TimeStamp+=1
            cur = cur[x]
        cur['.is_file.'] = True
        if content[-1]=='index.html':
            cur['..']['/'] = cur
        cur['..'] = not_found
        cur['.'] = not_found
    for i in range(M):
        url1 = raw_input()
        content = url1.split('/')
        content.pop(0)
        res1 = Root
        for x in content:
            if x == '':
                x = '/'
            if x not in res1:
                res1 = not_found
                break;
            res1 = res1[x]
        if '/' in res1:
            res1 = res1['/']
        #
        url2 = raw_input()
        content = url2.split('/')
        content.pop(0)
        res2 = Root
        for x in content:
            if x == '':
                x = '/'
            if x not in res2:
                res2 = not_found
                break;
            res2 = res2[x]
        if '/' in res2:
            res2 = res2['/']

        if res1 == not_found or res2 == not_found:
            print "not found"
        elif '.is_file.' not in res1 or '.is_file.' not in res2:
            print "not found"
        elif res1[Stamp] == res2[Stamp]:
            print "yes"
        else:
            print "no"
    N, M = map(int, raw_input().split() )

Measured memory_bytes: 4356
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


const ll INF = 10000000000;

int main() {
	int V, E; ll r; cin >> V >> E >> r;
	vector<vector<pair<int, ll>>> G(V);
	rep(i, E) {
		int s, t, d; cin >> s >> t >> d;
		G[s].push_back(make_pair(t, d));
	}

	vector<ll> dist(V, INF);
	dist[r] = 0;

	priority_queue<pair<int, ll>, vector<pair<int, ll>>, greater<pair<int, ll>>> que;
	que.push(make_pair(r, 0));

	while (!que.empty()) {
		pair<int, ll> p = que.top(); que.pop();

		int v = p.first;

		rep(i, G[v].size()) {
			int nv = G[v][i].first;
			ll cost = G[v][i].second;

			if (dist[nv] > dist[v] + cost) {
				dist[nv] = dist[v] + cost;
				que.push(make_pair(nv, dist[nv]));
			}
		}
	}

	rep(i, V) {
		ll d = dist[i];
		if (d != INF) cout << d << endl;
		else cout << "INF" << endl;
	}
}


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

int main( ){

    int n ;

    cin >> n ;

    if( n % 1000 == 0 ){

        cout << 0 << endl ;

    }else{

        cout << 1000 - ( n % 1000 ) << endl ;

    }

}


Measured memory_bytes: 3560
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

vi ans;

void makeans(int r, int l, int now){
	int R = 0;
	int L = 0; 
	rep(i,r+l){
		if(i<r){ 
			if((i+r)%2) R++;
			else L++; 
		}else{
			if((i+r+1)%2) L++;
			else R++;
		}
	}
	ans[now+r-1] += R;
	ans[now+r] += L;
	return;
}

void Main()
{
	string s;
	cin >> s;
	int n = s.size();
	ans.resize(n,0);
	int now = 0;
	int flag = 0;
	int r = 0;
	int l = 0;

	rep(i,n){
		if(s[i]=='R' && flag == 0) {
			r++;
		}
		else if(s[i]=='L') {
			l++;
			flag = 1;
		}
		else if(s[i]=='R' && flag == 1){
			//cout << r << " " << l << " " << now << endl;
			makeans(r,l,now);
			now = i;
			flag = 0;
			r = 1;
			l = 0;
		}
	}
	//cout << r << " " << l << " " << now << endl;
	makeans(r,l,now);
	rep(i,n) cout << ans[i] << " ";
	cout << endl;
	return;
}

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

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

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

  int sum;
  for (int i = 0; i < N; i++) {
    int a,b;
    cin >> a >> b;
    sum += b - a + 1;
  }
  cout << sum << endl;

}


Measured memory_bytes: 256
def ans (n):
	a = int(n[:2])
	b = int(n[2:])
	flagA = True
	flagB = True
	if a >12 or a==0 : flagA = False
	if b>12 or b == 0 : flagB = False
	if flagA and flagB : return 'AMBIGUOUS'
	if flagA : return 'MMYY'
	if flagB : return 'YYMM'
	return 'NA'

s = input()
print(ans(s))

Measured memory_bytes: 3060
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	int max1 = a - b;
	int min1 = min(c,max1);
	int ans = c - min1;
	cout<<ans;	

	return 0;
}

Measured memory_bytes: 256
n= int(input())
h = list(map(int,input().split()))
count=0
a=h[0]
for i in range(n-1):
  if a<h[i+1]:
    count+=1
    a=(h[i+1]-1)
  if a==h[i+1]:
    a=h[i+1]
    count+=1
if count==(n-1):
  print("Yes")
else:
  print("No")
      



Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
using namespace std;
const int maxn = 2e5 + 10;
int n, k, a[maxn];

int check(int x) {
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		cnt += (a[i] - 1) / x;
		if (cnt > k) return 0;
	}
	return 1;
}

int main()
{
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	int L = 0, R = 1e9, mid;
	while (L + 1 < R) {
		mid = (L + R) >> 1;
		if (check(mid)) R = mid;
		else L = mid;
	}
	printf("%d\n", R);
	return 0;
}


Measured memory_bytes: 4508
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  int dif = 'A' - 'a';
  string s;
  getline(cin, s);
  for (int i = 0; i < s.size(); i++) {
    if (isalpha(s[i]))
      s[i] += dif;
  }
  cout << s << endl;
}

Measured memory_bytes: 1180
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <chrono> 
using namespace std::chrono;
#define fl(i,z,n) for(int i=z;i<=(n);i++)
#define flr(i,z,n) for(int i=z;i>=(n);i--)
using namespace std;
#define ll long long 
#define pa(a,s) fl(i,0,s-1) cout<<*(a+i)<<" "; cout<<nl;
#define pv(v) fl(i,0,v.size()-1) cout<<v[i]<<" "; cout<<nl;
#define read(v) fl(i,0,v.size()-1) cin>>v[i];
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define vll vector<ll>
#define sll set<ll>
#define spll set<pll>
#define debnl(x) cout<<#x<<"="<<x<<nl;
#define deb(x) cout<<#x<<"="<<x<<" ";
#define mkp(x,y) make_pair(x,y)
#define ump unordered_map
#define ff first
#define ss second
#define in insert
#define sz size
#define len length
#define nl '\n'
#define pb push_back
#define in insert
#define ub upper_bound
#define lb lower_bound
#define ld long double
const int MXN=1e5;
ll mod=1e9+7;
void solve(){
    ld n,x,t;
    cin>>n>>x>>t;
    ll ans=t*(ceil(n/x));
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); ll t=1;
    //cin>>t; //comment for single test
    while(t--) solve();
}

Measured memory_bytes: 3740
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll mod =1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> T maxt(T x,T y) {if (x>y) return x;else return y;}
template<class T> T mint(T x,T y) {if (x>y) return y;else return x;}
//sort(v.begin(), v.end(), [](auto& x, auto& y){return x[1] < y[1];});


//小数出力
double print_double(double d){printf("%.11f", d);}

//約数列挙
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}



// ll combination_mod(int n, int k) {
//   k = mint(k,n-k);
//   ll ans = 1;
//   if (n==0 || k ==0) return ans;
//   rep(i,k) {
//     ans = ans*(n-i)%mod;
//     ans = ans*modinv(i+1)%mod;
//   }
//   return ans;
// }

struct edge {
  int from; //出発点
  int to;   //到達点
  ll cost; //移動コスト
};

//ベルマンフォード法
vector<ll> bellman_ford (vector<edge> edges, int V, int E, int r, ll INF = 100000000000) {  
  vector<ll> cost_to(V,INF);
  cost_to[r] = 0;
  rep(i,V) {
    rep(j,E) {
      edge e = edges[j];
      if (cost_to[e.from]==INF) continue;
      if (cost_to[e.to] > cost_to[e.from] + e.cost) {
        cost_to[e.to] = cost_to[e.from] + e.cost;
        if (i==V-1) {
          printf("NEGATIVE CYCLE\n");
          return {};
        }
      }

    }
  }
  return cost_to;
}

// combination
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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


// 木上の探索
vector<int> cnt;
void dfs(const vector<vector<int>> &G, int v, int p) {
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v);
    }

    // 帰りがけ時に、部分木サイズを求める
    cnt[v] = 1; // 自分自身
    for (auto c : G[v]) {
        if (c == p) continue;
        cnt[v] += cnt[c]; // 子のサイズを加える
    }
}

int main() {
  int N;
  cin >> N;
  char s;
  set<char> S;
  rep(i,N) {
    cin >> s;
    S.insert(s);
  }
  string ans="Four";
  if (S.size()==3) ans="Three";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdtr1c++.h>
#include<list>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    int A,B,X;
    cin >> A >> B >> X;
    if (0 <= X-A && X-A <= B){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
vi v, u;

void solve(){
    cin >> n;
    for(int i = 0, x; i < n; ++i){
        cin >> x;
        v.pb(x);
    }
    u = v;
    sort(all(v));
    int a = v[n / 2 - 1];
    int b = v[n / 2];
    
    for(int i = 0; i < n; ++i){
        if(u[i] <= a) cout << b << "\n";
        else cout << a << "\n";
    }
}

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

    solve();
    
    return 0;
}

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

int l[200][200],s[200][200];

signed main(void) {
    int n,m;
    while(cin >> n >> m, n){
        rep(i,n)rep(j,n){
            if(i != j)l[i][j] = s[i][j] = INF;
            else l[i][j] = s[i][j] = 0;
        }
        rep(i,m){
            int a,b,c;
            string str;
            cin >> a >> b >> c >> str;
            a--,b--;
            if(str == "L"){
                int t = min(l[a][b], c);
                l[a][b] = l[b][a] = t;
            }else{
                int t = min(s[a][b], c);
                s[a][b] = s[b][a] = t;
            }
        }
        rep(k,n)rep(i,n)rep(j,n){
            l[i][j] = min(l[i][j],l[i][k]+l[k][j]);
            s[i][j] = min(s[i][j],s[i][k]+s[k][j]);
        }
        /*
        cout << "land\n";
        rep(i,n){rep(j,n)cout << " " << l[i][j];cout << endl;}
        cout << "sea\n";
        rep(i,n){rep(j,n)cout << " " << s[i][j];cout << endl;}
        */
        int r;
        cin >> r;
        vi in(r);
        rep(i,r)cin >> in[i],in[i]--;
        vector<vi> dp(r,vi(n,INF));
        //dp[i][j]:= i番目まで集配が終わり船がjにあるときの最小コスト
        dp[0][in[0]] = 0;
        rep(i,r-1){
            //in[i]からin[i+1]に移動
            rep(x,n)rep(y,n){//船がxからyに移動
                int cost;
                if(x != y)cost = l[in[i]][x] + s[x][y] + l[y][in[i+1]];
                //in[i]からxに移動して、xからyまで船に乗り、yからin[i+1]に移動
                else cost = l[in[i]][in[i+1]];
                //船が移動しない場合は直接in[i+1]に向かう
                dp[i+1][y] = min(dp[i+1][y], dp[i][x]+cost);
            }
        }
        int ans = LINF;
        rep(i,n)ans = min(ans, dp[r-1][i]);
        cout << ans << endl;
    }

}



Measured memory_bytes: 5080
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

int N, u, v, a, b, P[1 << 20];
vector<int> g[1 << 20];

int dfs(int s, int p) {
  P[s] = p;
  int maxm = 0;
  for(auto x : g[s]) {
    if(x != p) {
      maxm = max(maxm, dfs(x, s));
    }
  }
  return maxm + 1;
}

int main() {
//  freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin >> N >> u >> v;
  for (size_t i = 1; i < N; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(v, -1);
  int x = u, counter = 0, ans = 0;
  while(P[x] != v) {
    x = P[x];
    counter++;
  }

  ans = (counter + 1) >> 1;
  counter /= 2;

  while (counter > 0) {
    counter--;
    u = P[u];
  }

  cout << ans + dfs(u, P[u]) - 1 << endl;

  return 0;
}


Measured memory_bytes: 33792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(ReadLine());
        string s = ReadLine();
        int c = 0, minC = n;

        for(int i = 1;i < n; i++)
        {
            if (s[i] == 'E') c++;
        }
        if (minC > c) minC = c;

        for (int i = 1; i < n; i++)
        {
            if (s[i - 1] == 'W') c++;
            if (s[i] == 'E') c--;
            if (minC > c)
            {
                minC = c;
                if (minC == 0) break;
            }
            
        }
        WriteLine(minC);
    }
}

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

int main()
{
    unsigned int a,b,c;

    cin >> a >> b;
    if((a * b % 2) == 1)
    {
        cout << "Odd" << endl;
    }
    else
    {
        cout << "Even" << endl;
    }
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int a[n + 1];
  rep(i, n) cin >> a[i + 1];

  vector<int> ans(n + 1);
  int cnt = 0;
  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int j = i * 2; j <= n; j += i) {
      sum += ans[j];
    }
    if (sum % 2 == a[i])
      ans[i] = 0;
    else {
      ans[i] = 1;
      ++cnt;
    }
  }

  cout << cnt << endl;
  for (int i = 1; i <= n; ++i)
    if (ans[i]) printf("%d%c", i, (i == n) ? '\n' : ' ');
  return 0;
}


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

ll my_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return my_pow(x * x, n / 2);
    return x * my_pow(x, n - 1);
}

int main() {
    ll a, n ,m;
    cin >> a >> n >> m;
    string s = to_string(m);
    ll t = (s.length() - 1) * 9 + s[0] - '0' - 1;
    if (s[0] == '9') t++;
    int ans = 0;
    
    for (ll i = 1; i <= t; i++) {
        ll x = my_pow(i + a, n);
        if (x > m) break;
        string k = to_string(x);
        ll d = 0;
        for (int j = 0; j < k.length(); j++) {
            d += k[j] - '0';
        }
        if (d == i) ans++;
        
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
  string sss;
  cin >> sss;
  int ans = 0;
  for (int i=0; i < sss.length(); i++){
    if (sss.substr(i,1) == "1"){ans++;}
  }
  cout << ans << "\n";
  return 0;
}


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

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

  if (s == 111) {
    cout << 3 << endl;
    return 0;
  }

  if (s == 000) {
    cout << 0 << endl;
    return 0;
  }

  if (s == 101 || s == 11 || s == 110) {
    cout << 2 << endl;
    return 0;
  }

  if (s == 100 || s == 10 || s == 1) {
    cout << 1 << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
/*
gcd[1]*am[1]
＋gcd[2]*am[2]...このなかに1でカウントしたものが含まれてる
+gcd[3]*am[3]...1と2で重複
むしろ
gcd[n]+am[n]
+gcd[n-1]+am[n-1]

K=1000とか
1000...1
999...1
998...1
...
500...500と1000だけど1000の組み合わせは重複
何通りあるかを配列で用意しといて、
500の倍数チェックで、その個数をひくのがよさそう
100000として
1が100000
2が50000
3が33333、全然まにあいそう
N乗を全部やるのは無理で、繰り返し二乗みたいなやつ
*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll MOD = 1e9+7;
ll modpow(ll a, ll n){
  if(n==1) return a%MOD;
  if(n%2==1) return (a*modpow(a,n-1))%MOD;
  else{
    ll t=modpow(a,n/2)%MOD;
    return (t*t)%MOD;
  }
}

int main(){
  ll N,K,ans=0; cin>>N>>K;
  vector<ll>amt(K+1,0);
  for(int i=K; i>=1; i--){
    //N=1000 500だったら1000/500=2通り、をN回
    amt[i]=modpow(K/i, N);
    ll j=2;
    while(i*j<=K)
      (amt[i]-=amt[i*j++])%=MOD;
    (ans+=i*amt[i])%=MOD;
  }
  if(ans<0)
    ans+=MOD;
  cout<<ans<<endl;
}


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

using namespace std;

int main(){
  int k, a, b;
  cin >> k >> a >> b;
  for(int i=1;k*i<=b;i++){
    if(i*k>=a && i*k<=b){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}



Measured memory_bytes: 3624
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] c = new int[n];
		int[] s = new int[n];
		int[] f = new int[n];
		for (int i = 0; i < n - 1; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		s[n - 1] = Integer.MAX_VALUE;
		int[] a = new int[n];
		a[n - 1] = 0;
		for (int i = 0; i < n; i++) {
			int t = 0;
			for (int j = i; j < n - 1; j++) {
				if (t <= s[j]) {
					t = s[j] + c[j];
				} else {
					if (t % f[j] == 0) t += c[j];
					else t += f[j] - (t % f[j]) + c[j];
				}
			}
			a[i] = t;
		}

		for (int i = 0; i < n; i++) {
			System.out.println(a[i]);
		}
	}
}

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

int main() {
    int n,a[100],b[100],c[100]={};
int sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    int flag=114514;
    for(int i=0;i<n;i++){
        sum+=b[a[i]-1];
        if(flag+1==a[i]-1){
            sum+=c[flag];
        }
        flag=a[i]-1;
    }
    cout<<sum<<'\n';
	return 0;
}


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

const int T[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
    int n, m;
    cin >> n >> m;
    int a[10];
    for(int i = 0; i < m; i++) cin >> a[i];
    sort(a, a + m, greater<int>());
    int dp[10005];
    for(int i = 0; i <= n; i++) dp[i] = -1;
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++){
            int k = a[j];
            if(T[k] <= i) dp[i] = max(dp[i], dp[i - T[k]] + 1);
        }
    }
    int s = n;
    for(int i = dp[n]; i > 0; i--){
        for(int j = 0; j < m; j++){
            int k = a[j];
            if(T[k] <= s && dp[s - T[k]] == i - 1){
                s -= T[k];
                cout << k;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  string s, t;
  cin >> s >> t;
  vector<vector<int>> ch(26);
  s += s;
  rep(i, s.length()) {
    ch[s[i] - 'a'].push_back(i);
  }
  ll ans = 0;
  int cur = 0;
  rep(i, t.length()) {
    int c = t[i] - 'a';
    if(ch[c].size() == 0) {
      puts("-1");
      return 0;
    }

    int pos = *lower_bound(ch[c].begin(), ch[c].end(), cur);
    cur = pos;
    if(cur >= s.length() / 2) {
      cur -= s.length() / 2;
      ans += s.length() / 2;
    }
    ++cur;
  }
  ans += cur;
  cout << ans << endl;

}

Measured memory_bytes: 1784