akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n;
vector<vector<lli> > g;
lli ans = 0;
lli dfs(lli x){
    lli ret = 0;
    vector<lli> d;
    for(lli i = 0;i < g[x].size();i++){
        d.push_back(dfs(g[x][i]));
    }
    sort(d.rbegin(),d.rend());
    for(lli i = 0;i < d.size();i++){
        ret = max(ret,d[i]+i+1);
    }
    return ret;
}
int main(){
    cin >> n;
    g = vector<vector<lli> > (n+1);
    for(lli i = 2;i <= n;i++){
        lli a;
        cin >> a;
        g[a].push_back(i);
    }
    cout << dfs(1) << endl;
    return 0;
}

Measured memory_bytes: 15104
N = raw_input()
N = int(N)
K = raw_input()
K = int(K)
x = raw_input()
x = x.split(' ')
x = [int(d) for d in x]

sum_ = 0
for i in range(N):
	sum_ += 2*min(abs(x[i]-K),x[i])

print(sum_)

Measured memory_bytes: 2568
#include <stdio.h>
#include <string.h>
int main(void)
{
  int n,m;
  int i,j;
  struct{
    int x,y;
  } man[50]={0}, chk[50]={0};
  int dist[50][50], min[50];
  int minpt[50];
  
  scanf("%d %d",&n,&m);
fprintf(stderr, "n=%d, m=%d\n", n, m);
  for(i=0;i<n;++i){
    int a,b;
    scanf("%d %d",&a,&b);
fprintf(stderr, "man[%d].x=%d, man[%d].y=%d\n", i, a, i, b);
    man[i].x=a;
    man[i].y=b;
    min[i]=2000000000;
  }
  for(j=0;j<m;++j){
    int a,b;
    scanf("%d %d",&a,&b);
fprintf(stderr, "chk[%d].x=%d, chk[%d].y=%d\n", j, a, j, b);
    chk[j].x=a;
    chk[j].y=b;
  }
  for(i=0;i<n;++i){
    for(j=0;j<m;++j){
      int x1=man[i].x, x2=chk[j].x;
      int y1=man[i].y, y2=chk[j].y;
      int d = ((x1<x2)?(x2-x1):(x1-x2))
            + ((y1<y2)?(y2-y1):(y1-y2));
      dist[i][j]=d;
      if(d<min[i]){
fprintf(stderr, "j=%d, d=%d, min[%d]=%d\n", j, d, i, min[i]);
        min[i]=d;
        minpt[i]=j+1;
      }
    }
  }
  for(i=0;i<n;++i){
    printf("%d\n",minpt[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

int main() {
	int number;
	int temp;
	std::vector<int> card;
	int answer = 0;

	std::cin >> number;
	for (int i = 0; i < number; i++) {
		std::cin >> temp;
		card.emplace_back(temp);
	}

	std::sort(card.rbegin(), card.rend());

	for (std::vector<int>::size_type i = 0; i < card.size(); i++)
		if (i % 2 == 0)
			answer += card[i];
		else
			answer -= card[i];

	std::cout << answer << std::endl;

	return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

int n;
map < string , int > cnt;

bool cmp(pair < string , int > a , pair < string , int > b){
    if(a.second > b.second)
        return 1;
    if(a.second == b.second){
        if(a.first < b.first)
            return 1;
    }
    return 0;
}

int main(){
    cin >> n;
    int mx = 0;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        cnt[s]++;
        mx = max(mx , cnt[s]);
    }
    vector < pair < string , int > > ans;
    for(auto v : cnt){
        ans.push_back({v.first , v.second});
    }
    sort(ans.begin() , ans.end() , cmp);
    for(auto v : ans){
        if(v.second == mx)
            cout << v.first << endl;
    }
}


Measured memory_bytes: 29676
N = int(input())

ans = 0
if int(N/10) >= 1:
  ans += 9
  if int(N/1000) >= 1:
    ans += 900
    if int(N/100000) >= 1:
      ans += 90000
    else:
      ans += max(N - 9999, 0)
  else:
    ans += max(N - 99, 0)
else:
  ans += N

print(ans)

Measured memory_bytes: 3060
s = input().split()

stack = [0] * 200
top = 0

def pop():
    global top
    top -= 1
    return stack[top+1]

def push(x):
    global top
    top += 1
    stack[top] = x

for i in s:
    if i == '+':
        a = int(pop())
        b = int(pop())
        push(a+b)
    elif i == '-':
        a = int(pop())
        b = int(pop())
        push(b-a)
    elif i == '*':
        a = int(pop())
        b = int(pop())
        push(a*b)
    else:
        push(int(i))

print(pop())


Measured memory_bytes: 5600
import java.util.*;
import java.lang.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int maxD = 1;


        while (maxD <= N) {
            maxD *= 2;
        }

        System.out.println(maxD/2);
    }
}

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

const int MAXN = 100010;
int qa[MAXN], ansl[MAXN];
std::map<int, std::vector<int> > qry;
int X, Q;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> X >> Q;
	for (int i = 1, t; i <= Q; ++i)
		std::cin >> t, qry[t].push_back(-1);
	std::cin >> Q;
	for (int i = 1, t; i <= Q; ++i)
		std::cin >> t >> qa[i], qry[t].push_back(i);
	int lx = 0, ly = 0, rx = X, ry = X, lst = 0, typ = 0;
	for (auto t : qry) {
		int d = t.first - lst; lst = t.first;
		ly -= d, ry -= d;
		if (ly < 0) lx -= ly, ly = 0;
		if (ry < 0) rx += ry, ry = 0;
		if (lx >= rx) lx = rx = 0;
		for (auto i : t.second) {
			if (i == -1) ly = X - ly, ry = X - ry, typ ^= 1;
			else {
				if (qa[i] <= lx) ansl[i] = ly;
				else if (qa[i] >= rx) ansl[i] = ry;
				else ansl[i] = ly + (ry - ly) / (rx - lx) * (qa[i] - lx);
				if (typ) ansl[i] = X - ansl[i];
			}
		}
	}
	for (int i = 1; i <= Q; ++i) std::cout << ansl[i] << '\n';
	return 0;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    string s;
    cin >> s;
    if (s == "ARC") {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
}

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


Measured memory_bytes: 3620
from collections import deque
H, W = map(int, input().split())
S = [[c for c in input()] for _ in range(H)]
a = sum([S[y][x] == "." for x in range(W) for y in range(H)])
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
B = [[-1]*W for _ in range(H)]
q = deque([(0, 0, 1)])  # y,x,step
while len(q) > 0:
    y, x, step = q.popleft()
    if y < 0 or H <= y or x < 0 or W <= x:
        continue
    if S[y][x] == '#' or B[y][x] >= 0:
        continue

    B[y][x] = step

    for i in range(4):
        q.append((y+dy[i], x+dx[i], step+1))
# print(*B, sep='\n')
print(a - B[H-1][W-1] if B[H-1][W-1] >= 0 else -1)


Measured memory_bytes: 41584
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()


int main(){
  ll N,K;
  cin >> N >> K;
  set<P> A;
  rep(i,N){
    ll a;
    cin >> a;
    if(i==0){
      A.insert(P(300000-1,a));
    }else{
      auto b=A.begin();
      rep(j,(ll)A.size()){
        P c=*b;
        if(c.second<=a+K&&c.second>=a-K){
          A.insert(P(c.first-1,a));
          break;
        }
        if(j==(ll)A.size()-1){
          A.insert(P(300000-1,a));
          break;
        }
        b++;
      }
    }
  }
  auto b=*A.begin();
  cout << 300000-b.first << endl;
}
    
  

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

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

const int N = 2e5 + 5;

int n;
ll dp[N], k, ans;
vector <ll> seg[N << 2];

void build(int id = 1, int b = 0, int e = n + 1) {
	if(e - b == 1) {
		seg[id].push_back(dp[b]);
		return;
	}
	int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
	build(lc, b, mid);
	build(rc, mid, e);
	for (int i = 0; i < seg[lc].size(); i++)
		seg[id].push_back(seg[lc][i]);
	for (int i = 0; i < seg[rc].size(); i++)
		seg[id].push_back(seg[rc][i]);
	sort(seg[id].begin(), seg[id].end());
}

ll get(int l, int r, ll val, int id = 1, int b = 0, int e = n + 1) {
	if(l >= e || b >= r)
		return 0;
	if(l <= b && e <= r) {
		int x = lower_bound(seg[id].begin(), seg[id].end(), val) - seg[id].begin();
		int sz = seg[id].size();
		return sz - x;
	}
	int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
	return get(l, r, val, lc, b, mid) + get(l, r, val, rc, mid, e);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> dp[i + 1];
		dp[i + 1] += dp[i] - k;
	}
	build();
	for (int i = 0; i <= n; i++) {
		ans += get(i + 1, n + 1, dp[i]);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 64500
#include <bits/stdc++.h>
using namespace std;
 
int n, t, a[100010];
int mx=0, ans=0;
bool yes[100005];

priority_queue <int> pq;
vector <int> v;
 
int main()
{
	scanf ("%d%d", &n, &t);
	for (int i=0; i<n; i++)  scanf ("%d", &a[i]);
	
	for (int i=n-2; i>=0; i--){
		pq.push (a[i+1]);
		mx = max (mx, pq.top()-a[i]);
		v.push_back (pq.top()-a[i]);
	}
	
	for (int i=0; i<v.size(); i++) 
		if (v[i] == mx) 
			ans++;
	
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1660
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ab = []
ans = 0
for _ in range(n):
    a, b = map(int, readline().split())
    ab.append(a + b)
    ans -= b
ab.sort(reverse=True)
ans += sum(ab[::2])
print(ans)


Measured memory_bytes: 7448
#include<stdio.h>
 
int main() {
    int n, x, count = 0, i, j, k;
    while(1) {
        scanf("%d %d", &n, &x);
        if(n == 0) break;
        if(n * 3 - 3 < x) {
            puts("0");
            continue;
        }
        for(i = n; i >= 3; --i) {
            for(j = i - 1; j >= 2; --j) {
                for(k = j - 1; k >= 1; --k) {
                    if(i + j + k == x) ++count;
                }
            }
        }
        printf("%d\n", count);
        count = 0;
    }
    return 0;
}


Measured memory_bytes: 2076
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a=0;
	int ransuu[100000];
	for (int i = 0; i < n; i++) {
		cin >> ransuu[i];
		if (i > 0)if (ransuu[i] > ransuu[i - 1]) {
			a++;
		}
	}
	cout << a << endl;
}



Measured memory_bytes: 3476
s = input()
t_list = ("dream", "dreamer", "erase", "eraser")
right = len(s)
left = 0
counter = 100000
while counter > 0:
    for i in t_list:
        if s[left-len(i):right] == i:
            right -= len(i)
            left -= len(i)
        counter -= 1
if right == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3316
a, b, c, d, e, f = map(int, input().split())

limit = e / (100 + e)

mx = 0
ans = [100 * a, 0]

a_max = f // (100 * a)
for a_i in range(a_max + 1):
    ag = 100 * a * a_i
    bcdg_max = f - ag
    b_max = bcdg_max // (100 * b)
    for b_i in range(b_max + 1):
        bg = 100 * b * b_i
        if ag + bg == 0:
            continue
        cdg_max = bcdg_max - bg
        c_max = cdg_max // c
        for c_i in range(c_max + 1):
            cg = c * c_i
            dg_max = cdg_max - cg
            d_max = dg_max // d
            for d_i in range(d_max + 1):
                dg = d * d_i
                tmp = (cg + dg) / (ag + bg + cg + dg)
                if mx < tmp <= limit:
                    mx = tmp
                    ans = [ag + bg + cg + dg, cg + dg]

print(*ans)


Measured memory_bytes: 3064
def f(n,s,x):
  if n == s == 0:
    return 1
  elif n == 0 or x == 0:
    return 0
  else:
    a = 0
    for i in range(x):
      a += f(n-1,s-i,i)
    return a
while True:
  n,s = map(int,input().split())
  if n == s == 0:
    break
  print(f(n,s,10))

Measured memory_bytes: 7748
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}
#line 2 "main.cpp"
int main(){
	int n,x,t;
	std::cin>>n>>x>>t;
	std::cout<<(n+x-1)/x*t<<std::endl;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define endl endl;cf
#define be begin()
#define sz size()
#define en end()
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=1;i<=b;++i)
#define forr(i,a,b) for(ll i=0;i<b;++i)
#define rngx mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define cf cout.flush()
int main()
{
    ios;
    ll n , m , curr ;
    cin >> n >> m >> curr ;
    vl v ;
    set<ll>s;
    forn( i ,1 , m)
    {
        ll x;
        cin >>x ;
        s.insert(x);
    }
    ll cl = 0 , cr = 0 ;
    for(ll i = curr -1 ; i>=0 ; --i)
    {
        if(s.find(i) !=s.end()){
            ++cl;
        }
    }
    for(ll i = curr+1 ; i <= n ; ++i){
        if(s.find(i) != s.end()) ++cr;
    }
    cout << min(cr , cl ) << endl;
    return 0;
}


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

using namespace std;

int main() {
  int N, ans{200000};
  string S;
  cin >> N >> S;
  vector<int> l(N+1), r(N+1);
  for (int i = 0; i != N; ++i) {
    l[i+1] = l[i] + (S[i] == '#');
    r[N-i-1] = r[N-i] + (S[N-i-1] == '.');
  }
  for (int i = 0; i <= N; ++i) ans = min(ans, l[i] + r[i]);
  cout << ans << endl;
}



Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 0;
string s;
ll m = 200000000;

void input() {
  IN(N);
  REP(i, N) {
    IN(t);
    if (t <= m) ret++;
    CHMIN(m, t);
  }
}

void solve() {
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int x,y;
	int n;
	int d[102][102]={0};
	cin>>y>>x;
	int sum=0;
	for(int i=0;i<y;i++){
		for(int j=0;j<x;j++){
			cin>>n;
			d[i][j]=n;
			d[i][x]+=n;
			d[y][j]+=n;
			d[y][x]+=n;
		}
	}
	for(int i=0;i<=y;i++){
		for(int j=0;j<=x;j++){
			if(j>0)cout<<" ";
			cout<<d[i][j];
			if(j==x)cout<<endl;
		}
	}
}

Measured memory_bytes: 3136
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        d: i32,
    }

    if d == 22 {
        println!("Christmas Eve Eve Eve");
    } else if d == 23 {
        println!("Christmas Eve Eve");
    } else if d == 24 {
        println!("Christmas Eve");
    } else {
        println!("Christmas");
    }
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main(void){

int a,b,c;
cin>>a>>b>>c;

if((c>a&&b>c)||(c==a&&b>c)||(c>a&&b==c)||(c==a&&c==b)){
    cout<<"Yes"<<endl;
    }

else{
    cout<<"No"<<endl;
}
}

Measured memory_bytes: 3608
A,B,C=map(int, raw_input().split())
cnt=0

if A%2==1 or B%2==1 or C%2==1:
    print 0
    quit()

for _ in range(100):
    cnt+=1
    new_A=B/2+C/2
    new_B=A/2+C/2
    new_C=A/2+B/2
    A,B,C=new_A,new_B,new_C
    if new_A%2==1 or new_B%2==1 or new_C%2==1:
        print cnt
        quit()
else:
    print -1

Measured memory_bytes: 28012
#include <iostream>
#include <vector>
#include <cctype>

using namespace std;

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

int main(){
  char c;
  cin >> c;
  
  if(isupper(c)) cout << 'A' << endl;
  else cout << 'a' << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){

	int h, w;
	int i, j;

	while(1){
		scanf("%d %d ", &h, &w);

		if(h==0&&w==0)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
					printf("#");

				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <map>
#include <set> 

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;


typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;

int t[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

    cout << t[k-1] << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			if(m==0)break;
			int[] a = new int[m+1];
			int[] b = new int[m+1];
			for(int i=1;i<=m;i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
			}
			int[][] p = new int[m+1][1001];
			p[0][0] = 1;
			for(int i=1;i<=m;i++){
				for(int k=0;k<1001;k++){
					for(int s=0;s<=b[i];s++){
						if(k-a[i]*s<0)break;
						p[i][k] += p[i-1][k-s*a[i]];
					}
				}
			}
			int g = sc.nextInt();
			while(g--!=0)System.out.println(p[m][sc.nextInt()]);
		}
	}
}

Measured memory_bytes: 21024
n, m, c = map(int, input().split())
b = [int(x) for x in input().split()]

ans = 0
for _ in range(n):
    a = ([int(x) for x in input().split()])
    equ = 0
    for i in range(m):
        equ += a[i] * b[i]
    equ += c

    if equ > 0:
        ans+=1


print(ans)
#%%



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

int main(int argc, char* argv[]){
	int n,m;
	cin >> n;
	string s[n];
	for(int i=0;i<n;++i) cin >> s[i];
	cin >> m;
	string t[m];
	for(int i=0;i<m;++i) cin >> t[i];
	
	vector<int> a(n, 0);int cnt=0;
	for(int i=0;i<n;++i){
		string x = s[i];
			for(int j=0;j<n;++j){
				if(x==s[j]) ++cnt;
			}
			for(int j=0;j<m;++j){
				if(x==t[j]) --cnt;
			}
		a[i]=cnt;cnt=0;
	}
	sort(a.begin(),a.end());
	if(a[a.size()-1]<0) cout << 0 << endl;
	else cout << a[a.size()-1] << endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
S = input()
dp = [0] * 13
dp[0] = 1

for i in range(len(S)):
    cdp = [0] * 13
    tmpS = 0
    if S[i] == '?':
        tmpS = -1
    else:
        tmpS = int(S[i])
    for j in range(10):
        if tmpS != -1 and tmpS != j: continue
        for k in range(13):
            cdp[(k * 10 + j) % 13] += dp[k]
            cdp[(k * 10 + j) % 13] %= MOD

    dp = cdp[:]
print(dp[5])

Measured memory_bytes: 74136
#include <stdio.h>

int main()
{
    int K;
    int g,k;
    int ans;

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

    if(K%2==0){
        g=K/2;
        k=K/2;
    }
    else{
        g=K/2;
        k=(K+1)/2;
    }
    ans=g*k;
    
    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n;
int l[110];

void init() {

}

void input() {
  cin >> n;
  REP(i, n) {
    cin >> l[i];
  }
}

void solve() {
  sort(l, l+n);
  int sum = 0;
  FOR(i, 0, n-1) {
    sum += l[i];
  }
  if (sum <= l[n-1]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int cnt[26],i,x,c,len,sum;
	char buf[1001];
	scanf("%s",buf);
	len=strlen(buf);
	for(i=0;i<26;i++)	cnt[i]=0;
	for(i=0;i<len;i++)	{
		x=buf[i]-'a';
		cnt[x]++;
	}
	sum=0;
	for(i=0;i<26;i++)	{
		x=cnt[i]%2;
		sum+=x;
	}
	printf("%d\n",sum/2);
	return 0;
}


Measured memory_bytes: 2732
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let mut v = vec![];
    let mut n: isize;
    input!(n);

    if n == 0 {
        p(0);
        return;
    }

    while n != 1 {
        if n > 0 {
            if n % 2 == 0 {
                v.push(0);
            } else {
                v.push(1);
            }
            n /= -2;
        } else {
            if n % 2 == 0 {
                v.push(0);
                n /= -2;
            } else {
                v.push(1);
                n = (n - 1) / -2;
            }
        }
    }
    v.push(1);
    for z in v.iter().rev() {
        print!("{}", z);
    }
    println!("");
}

Measured memory_bytes: 4352
#include <stdio.h>

#define N 10	// RÌ
#define TOP 3	// ã©ç½ÔÚÜÅ\¦·é©

int main(void) {
	int height[N];
	int i, j;
	int heighest;
	int t;

	i = 0;
	while(scanf("%d",&height[i++]) != EOF) {
	}

	for(i = 0; i < TOP; i++) {
		heighest = i;
		for(j = i; j < N; j++) {
			if(height[heighest] < height[j]) {
				heighest = j;
			}
		}
		t = height[i];
		height[i] = height[heighest];
		height[heighest] = t;
	}

	for(i = 0; i < TOP; i++) {
		printf("%d\n", height[i]);
	}

	return 0;
}

Measured memory_bytes: 0
#import<ios>
int D,d,c,a,X=448;char s[9];
int main()
{
for(;c+21&&scanf("%s",s);a+=D/64)
c=*s-69,
d=511-D,
D=
c-9 ?
c-14?
c   ?
c-18?
c-13?
c-7 ?
a&&printf("%d\n",a),a=0,83:
D   &X|d* 8&56|D/ 8&7:
D   &X|D* 8&56|d/ 8&7:
D*64&X|D   &56|d/64:
d*64&X|D   &56|D/64:
d* 8&X|D/ 8&56|D   &7:
D* 8&X|d/ 8&56|D   &7;
}

Measured memory_bytes: 0
#include <stdio.h>
int a[1000001];
int main(){
    int K;
    scanf("%d",&K);
    a[1]=7%K;
    for(int i=2;i<=K;i++)a[i]=(a[i-1]*10+7)%K;
 
    for(int i=1;i<=K;i++)if(a[i]==0){
        printf("%d\n",i);
        return 0;
    }
    printf("-1\n");
}

Measured memory_bytes: 5608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int a[N];
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);int ans=0;
	for(int i=1,j=1;i<=n;i=j+1,j=i)
	{
		while(j<n&&a[i]==a[j+1]) j++;
		if(j-i+1>=a[i]) ans+=j-i+1-a[i];
		else ans+=j-i+1;
	}
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 640
function main(input) {
  const inputs = input.split('\n')[0].split(' ').map( x => parseInt(x, 10))
  answer = 0
  if (inputs[0] > inputs[1]){
    answer += inputs[0];
    inputs[0] = inputs[0]-1;
  }else{
    answer += inputs[1];
    inputs[1] = inputs[1]-1;
  }

  if (inputs[0] > inputs[1]){
    answer += inputs[0];
    inputs[0] = inputs[0]-1;
  }else{
    answer += inputs[1];
    inputs[1] = inputs[1]-1;
  }

  console.log(answer);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <math.h>
using namespace std;
int main(){
    int n,nummax=INT_MIN,nummin=INT_MAX;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        nummax=max(nummax,a[i]);
        nummin=min(nummin,a[i]);
    }
    cout<<nummax-nummin<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string X, Y;
    cin >> X >> Y;

    if (X > Y) {
        cout << ">" << endl;
    } else if (X < Y) {
        cout << "<" << endl;
    } else {
        cout << "=" << endl;
    }

    return 0;
}


Measured memory_bytes: 760
N = int(input())
A = list(map(int,input().split()))

ans = [0]*N
for i in range(N):
    if i % 2 == 0:
        ans[0] += A[i]
    else:
        ans[0] -= A[i]

for i in range(1,N):
    ans[i] = (A[i-1] - ans[i-1]/2)*2

for i in range(N):
    if i != N-1:
        print(int(ans[i]),end=' ')
    else:
        print(int(ans[i]))


Measured memory_bytes: 14092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int ans=max(0,C-(A-B));
  cout << ans << endl;
}

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

int main()
{
    int N, M, a = 0;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for (int i = 0; i < N; i++)
        cin >> A.at(i);
    for (int i = 0; i < M; i++)
        cin >> B.at(i);
    for (int i = 0; i < N - (M - 1); i++) {
        for (int j = 0; j < N - (M - 1); j++) {
            for (int k = 0; k < M; k++) {
                if (A.at(i + k).substr(j, M) != B.at(k))
                    break;
                if (k == M - 1)
                    a = 1;
            }
        }
    }
    if (a == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int f[410][410] = {0};
ll dp[410][410];
int n;
vector<ll> a;
vector<ll> sum;

ll rec(int i, int j) {
    if(f[i][j]==1) return dp[i][j];
    f[i][j] = 1;
    if(i == j) return 0;
    ll ret = 1e18;
    for(int k = i; k < j; k++) {
        chmin(ret, rec(i, k) + rec(k+1, j));
    }
    return dp[i][j] = ret + sum[j+1] - sum[i];
}

int main(){
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sum.assign(n+1,0);
    for(int i = 0; i < n; i++) sum[i+1] = sum[i] + a[i];
    ll ans = rec(0, n-1);
    cout << ans << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  cout<<"ABC"<<n<<endl;
}

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

#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ll long long int
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD=1e9+7;

void solve(){
   ll a,b;
   cin >>a >> b;
   ll ans=a*b;
   cout << ans;
}


int main(){
  IOS
     solve();
}
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid

Measured memory_bytes: 3636
import sys
fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


def initialize_int(adj, s):
    """
    assume that all vertex in {0, 1, 2, ..., N - 1}
    """
    N = len(adj)
    MAX_NUM = float('inf')
    d = [MAX_NUM] * N
    d[s] = 0
    parent = [None] * N
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# and also we do not have to implement Vertex class.
# Instead, we can use (distance, vertex).
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, parent = initialize_int(adj, s)
    priority_queue = []
    heappush(priority_queue, (d[s], s))
    while priority_queue:
        distance, source = heappop(priority_queue) 
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
                parent[neighbor] = source
                heappush(priority_queue, (new_distance, neighbor))
    return d


n, m, s, t = [int(elem) for elem in fin().split()]
s -= 1
t -= 1
adj = defaultdict(list)
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = [int(elem) for elem in fin().split()]
    u -= 1
    v -= 1
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in reversed(range(n)):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
for cost in reversed(min_cost_after_each_year_reversed):
    print(initial_money - cost)


Measured memory_bytes: 130652
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=105;
int n,m,a[maxn],b[maxn];
inline char nc(){
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
int main(){
	n=read(),m=read();
	for (int i=1;i<=m;i++) a[i]=read();
	for (int i=2;i<=m;i++)
	if(a[i]&1) swap(a[i],a[1]);
	for (int i=m-1;i>1;i--)
	if(a[i]&1) swap(a[i],a[m]);
	for (int i=2;i<m;i++)
	if(a[i]&1) return puts("Impossible")&0;
	for (int i=1;i<=m;i++)
	printf("%d",a[i]),putchar(i==m?'\n':' ');
	if(a[1]>1) b[++b[0]]=a[1]-1;
	for (int i=2;i<m;i++) b[++b[0]]=a[i];
	if(m>1){
		b[++b[0]]=2;
		if(a[m]>1) b[++b[0]]=a[m]-1;
	}else b[++b[0]]=1;
	for (int i=0;i<=b[0];i++)
	printf("%d",b[i]),putchar(!i||i==b[0]?'\n':' ');
	return 0;
}

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

using namespace std;
int main()
{
  int j = 0;
  string player = "abc";
  string strlist[3], str;
  for (int i = 0; i < 3; i++) cin >> strlist[i];

  while (true)
  {
    if (strlist[j].length() == 0)
    {
      cout << (char)toupper(player[j]);
      break;
    }
    str = strlist[j][0];
    strlist[j].erase(0, 1);
    j = player.find(str[0]);
  }

  cin >> j;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
struct UnionFind {
    vector<int> par,siz; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) , siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        for(int i = 0; i < N; i++) siz[i] = 1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        siz[rx]+=siz[ry];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x){
        return siz[root(x)];
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf(n);
    for(int i=0;i<m;i++){
        int x,y;cin >> x >> y;
        x--,y--;
        uf.unite(x,y);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(uf.same(p[i],i)){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(void) {
  int n; cin >> n;
  double ans;
  for (int i=0; i<n; i++) {
    double x; string u;
    cin >> x >> u;
    if (u == "JPY") {
      ans += x;
    } else {
	  ans += x * 380000;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3740
main = do
    s <- getLine
    case s of
        "-" -> return ()
        _   -> oneShuffle s >> main

oneShuffle :: String -> IO()
oneShuffle s = do
    ns <- getLoopIntValues 
    putStr $ foldl shuffle s ns
    putStrLn ""

shuffle :: String -> Int -> String
shuffle s n = drop n s ++ take n s

getLoopIntValues :: IO([Int])
getLoopIntValues = do
    vs <- getLoopValues
    return $ map read vs
    
getLoopValues :: IO([String])
getLoopValues = do
    loopNum <- getInt
    getLoopValues' loopNum

getLoopValues' :: Int -> IO([String])
getLoopValues' 0 = return []
getLoopValues' n = do
    v <- getLine
    vs <- getLoopValues' (n - 1)
    return $ v : vs

getInt :: IO (Int)
getInt = do
    str <- getLine
    return $ read str
    


Measured memory_bytes: 4028
#include <iostream>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

#define LOOP(N) for(int i=0; i<(N); ++i)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(start); i<(end); ++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using Graph = vector< vector<int> >;

const ll MOD = 1000000007;

void sayYes() {cout << "Yes" << endl;}
void sayNo() {cout << "No" << endl;}


int main() {
    int N; cin >> N;
    char s[1000001] = {0,}; cin >> s;
    if (s[0] == 'W') {
        cout << 0;
        return 0;
    }
    
    bool is_L = true;
    int l_num = 1;
    int factor = 1;
    ll result = 1;
    FOR(i, 1, 2*N) {
        is_L = (s[i-1]==s[i]) ? !is_L : is_L;
        if (is_L) {
            ++l_num;
            ++factor;
        }
        else {
            result = result * factor % MOD;
            --factor;
        }
        // cout << i << " " << (is_L ? 'L' : 'R') << " " << l_count << " " << r_count << endl;
    }
    if (l_num != N) {
        cout << 0;
        return 0;
    }

    FOR(i, 1, N) {
        result = result * i % MOD;
    }
    cout << result * N % MOD;
}

Measured memory_bytes: 1280
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	int N, M, a, b, w;
	int[] parent;
	Node[] node;

	void run() {
		for (;;) {
			N = sc.nextInt(); // 荷物数
			M = sc.nextInt(); // クエリ数
			if ((N | M) == 0) {
				return;
			}
			parent = new int[N + 1];
			node = new Node[N + 1];
			init();

			for (int i = 0; i < M; i++) {
				String query = sc.next();
				a = sc.nextInt();
				b = sc.nextInt();
				if (query.equals("!")) {
					w = sc.nextInt();
					union(a, b, w);
				} else if (query.equals("?")) {
					System.out.println(same(a, b) ? node[b].weight
							- node[a].weight : "UNKNOWN");
				}
			}
		}
	}

	void init() {
		for (int i = 0; i <= N; i++) {
			parent[i] = i;
			node[i] = new Node(0, 0);
		}
	}

	void union(int x, int y, int w) {
		int rootX = find(x);
		int rootY = find(y);
		if (rootX == rootY) {
			return;
		}
		if (node[rootX].rank < node[rootY].rank) {
			node[rootX].weight = -w - node[x].weight + node[y].weight;
			parent[rootX] = rootY;
		} else {
			node[rootY].weight = w - node[y].weight + node[x].weight;
			parent[rootY] = rootX;

			if (node[rootX].rank == node[rootY].rank) {
				node[rootX].rank++;
			}
		}
	}

	int find(int target) {
		if (parent[target] == target) {
			return target;
		} else {
			int tmp = find(parent[target]);
			node[target].weight += node[parent[target]].weight;
			return parent[target] = tmp;
		}
	}

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

	class Node {
		int weight;
		int rank;

		/**
		 * @param weight
		 * @param rank
		 */
		public Node(int weight, int rank) {
			super();
			this.weight = weight;
			this.rank = rank;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

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

int main(void){
   int N,M; 
   cin >>N>>M;
   bool AC[N];
   int WA[N];
  
   int WAsum=0;
   int ACsum=0;
   
   rep(i,N){
       WA[i]=0;
       AC[i]=false;
   }
   while(M>0){
       int p;
       string s;
       cin >> p>>s;
       M--;
       if(AC[p-1]==true){
           continue;
       }
       if(s=="AC"){
           WAsum+=WA[p-1];
           ACsum++;
           AC[p-1]=true;
           
       }
       else if(s=="WA"){
           WA[p-1]++;
       }
   }
   cout << ACsum << " "<< WAsum << endl;
  
}


Measured memory_bytes: 4044
X, K, D = [int(x) for x in input().split()]

if X < 0:
    X *= -1

if X - K * D >= 0:
    print(X - K * D)
else:
    times = X // D
    K -= times
    X -= times * D
    X -= (K % 2) * D
    print(abs(X))


Measured memory_bytes: 61684
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>
const int N = 2e5 + 10;

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i = 0 ; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(i == n - 1) {
            ans += (a[i] == x);
        }
        else if (a[i] <= x) {
            x -= a[i];
            ans++;
        } else {
            break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

def gcd(a, b):
    while a%b!=0:
        a, b = b, a%b
    return b

X = B//C - (A-1)//C
Y = B//D - (A-1)//D
CD = C*D // gcd(C, D)
XY = B//CD - (A-1)//CD

print(B-A+1-(X+Y-XY))

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (a < 10 && b < 10 ? a * b : -1) << endl;
  return 0;
}


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

int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;

    unsigned int p = 0,ptmp;
    int j[65000];

    for(int i = 0;i < n;i++){
      scanf("%d",&ptmp);
      p += ptmp;
    }
    for(int i = 0;i < n-1;i++) scanf("%d",&j[i]);

    sort(j,j+n-1,greater<int>());

    int ntmp = n;

    for(int i = 0;i < n-1;i++){
      if(p * ntmp <= (p+j[i]) * (ntmp-1)){
        ntmp--;
        p += j[i];
      }else{
        break;
      }
    }
    cout << p * ntmp << endl;
  }
  return 0;
}







Measured memory_bytes: 3396
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int s =scan.nextInt();
		int h = s/3600;
		int m = (s%3600)/60;
		s=(s%3600)%60;
		System.out.println(h+":"+m+":"+s);
        scan.close();
	}

}


Measured memory_bytes: 26256