akhauriyash/Code-Regression huggingface dataset:
###############################################################################

from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * sy) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


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


def main():
    N, T = intin()
    ctlist = intinl(N)

    min_cost = 999999

    for c, t in ctlist:
        if t <= T:
            if c < min_cost:
                min_cost = c

    if min_cost > 9999:
        print('TLE')
    else:
        print(min_cost)


if __name__ == '__main__':
    main()


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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if((x-x%d)/d>k) cout<<x-k*d;
	else {
		dbg(x%d);
		if(((x-x%d)/d)%2==k%2) cout<<x%d;
		else cout<<d-x%d;
	}
	return 0;
}

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

int main()
{
    long long int n, m;
    long long int ans = 0;
    
    cin >> n >> m;
    
    if((2 * n) > m) {
        ans = m / 2;
    } else if((2 * (n + 1)) > m) {
        ans = n;
    } else {
        ans = n + ((m - (2 * n)) / 4);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

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


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

  REP(i,n){
    cout<<s[i]<<t[i];
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;

inline ll read(){
	ll Hashimoto=0,Kanna=1;
	char I_Love=getchar();
	while(I_Love<'0'||I_Love>'9'){
		if(I_Love=='-')Kanna=-1;
		I_Love=getchar();
	}
	while(I_Love>='0'&&I_Love<='9'){
		Hashimoto=Hashimoto*10+I_Love-'0';
		I_Love=getchar();
	}
	return Hashimoto*Kanna;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int a,b;

int I_Love_Hashimoto_Kanna() {
  fastio;
  cin>>a>>b;
  
  int x=0;
  if(a+b==15)x+=1;
  if(a*b==15)x+=2;
  if(x==1)Tone("+")
  else if(x==2)Tone("*")
  else if(x==0)Tone("x");
  
  
  
  return 0;
}


Measured memory_bytes: 256
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
const int N = 5e5+10;
const double eps = 0.00000001;
const ll mod = 1e18 + 7 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int s[100];
int main(){
    memset(s,-1,sizeof s);
    int n = read(),m = read();
    int a,b;
    rep(i,1,m){
        cin >> a>>b;
        if(s[a]== -1) s[a] = b;
        else if(s[a] != b) return puts("-1"),0;
    }
   if(s[1] == 0&&n!=1) return puts("-1"),0;
    if(s[1] == -1&&n!=1) s[1] = 1;
    rep(i,1,n){
        cout << (s[i] == -1?0:s[i]);
    }
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: n, k, m, res, l
  integer, allocatable :: v(:), x(:)
  read (*, *) n, k
  allocate (v(n))
  read (*, *) v(:)
  res = 0
  do m = 0, min(n, k)  ! 取り出す数
    do l = 0, m  ! 左端から取り出す数
      x = [ v(1:l), v(n - m + l + 1:n) ]
      call quicksort(x)
      res = max(res, point(x, k - m))
    end do
  end do
  print "(i0)", res

  contains

  function point(x, r)  ! Can return up to r
    integer, intent(in) :: x(:)
    integer :: point, i, d, r
    point = 0
    d = 0
    do i = 1, size(x)
      if (x(i) < 0 .and. d < r) then
        d = d + 1
      else
        point = point + x(i)
      end if
    end do
  end function point

  recursive subroutine quicksort(a)
    integer, intent(inout) :: a(:)
    integer :: pivot, i, j, k, tmp, n
    real(4) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort
end program main


Measured memory_bytes: 768
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  string s, t;
  cin >> s >> t;
  int max = 0;
  for(int i = 0; i < s.size()-t.size()+1; i++){
    int ans = 0;
    for(int j = 0; j< t.size(); j++) {
      if(s.at(i+j) == t.at(j))ans++;
    }
    if(max <= ans){
      max = ans; 
    }
  }
  cout << t.size()-max << endl;
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    var num = 0
    for(i in 0..a) {
        for(j in 0..b) {
            for(k in 0..c) {
                if(x == i * 500 + j * 100 + k * 50) {
                    num += 1
                }
            }
        }
    }
    println(num)
}

Measured memory_bytes: 31772
#include<bits/stdc++.h>
using namespace std;
void iosbase(void);
typedef  long long int     ll;
typedef  vector<int>       vi;
typedef  pair<int, int>     pii;
#define  int               ll
#define  pb                push_back
#define  mp                make_pair
#define  si(x)             (int)x.size()
#define  F                 first
#define  S                 second
#define  all(x)            x.begin(),x.end()
#define  minv(m,n)         *min_element(m,n)
#define  maxv(m,n)         *max_element(m,n)
#define  mem(a,x)          memset(a,x,sizeof(a))
#define  deb(x)            cout<<"> "<<#x<<" : "<<x<<endl
#define  rep(i,n)          for(int i=0;i<n;i++)
#define  prs(x,y)          fixed<<setprecision(y)<<x
#define  w(x)              int x;cin>>x; while(x--)
#define  show(a)           for(auto x:a){cout<<x<<" ";}cout<<endl;
#define   N  (int)1e5+5

int32_t main()
{
  iosbase();
  int l , r , d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = 1 ; i <= 100 ; i++)
  {
    if (d * i >= l and d * i <= r)
      ans++;
  }
  cout << ans << endl;


}


void iosbase(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
}

Measured memory_bytes: 3608
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    for h in range(H) :
        for w in range(W) :
            if (h + w) % 2 == 0 :
                print("#", end="")
            else :
                print(".", end="")
        print()
    print()


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vi mmn('z'-'a'+1, 0), mm('z'-'a'+1, 0);

    string st1;
    cin >> st1;
    
    string st2;
    cin >> st2;
    
    rep(i, st1.size()) {
        mmn[st1[i] - 'a']++;
    }

    rep(i, st2.size()) {
        mm[st2[i] - 'a']++;
    }

    int ans = 0;
    sort(all(mmn));
    sort(all(mm));

    rep(i, mm.size()) {
        ans += abs(mmn[i] - mm[i]);
    }

    cout << ans / 2 << endl;


    return 0;
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k, q;
  cin >> k >> q;
  ll d[5000];
  rep(i, k) cin >> d[i];
  rep(qi, q)
  {
    ll n, x, m;
    cin >> n >> x >> m;
    ll dm[5000];
    rep(i, k) dm[i] = d[i] % m;
    ll d_sum = 0;
    rep(i, k) d_sum += dm[i];
    ll cnt = 0;
    //a[i] = a[i+1]
    ll zero = 0;
    rep(i, k) zero += dm[i] == 0;
    cnt += ((n - 1) / k) * zero;
    rep(i, (n - 1) % k) cnt += dm[i] == 0;
    //a[i] > a[i+1]
    ll a = x + ((n - 1) / k) * d_sum;
    rep(i, (n - 1) % k) a += dm[i];
    cnt += (a / m) - (x / m);
    cout << n - 1 - cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 384
def sieve_of_eratosthenes(N):
    N += 1
    sieve = list(range(N))
    for p in range(2, int(N ** 0.5) + 1):
        if sieve[p] == p:
            for i in range(p << 1, N, p):
                sieve[i] = p
    return sieve

def lcm_with_sieve(numbers, N):
    sieve = sieve_of_eratosthenes(N)
    lcm = dict()
    for n in numbers:
        d = dict()
        while n > 1:
            factor = sieve[n]
            n //= factor
            d[factor] = d.get(factor, 0) + 1
        for factor, power in d.items():
            lcm[factor] = max(lcm.get(factor, 0), power)
    return lcm

MOD = 10 ** 9 + 7
input()
A = tuple(map(int, input().split()))
lcm = 1
for factor, power in lcm_with_sieve(A, 10 ** 6).items():
    lcm = lcm * pow(factor, power, MOD) % MOD
total = 0
for a in A:
    total = (total + lcm * pow(a, MOD - 2, MOD)) % MOD
print(total)

Measured memory_bytes: 51184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,i0,n) for(int i=i0;i<n;++i)
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define INF12 1000000000000 //10^12
#define INF9 1000000000 //10^9
#define MOD 10000007 //10^9+7

int N,A,B,ans=0;

int sumDigit(int n) {
    int res = 0;
    while(n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res; 
}

int main() {
    cin >> N >> A >> B;
    rep(i,1,N+1) {
        int t = sumDigit(i);
        if(A <= t && t <= B) ans += i;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,t[1000],m,p,x,i,j,sum,temp;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&t[i]);
    }
    scanf("%d",&m);
    for(i=1;i<=m;i++)
    {
        sum=0;
        scanf("%d%d",&p,&x);
        temp=t[p];
        t[p]=x;
        for(j=1;j<=n;j++)
        {
            sum=sum+t[j];
        }
        printf("%d\n",sum);
        t[p]=temp;
    }
    return 0;
}


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

using namespace std;

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

Graph G;
vector<int> res;

void dfs(int u, int p, int c) {
  res[u] = c;
  for (auto g : G[u]) {
    if (g.first == p) continue;
    if (g.second & 1)
      dfs(g.first, u, 1 - c);
    else
      dfs(g.first, u, c);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  G.assign(N, vector<Edge>());
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    G[u].push_back(Edge(v, w));
    G[v].push_back(Edge(u, w));
  }
  res.assign(N, 0);
  dfs(0, -1, 1);
  for (auto r : res)
    cout << r << '\n';
  return 0;
}


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

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

    vector<pair<int,int> > p(n);

    ll a=0,b=1;

    for(int i=0; i<n; i++){ 
        int q,x; cin>>q>>x;
        p[i] = make_pair(q,x);
        if(p[i].first == 1) b *= p[i].second;       
    }

    ll bef=1,aft=1;

    for(int i=0; i<n;  i++){
        if(p[i].first == 1) aft *= p[i].second;
        else if(p[i].first == 2) aft += p[i].second;
        else if(p[i].first == 3) aft -= p[i].second;
    }

    a = b * bef - aft;

    cout<<a<<" "<<b<<endl;

    return 0;

}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int a, b, c, A, B, C, ta, tb, tc;
int n;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a >> b >> c;
        ta = max(B,C) + a;
        tb = max(A,C) + b;
        tc = max(A,B) + c;
        A = ta; B = tb; C = tc;
    }
    cout << max({A,B,C}) << '\n';
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int n;
string s="";
main()
{
	cin>>n;
	if(n==0)
	{
		cout<<"0"<<endl;
		return 0;
	}
	while(n)
	{
		s=(n&1?"1":"0")+s;
		n=n>0?-n/2:-(n-1)/2;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin>>n;
    int edge[n][2];
    rep(i,n-1)cin>>edge[i][0]>>edge[i][1];
    set<int> neighbors[n+1];
    rep(i,n-1){
        neighbors[edge[i][0]].insert(edge[i][1]);
        neighbors[edge[i][1]].insert(edge[i][0]);
    }
    queue<int> que;
    int d_a[n+1],d_b[n+1];
    int checked[n+1]={};
    checked[1]=true;
    d_a[1]=0;d_b[n]=0;
    que.push(1);
    while(!que.empty()){
        int tmp=que.front();
        que.pop();
        for(auto x:neighbors[tmp]){
            if(!checked[x]){
                checked[x]=true;
                que.push(x);
                d_a[x]=d_a[tmp]+1;
            }
        }
    }
    que.push(n);
    rep(i,n+1)checked[i]=false;
    checked[n]=true;
    while(!que.empty()){
        int tmp=que.front();
        que.pop();
        for(auto x:neighbors[tmp]){
            if(!checked[x]){
                DEBUG{cout << x << endl;}
                checked[x]=true;
                que.push(x);
                d_b[x]=d_b[tmp]+1;
            }
        }
    }
    int cnt=0;
    rep(i,n){
       if(d_a[i+1]<=d_b[i+1])cnt++; 
    }
    DEBUG{cout << cnt << endl;}
    if(cnt*2>n)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}


Measured memory_bytes: 16256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n, k, q;
    cin>>n>>k>>q;
    vi a(n, 0);
    rep(i,q){
        lli ai;

        cin>>ai;
        ai--;
        a[ai]++;
    }
    rep(i,n){
        Yes(k-q+a[i]>0);
    }
}

Measured memory_bytes: 4064
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
  a, b = list(map(int, input().split()))
  A[i] = a
  B[i] = b
  
#モンスターの体力を i 減らすため消耗する魔力の最小値  
DP = [float("inf")] * (H + max(A) + 1)
DP[0] = 0  
for i in range(len(DP)):
  for j in range(N):
    if i - A[j] >= 0:
      DP[i] = min(DP[i], DP[i - A[j]] + B[j])
#print(DP) 
print(min(DP[H:H + max(A) + 1]))
  

Measured memory_bytes: 74316
#include<bits/stdc++.h>
#define ii pair<int,int>
using namespace std;
map<int,int> mm;
int main(){
	int k,n,a;
	cin>>n>>k;
	for(int i = 0;i<n;i++){
		cin>>a;
		mm[a]++;
	}
	vector<ii> v;
	for(auto e : mm){
		v.push_back({e.second,e.first});
	}
	sort(v.begin(), v.end());
	int lv = v.size();int j = lv-1;
	int ans = 0;
	int i = lv-1;
	while(k--){
		if(i<0) break;
//		cout<<v[i].first<<" "<<v[i].second<<"\n";
		if(i>=0) ans+=v[i--].first;
		else break;
	}
//	cout<<lv<<' '<<ans<<"\n";
	ans = n-ans;
	cout<<ans<<"\n";
	return 0;
}

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

int main() {
	string S; long long K;
	cin >> S >> K;                                                      //////////           BASICALLY THE FIRST NON-ONE 
 // CHARACTER IF EXIST IN LESS THAN K MOVES OR 1 IF THERE ARE INITIALLY K-ONES
	for (int i = 0; i < min((long long)S.size(), K); i++) {
		if (S[i] >= '2') { cout << S[i] << endl; return 0; }
	}
	cout << '1' << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
const int mod = 1000000007;


int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = 0;
    ll tmp;
    if(A == 0 && B == 0){
        cout << "0" << endl;
        return 0;
    }
    tmp = (N / (A + B));
    ans += tmp * A;
    N -= (tmp * (A + B));
    if(N > A){
        ans += A;
    }else{
        ans += N;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=(res*x);
        }
        x=(x*x);
        y=y/2;
    }
    return res;
}
 
 
int main(){
 
/* #ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif*/
   
ll n,i,w,j,x,y,k;
sfl(n);sfl(w);



vec<ll>dp(100005,inf),dp1(100005,inf);
dp1[0]=0;
dp[0]=0;
f(i,0,n){
  sfl(x);sfl(y);

  f(j,1,100005){
    if(y<=j&&dp[j-y]!=inf)
  dp1[j]=min(dp[j],dp[j-y]+x);

}
dp=dp1;



}



for(i=100004;i>=0;i--){
if(dp[i]<=w){
cout<<i;
break;
}

}

 
   return 0;
 }

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
double n;
while(scanf("%lf",&n)!=EOF){
n=n/9.8;
n=n*n*4.9;
int i;
for(i=1;i*5-5<n;i++);
cout<<i<<endl;
}
return 0;
}

Measured memory_bytes: 1232
// Sum of Three Integers
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int K, S;
    int count = 0;
    cin >> K >> S;
    for (int X = 0; X <= K; ++X) {
        for (int Y = 0; Y <= K; ++Y) {
            int Z = S - X - Y;
            // cout << X << ' ' << Y << ' ' << Z << endl;
            if (0<= Z && Z <= K && (S == X + Y + Z)) {
                ++count;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
// Twitter@KonoLv1 2020年春からエンジニア見習いデビュー！
 
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
 
int main(void){
    int i,j;            //  ループ文に使用
    int x,y,z; 
    int count1,count2,count;   //  カウント用に使用
    int flg,mode;
    i = j = x = y = z = count1 = count2 = count = flg = mode = 0;
    int n;
    int h,w;
    double dx,dy;
    int box[1024] = {};
    int box2[1024] = {};
    char s[200001] = {};        //  文字列
    char s2[200001] = {};        //  文字列
 
 
    //  入力処理
    
    // scanf("%s",s); // 文字列
     scanf("%d %d %d",&h,&w,&n); // 整数
     if (h > w){
         for (i = 1; i <= w; i++){
             if (i * h >= n){
                 printf("%d",i);
                 break;
             }
         }
     }else{
        for (i = 1; i <= h; i++){
            if (i * w >= n){
                printf("%d",i);
                break;
            }
        }
     }
    // scanf("%lf",dx); // 小数
    
    /*
    for (i = 0; i < n; i++){
        scanf("%d",);  
    }
    */
    //  計算処理
   
   
   
   
    //  出力処理

    //printf("%.0f",dy / dx);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

/*
左からできる限りaにしていく
aにできないなら一個右をaにする
一番右で回数を調整
*/

int main() {
    string s; cin >> s;
    ll k; cin >> k;

    rep(i, 0, sz(s)){
        if(s[i] == 'a') continue;
        if('z'-s[i] + 1 <= k){ 
            k -= ('z'-s[i]) + 1;
            s[i] = 'a';
        }
    }
    k %= 26;
    s[sz(s)-1] += k;
    if(s[sz(s)-1] > 'z') s[sz(s)-1] -= 26;
    co(s);


    return 0;
}




Measured memory_bytes: 3736
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(long long  i = 0; i < n; i++)
#define rep2(i,a,n) for(long long  i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

int main() 
{
    int a,b; cin >> a >> b;    
    map<int, int> t;
    int h = 1;
    t[1] = h;
    
    for(int i = 2; i < 1000; i++) {
        h += i; 
        t[i] = h;
    }
    cout << t[abs(a-b)] - b<< endl;

    return 0;
}



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

using namespace std;

int main() {
    string s, t;

    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>() );

    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, t, a int
	fmt.Scan(&n, &t, &a)

	ans := 0
	temp := 600.0
	for i := 0; i < n; i++ {
		var h int
		fmt.Scan(&h)
		ht := math.Abs((float64(t) - float64(h)*0.006) - float64(a))
		if ht < temp {
			ans = i + 1
			temp = ht
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main()
{
    char S1[10],s2[10],s3[10];
    int i;
    scanf("%s %s %s",&S1,&s2,&s3);

    for(i=0;i<10;i++){
    if('a'<=S1[i] && S1[i]<='z' && 'a'<=s2[i] && s2[i]<='z' && 'a'<=s3[i] && s3[i]<='z'){
       continue;

    }
    }
    S1[0]=S1[0]-32;
    s2[0]=s2[0]-32;
    s3[0]=s3[0]-32;
    printf("%c%c%c",S1[0],s2[0],s3[0]);
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int i;
  int N;
  string ans;
  string S, T;
  cin >> N;
  cin >> S >> T;
  
  ans = "";
  for(i = 0; i < N; i++) {
    ans += S[i];
    ans += T[i];
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


int main() {
  lint n; cin >> n;
  vector<lint> a(n); for(lint i=0;i<n;i++) { cin >> a[i]; }

  vector<lint> b(n);

  lint i=0;
  for(i=0;i<(n+1)/2;i++) { b[i] = a[n-2*i-1]; }
  for(i=0;i<(n+1)/2;i++) { b[i+(n+1)/2] = a[2*i+n%2]; }


  for(lint i=0;i<n;i++) { cout << b[i] << " "; }
  cout << endl;
  return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  
  int n,k,s,ans[100005],i;
  const int lim=1e9;
  
  cin >> n >> k >> s;
  
  for (i=0;i<k;i++) ans[i]=s;
  for (i=k;i<n;i++) ans[i]=(s+1)%lim;
  
  for (i=0;i<n;i++) cout << ans[i] << ' ';
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};


// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main()
{

    cin >> N >> W;
    for (int i=0; i<N; ++i)
    {
        cin >> weight[i] >> value[i];
    }

    for (int i=0; i<N; ++i)
    {
        for (int sum_w=0; sum_w<=W; ++sum_w)
        {
            // i 番目の品物を選ぶ場合
            if(sum_w - weight[i] >= 0)
            {
                if(dp[i+1][sum_w] < dp[i][sum_w - weight[i]] + value[i])
                {
                    dp[i+1][sum_w] = dp[i][sum_w - weight[i]] + value[i];
                }
            }

            // i 番目の品物を選ばない場合
            if(dp[i+1][sum_w] < dp[i][sum_w])
            {
                dp[i+1][sum_w] = dp[i][sum_w];
            }
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}

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

string S;

int main() {
    cin >> S;

    int ans = 0;
    char now = S[0];
    for (int i = 1; i < S.length(); i++) {
        if (now != S[i]) {
            now = S[i];
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
ans = 'NO'
a, b, c = map(int, input().split())
memo = []
for i in range(1, 10**9):
  tmp = (a * i)%b
  if tmp == c:
    ans = 'YES'
    break
  if tmp in memo:
    break
  else:
    memo.append(tmp)
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#define rep(i, n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int a;
    cin >> a;
    if (i % 2 == 1 && a % 2 == 1) ans++;
  }
  
  cout << ans;
}

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

long long int N, a;
unordered_map<long long, long long> m;

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &a);
        ++m[a];
    }
    a = 0;
    for(auto i : m){
        a += i.second >= i.first ? i.second - i.first : i.second;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 4260
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
vector<int>arr(0);
int main(void)
{
	int a; cin >> a;
	if (a > 999)
	{
		cout << "ABD" << "\n";
	}
	else {
		cout << "ABC" << "\n";
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
ll solve(){
    int n,ans=0;
    cin>>n;
    if(n == 1) return 0;
    vector<vector<ll> > C(n,vector<ll>(n));
    C[0][0]=C[1][0]=C[1][1]=1;
    for(int i=2;i<n;i++){
        C[i][0]=1;
        for(int j=1;j<=i;j++){
            C[i][j] = (C[i-1][j]+C[i-1][j-1])%mod;
        }
    }
    for(int l=1;n>=3*l;l++){
        ans=(ans+C[n-2*l-1][l-1]+mod)%mod;
    }
    return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 34428
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict


class Solution:
    def main(self):
        X, A = map(int, input().split())
        if X < A:
            print(0)
        else:
            print(10)

if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 3316
# 最後の体力が0になるのが早い方が負け
A, B, C, D = map(int, input().split())

while A > 0 and C > 0:
    C -= B
    if C <= 0:
        print('Yes')
        break
    A -= D
    if A <= 0:
        print('No')
        break


Measured memory_bytes: 9104
/*
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 5e5 + 5, M = 998244353, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
struct DSU {
    int p[N];
    void init(int n) { iota(p + 1, p + n + 1, 1); }
    int find(int x) { return p[x] == x ? x : (p[x] = find(p[x])); }
    void unite(int u, int v) { p[find(u)] = find(v); }
} a, b;
void Main() {
    int n, K, L;
    input(n, K, L);
    a.init(n);
    b.init(n);
    for (int i = 0; i < K; ++i) {
        int u, v;
        input(u, v);
        a.unite(u, v);
    }
    for (int i = 0; i < L; ++i) {
        int u, v;
        input(u, v);
        b.unite(u, v);
    }
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= n; ++i) ++mp[{a.find(i), b.find(i)}];
    for (int i = 1; i <= n; ++i) cout << mp[{a.p[i], b.p[i]}] << " \n"[i == n];
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RANGE(i,a,b) for(int i=(a);i<=(b);i++)
#define RANGER(i,a,b) for(int i=(b);i>=(a);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)
using ll=long long int;
using vi=vector<int>;
using vii=vector<vi>;
using pi=pair<int,int>;
constexpr int INF=1<<30;
constexpr ll INTL=1ll<<60;

int main(){
  string S;
  cin>>S;
  int f,s;
  f=stoi(S.substr(0,2));
  s=stoi(S.substr(2,2));
  if(0<f&&f<=12&&0<s&&s<=12){
    cout<<"AMBIGUOUS"<<endl;
  }else if(0<f&&f<=12){
    cout<<"MMYY"<<endl;
  }else if(0<s&&s<=12){
    cout<<"YYMM"<<endl;
  }else{
    cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    string a;
    cin >> a;
    if (a == "A")
    {
        cout << "T";
    }
    else if (a == "T")
    {
        cout << "A";
    }
    else if (a == "C")
    {
        cout << "G";
    }else{
        cout << "C";
    }
}


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

#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(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        vi v(4);
        rep(i,4)cin>>v[i];
        sort(all(v));
        bool flag=false;
        if(v[0]==1)if(v[1]==4)if(v[2]==7)if(v[3]==9)flag=true;
        cout<<(flag?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
h, w, a, b = map(int, raw_input().split())

MOD = 10**9+7

M = 2*10**5
fact = [1]*(M+1)
rev = [1]*(M+1)
for i in xrange(1, M+1):
    fact[i] = (fact[i-1]*i) % MOD
    rev[i] = pow(fact[i], MOD-2, MOD)

def comb(a, b):
    a -= 1; b -= 1
    return (fact[a+b] * rev[a] * rev[b]) % MOD

ans = 0
for y in xrange(1, h-a+1):
    ans += comb(y, b) * comb(h-y+1, w-b)
    ans %= MOD
print ans


Measured memory_bytes: 15492
// MinMaxAndSum.c
// n個の整数 ai(i=1,2,...n)を入力し、それらの最小値、最大値、合計値を
// 求めるプログラムを作成してください。
// 【入力】
// １行目に整数の数 nが与えられます。２行目に n個の整数 aiが空白区切りで与えられます。
// 【出力】
// 最小値、最大値、合計値を空白区切りで１行に出力してください。
// 【制約】
// ・0<n≤10000
// ・−1000000≤ai≤1000000
// 【例】
// 入力：
// 5
// 10 1 5 4 17
// 出力：
// 1 17 37
#include<stdio.h>

int main( void) {
  int n, a;
  long long max = -1000000, min = 1000000, sum = 0;

  scanf( "%d", &n);

  for ( int i = 0; i < n; i++) {
    scanf( "%d", &a);

    if ( a >= max) max = a;
    if ( a <= min) min = a;

    sum += a;
  }

  printf( "%lld %lld %lld\n", min, max, sum);

  return 0;
}



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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

struct ruqst{
    vll t, d, tag;

    ruqst(int len, int init) {
        t.resize((len + 5) * 4, init);
        d.resize((len + 5) * 4, 0);
        tag.resize((len + 5) * 4, 0);
    }

    ll qry(int p, int l, int r, int tl, int tr) {
        if (tl <= l && r <= tr) return t[p];
        int mid = (l + r) / 2;
        if (tag[p]) {
            t[p * 2] = d[p] * (mid - l + 1), d[p * 2] = d[p], tag[p * 2] = 1;
            t[p * 2 + 1] = d[p] * (r - mid), d[p * 2 + 1] = d[p], tag[p * 2 + 1] = 1;
            d[p] = 0, tag[p] = 0;
        }
        ll rt = 0;
        if (tl <= mid) rt += qry(p * 2, l, mid, tl, tr);
        if (mid < r && tr > mid) rt += qry(p * 2 + 1, mid + 1, r, tl, tr);
        return rt;
    }

    void set(int p, int l, int r, int tl, int tr, ll x) {
        if (tl <= l && r <= tr) {
            t[p] = x * (r - l + 1), d[p] = x, tag[p] = 1;
            return;
        }
        int mid = (l + r) / 2;
        if (tag[p]) {
            t[p * 2] = d[p] * (mid - l + 1), d[p * 2] = d[p], tag[p * 2] = 1;
            t[p * 2 + 1] = d[p] * (r - mid), d[p * 2 + 1] = d[p], tag[p * 2 + 1] = 1;
            d[p] = 0, tag[p] = 0;
        }
        if (tl <= mid) set(p * 2, l, mid, tl, tr, x);
        if (mid < r && tr > mid) set(p * 2 + 1, mid + 1, r, tl, tr, x);
        t[p] = t[p * 2] + t[p * 2 + 1];
        return;
    }
};

int main() {
    // freopen("n", "r", stdin);
    // freopen("a.out", "w", stdout);
    int n, q; cin >> n >> q;
    ruqst st(n, 0);
    FOR(_, 1, q) {
        int c; cin >> c;
        if (c == 0) {
            int s, t, x; cin >> s >> t >> x;
            st.set(1, 0, n - 1, s, t, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << st.qry(1, 0, n - 1, s, t) << endl;
        }
    }
}


Measured memory_bytes: 12324
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=2*1e5+10;
char s[MAXN];
int ans,n,h=1;
int main(){
    scanf("%d%s",&n,s+1);
    while(h<n){
        while(s[h]=='R') h++;
        while(s[n]=='W') n--;
        if(h>=n) break;
        ans++; h++; n--;
    }
    printf("%d",ans);
}


Measured memory_bytes: 4016
#include <stdio.h>

int main(int argc,char* argv[]){
  int c1,c2,c3;
  int nums[11];
  int i;

  while(scanf("%d %d %d",&c1,&c2,&c3) != EOF){
    int my = c1 + c2;
    int sc = 0; int fa = 0;
    
    for(i = 0; i < 11;i++){
      nums[i] = 1;
    }
    nums[c1] = nums[c2] = nums[c3] = 0;
    
    for(i = 1; i < 11;i++){
      if(nums[i]){
	if(my + i > 20){
	  fa++;
	}else{
	  sc++;
	}
      }
    }

    if((double)(sc)/(sc + fa) >= 0.5){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  
  }
  
  return 0;
  
}

Measured memory_bytes: 0