akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int main()
{
  string S;
  cin >> S;
  stack<int> Q;
  for (int i=0; i<S.size(); i++) {
    if (S[i] == 'S') Q.push(1);
    else {
      if (Q.size() && Q.top() == 1) {
        Q.pop();
      } else {
        Q.push(-1);
      }
    }
  }
  printf("%d\n", Q.size());
}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL k;
    cin >> n >> k;
    vector<LL> a(n);
    for(LL i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    LL lo=1;
    LL hi=a[a.size()-1];
    LL mid=(lo+hi)/2;
    LL sum;
    LL ans=a[a.size()-1];
    LL tmp;
    while(true){
        sum=0;
        for(LL i=0; i<n; i++){
            if(a[i]%mid==0){
                tmp=a[i]/mid;
            }else{
                tmp=a[i]/mid+1;
            }
            sum+=tmp-1;
        }
        //cout << sum << " " << lo << " " << mid << " " << hi << endl;
        if(sum<=k){
            ans=mid;
        }
        if(lo+1>=hi){
            break;
        }
        if(sum<=k){
            hi=mid;
        }else{
            lo=mid;
        }
        mid=(lo+hi)/2;
    }

    cout << ans << endl;

    return 0;
}


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

void kaibun(string &S, string &ans) {
    rep(i,S.size()/2) {
        if (S.at(i) != S.at(S.size() - 1 - i)) {
            ans = "No";
        }
    }
}

int main() {
    string S;
    cin >> S;
    string ans = "Yes";
    int N = S.size();

    string bS = S.substr(0, (N - 1) / 2);
    string eS = S.substr((N + 3) / 2 - 1);
    kaibun(S, ans);
    kaibun(bS, ans);
    kaibun(eS, ans);

    cout << ans << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a[1001];
long long b[1000000];
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		a[n] = 0;
		int f = 0;
		for (int i = 0; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				b[f] = a[i] + a[j];
				f++;
			}
		}
		long long sum = 0;
		sort(b, b + f);
		for (int i = 0; i <= f; i++) {
			int s = 0, e = f, t;
			long long g = m - b[i];
			while (e - s > 1) {
				t = (e + s) / 2;
				if (b[t] > g) e = t;
				if (b[t] <= g) s = t;
			}
			if (b[i] + b[s] <= m) sum = max(sum, b[i] + b[s]);
			if (b[i] + b[e] <= m) sum = max(sum, b[i] + b[e]);
		}
		cout << sum << endl;
	}
}

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

int main(){
  int X;
  cin >> X;
  for(ll i=0;i<150;++i){
    for(ll j=0;j<150;++j){
      if(pow(j,5)-pow(i,5)==X){
        cout << j << " " << i << endl;
        return 0;;
      }
      else if(pow(j,5)+pow(i,5)==X){
        cout << j << " " << -i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4080
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    lli n, a, b,ans=0;
    cin >> n >> a >> b;
    if(a == 0) {
        cout << 0 << endl;
        return 0;
    }
    if(b == 0) {
        cout << n << endl;
        return 0;
    }
    ans += a * (n / (a + b));
    if(n % (a + b) <= a)
        ans += n % (a + b);
    else if(n % (a + b) > a)
        ans += a;
    cout << ans << endl;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

void dfs(const vvi& g,int p,int u,bool odd,const vi& ps,vector<tuple<int,int>>& rs)
{
	int mn=-INF,mx=INF;
	if(ps[u]!=-1){
		if(ps[u]%2!=odd)
			throw "X";
		tie(mn,mx)=mt(ps[u],ps[u]);
	}
	for(int v:g[u]) if(v!=p)
		dfs(g,u,v,!odd,ps,rs);
	for(int v:g[u]) if(v!=p){
		mn=max(mn,get<0>(rs[v])-1);
		mx=min(mx,get<1>(rs[v])+1);
	}
	if(mn>mx)
		throw "X";
	rs[u]=mt(mn,mx);
}

void dfs2(const vvi& g,int p,int u,vi& ps,const vector<tuple<int,int>>& rs)
{
	for(int v:g[u]) if(v!=p){
		int p=ps[u]-1;
		if(p<get<0>(rs[v])) p+=2;
		ps[v]=p;
		dfs2(g,u,v,ps,rs);
	}
}

void solve(const vvi& g,vi& ps)
{
	int n=g.size();
	vector<tuple<int,int>> rs(n);
	rep(i,n) if(ps[i]!=-1){
		dfs(g,-1,i,ps[i]%2,ps,rs);
		dfs2(g,-1,i,ps,rs);
		break;
	}
}

int main()
{
	for(int n;cin>>n && n;){
		vvi g(n);
		vi ps(n,-1);
		rep(i,n-1){
			int u,v; cin>>u>>v; u--,v--;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		int k; cin>>k;
		rep(i,k){
			int v,p; cin>>v>>p; v--;
			ps[v]=p;
		}

		try{
			solve(g,ps);
			cout<<"Yes"<<endl;
			for(int p:ps)
				cout<<p<<endl;
		}
		catch(...){
			cout<<"No"<<endl;
		}
	}
}


Measured memory_bytes: 17792
#include <cstdio>
#include <list>
#include <iostream>
using namespace std;

int main(){
	int n,num;
	char s[20];
	list<int> A;
	scanf("%d",&n);
	for(int i = 1 ;i <= n ; i++){
		scanf("%s",s);
		if(s[0]=='i') {
			scanf("%d",&num);
			A.push_front(num);
		}
		else if(s[6]=='F') A.pop_front();
		else if(s[6]=='L') A.pop_back();
		else if(s[0]=='d'){
			scanf("%d",&num);
			for(list<int>::iterator it=A.begin();it!=A.end();it++){
				if(*it==num) {
					A.erase(it);
					break;
				}
			}
		}

	}
	int i =0;
	for(list<int>::iterator it=A.begin();it!=A.end();it++){
		if(i++) printf(" ");
		printf("%d",*it);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 34432
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
  string a, b;
  cin >> a >> b;
  cout << b << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n;
ll h[200000];
int f[200000];

ll abs(ll a, ll b)
{
    return (a>b)?a-b:b-a;
}
ll min(ll a, ll b)
{
    return (a<b)?a:b;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; ++i)
        cin>>h[i];
    f[n]=0;
    f[n-1]=abs(h[n-1],h[n]);
    for (int i=n-2; i>=1; --i)
        f[i]=min(f[i+1]+abs(h[i],h[i+1]), f[i+2]+abs(h[i],h[i+2]));
    cout<<f[1]<<endl;
    return 0;
}



Measured memory_bytes: 1408
s= input()[::-1]
 
sum_of_digits = 0
 
cnts = [0] * 2019
 
cnts[0] = 1
 
d = 1
 
for c in s:
    sum_of_digits += int(c) * d
    num = sum_of_digits % 2019
    d *= 10
    d %=2019
    cnts[num] += 1
 
ans = 0
    
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Measured memory_bytes: 68440
import sys
from sys import stdin
input = stdin.readline

n,k = (int(x) for x in input().split())
w = [int(input()) for i in range(n)]

# 最大積載Pのトラックで何個の荷物を積めるか
def check(P):
    i = 0
    for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i

def solve():
    left = 0
    right = 100000 * 10000  #荷物の個数 * 1個当たりの最大重量

    while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

print(solve())


Measured memory_bytes: 9580
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
	string s; cin >> s;
	ll ans = 0;
	for (char c : s){
		if (c == '+') ans++;
		else ans--;
	}cout << ans << endl;
	return 0;
}

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

using ll = long long;
// Loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

int main(void) {
	int atama, asi;
	cin >> atama >> asi;
	int kame, turu;
	kame = (asi / 2) - atama;
	turu = atama - kame;
	Yes((kame >= 0) && (turu >= 0) && (atama == kame + turu)
	    && (asi == 2 * turu + 4 * kame));
	return 0;
}

Measured memory_bytes: 3620
// Last Change: 09/10/2019 23:57:18.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max();

struct Node {
  ll cost;
  ll pos;
  Node(ll a, ll b) : cost(a), pos(b) {
  }
  bool operator<(const Node &another) const {
    return cost < another.cost;
  }
  bool operator>(const Node &another) const {
    return cost > another.cost;
  }
};

int main() {
  // n:頂点数
  ll n;
  cin >> n;
  vector<vector<pair<ll, ll>>> edge(n);
  for (ll i = 0; i < n - 1; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    edge[a].push_back(make_pair(b, c));
    edge[b].push_back(make_pair(a, c));
  }

  ll Q, K;
  cin >> Q >> K;
  --K;

  vector<ll> dist(n, INF);
  priority_queue<Node, vector<Node>, greater<Node>> q;
  ll cnt = 0;
  q.push(Node(0, K));
  while (cnt < n) {
    Node cur = q.top();
    q.pop();
    if (dist[cur.pos] > cur.cost) {
      dist[cur.pos] = cur.cost;
      ++cnt;
      for (auto &&e : edge[cur.pos]) {
        q.push(Node(cur.cost + e.second, e.first));
      }
    }
  }

  {
    ll x, y;
    for (ll i = 0; i < Q; ++i) {
      cin >> x >> y;
      --x, --y;
      cout << dist[x] + dist[y] << endl;
    }
  }
}


Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    v[x-1] = i;
  }
  int res = n - 1;
  int l = 1;
  for (int i = n - 2; i >= 0; i--) {
    if (v[i] < v[i+1]) {
      l++;
      res = min(res, n - l);
    } else l = 1;
  }
  cout << res << endl;
}

Measured memory_bytes: 4060
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            int[] A = new int[n];
            int max = 0;
            for(int i=0; i<n; i++)
            {
                A[i] = int.Parse(In[i]);
                //Console.WriteLine("i={0}",i);
                if (A[i] > max) max = A[i];
            }
            int[] C = new int[max+1];//C[0]は空で、C[1]に１の出た回数を記録する、最後の要素は、C[max];
            for(int i=0; i<n; i++)
            {
                C[A[i]]++;
            }
            long[] CC = new long[max + 1];//場合の数を記録する
            long sum = 0;//全部の合計
            for (int i = 0; i < max+1; i++)
            {
                if (C[i] == 0 || C[i] == 1) CC[i] = 0;
                else if (C[i] >= 2)
                {
                    long x = C[i];
                    CC[i] = x * (x - 1) / 2;
                }
                sum += CC[i];//全部の場合の数の合計を出しておく
            }
            long res = 0;
            for(int i=0; i<n; i++)//着目する数字をsumから引き、ボール一個減らした分だけsumに足す
            {
                if (C[A[i]] == 1) res = sum;
                else if (C[A[i]] == 2) res = sum - 1;
                else if (C[A[i]] >= 3)
                {
                    res = sum;
                    long y = C[A[i]];
                    res-= y * (y - 1) / 2;
                    long z = C[A[i]]-1;
                    res += z * (z - 1) / 2;
                }
                Console.WriteLine(res);
            }
        }
    }
}

Measured memory_bytes: 36060
#include <cstdio>
#include <utility>
#include <map>
using namespace std;


int main(){
  map<char,int>  a;
  char x,y;
  a['A']=1;
  a['B']=a['C']=0;
  while(scanf("%c,%c",&x,&y)>0) swap(a[x],a[y]);
  for(int i=0;i<3;i++){
    if(a[(char)(i+'A')]==1){
      printf("%c\n",(char)(i+'A'));break;
    }
  }
  return 0;
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
typedef long long lnt;
lnt d[100010],p[100010],ans[100010];
std::vector<lnt>tmp;
bool vi[100010];
void dfs(lnt x){
    vi[x]=true;
    tmp.push_back(x);
    if(vi[p[x]]) return;
    dfs(p[x]);
    return;
}
int main(){
    lnt n,m,k,x,i;
    lnt t;
    scanf("%lld",&n);
    for(k=1;k<=n;k++){
        scanf("%lld",&d[k]);
    }
    scanf("%lld%lld",&m,&t);
    for(k=1;k<n;k++) p[k]=k;
    for(k=1;k<=m;k++){
        scanf("%lld",&x);
        std::swap(p[x-1],p[x]);
    }
    for(k=1;k<n;k++){
        if(!vi[k]){
            tmp.clear();
            dfs(k);
            long long c=t%tmp.size();
            for(i=0;i<tmp.size();i++){
                lnt j=tmp[i];
                ans[j]=tmp[(i+c)%tmp.size()];
            }
        }
    }
    lnt qq=d[1];
    for(k=1;k<=n;k++){
        printf("%lld\n",qq);
        qq+=(d[ans[k]+1]-d[ans[k]]);
    }
}
        

Measured memory_bytes: 7668
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(int s) {
    int color[n], d[n], p[n];
    for (int i=0; i<n; i++) {
        color[i] = WHITE;
        d[i] = INFTY;
    }
    d[s] = 0;
    color[s] = GRAY;

    while (1) {
        int mincost = INFTY;
        int u = -1;
        for (int i=0; i<n; i++) {
            if (color[i]!=BLACK && d[i]<mincost) {
                mincost = d[i];
                u = i;
            }
        }

        if (mincost == INFTY) {
            break; // All nodes visited
        }

        color[u] = BLACK;
        for (int v=0; v<n; v++) {
            if (color[v]!=BLACK && M[u][v]<INFTY) {
                if (d[u]+M[u][v]<d[v]) {
                    d[v] = d[u]+M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for (int i=0; i<n; i++) {
        cout << i << " " << d[i] << endl;
    }
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            M[i][j] = INFTY;
        }
    }

    int u, k, v, c;
    for (int i=0; i<n; i++) {
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
 
    dijkstra(0);
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
using namespace std;
int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int main() {
    int K;
    cin >> K;
    long long summ = 0;
    for (int i = 1; i <= K; ++i)
        for (int j = 1; j <= K; ++j)
            for (int k = 1; k <= K; ++k)
                summ += gcd(gcd(i, j), k);
    cout << summ << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<int>edge[200005];
bool used[200005],cy[200005];
int go[200005];
int G[200005];
int dfs(int v,int u){
	if(G[v] != -1) return G[v];
	set<int>S;
	for(int i=0;i<edge[v].size();i++){
		if(!cy[edge[v][i]]) S.insert(dfs(edge[v][i],v));
	}
	for(int i=0;;i++){
		if(S.find(i) == S.end()){
			return G[v] = i;
		}
	}
}
vector<int>cand[200005];
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		int a; cin >> a; go[i] = a;
		edge[a].pb(i);
	}
	int cur = 1;
	vector<int>vi;
	for(int i=1;i<=2*n;i++){
		if(!used[cur]) used[cur] = 1;
		else if(!cy[cur]){
			vi.pb(cur);
			cy[cur] = 1;
		}
		cur = go[cur];
	}
	memset(G,-1,sizeof(G));
	for(int i=1;i<=n;i++){
		if(cy[i])
		{
			dfs(i,-1);
			G[i] = -1;
		}
	}
	P p = mp(INF,INF);
	for(int i=1;i<=n;i++){
		if(cy[i]){
			p = min(p,mp((int)edge[i].size(),i));
			set<int>S;
			for(int j=0;j<edge[i].size();j++){
				S.insert(G[edge[i][j]]);
			}
			for(int ii=0;;ii++){
				if(S.find(ii) == S.end()){
					cand[i].pb(ii);
					if(cand[i].size() == 2) break;
				}
			}
		}
	}
	int MX = p.fi,V = p.sc; //cout << MX << " "<< V << endl;
	for(int i=0;i<=MX;i++){
		int cur = V,val = i;
		do{
			int nx = cur,valn = val;
			cur = go[cur];
			if(cand[cur][0] == valn) val = cand[cur][1];
			else val = cand[cur][0];
			if(val != i && cur == V) goto bad;
			//cout << val << " " << cur << endl;
		}while(cur != V);
		puts("POSSIBLE"); return 0; bad:;
	}
	puts("IMPOSSIBLE");
}

Measured memory_bytes: 22644
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q),r(Q);
    for(int i = 0; i < Q; i++) cin >> l[i] >> r[i];
    vector<int> AC(N);
    AC[0] = 0;
    for(int i = 1; i < N; i++){
        AC[i] = AC[i-1];
        if(S[i] == 'C' && S[i-1] == 'A') AC[i] ++;
    }
    for(int i = 0; i < Q; i++){
        cout << AC[r[i]-1] - AC[l[i] -1] << endl;
    }
}


Measured memory_bytes: 2176
#define VERNIY st();int ver=0,niy=0,hbk=0
//#pragma GCC optimize("0fast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>

#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <functional>
#include <sstream>
typedef unsigned long long LLU;
typedef long long LL;
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
typedef vector<int> vd;
typedef vector<pair<int,int> > vpd;
typedef pair<int,int> pd;
typedef queue<int> qd;
typedef queue<pair<int,int> > qpd;
typedef priority_queue<int> maxpqd;
typedef priority_queue<int, vector<int>, greater<int> > minpqd;
#define fr front
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; ++a)
#define forineq(a,b,c) for(int a=b ; a<=c ; ++a)
#define forde(a,b,c) for(int a=b ; a>=c ; --a)
#define UPC(oo) (oo>='A' && oo<='Z')
#define LWC(oo) (oo>='a' && oo<='z')
#define DGT(oo) (oo>='0' && oo<='9')
#define UPCVOC(oo) (oo=='A' || oo=='E' || oo=='I' || oo=='U' || oo=='O')
#define LWCVOC(oo) (oo=='a' || oo=='e' || oo=='i' || oo=='u' || oo=='o')
#define filein freopen("in.txt","r",stdin);
#define fileout freopen("out.txt","w",stdout);
#define setarr(a,b,c) memset(a,b,sizeof(c))

template<class Ver>
inline void in(Ver &a){cin>>a;}
template<class Ver,class Niy>
inline void in(Ver &a, Niy &b){cin>>a>>b;}
template<class Ver,class Niy, class Hbk>
inline void in(Ver &a, Niy &b, Hbk &c){cin>>a>>b>>c;}

template<class Ver>
inline void out(Ver a){cout<<a<<"\n";};
template<class Ver,class Niy>
inline void out(Ver a,Niy b){cout<<a<<" "<<b<<"\n";};
template<class Ver,class Niy, class Hbk>
inline void out(Ver a, Niy b, Hbk c){cout<<a<<" "<<b<<" "<<c<<"\n";};

inline void debug(){cout<<"asd"<<endl;}
template<class Ver>
inline void debug(Ver a){cout<<"--- "<<a<<endl;};
template<class Ver,class Niy>
inline void debug(Ver a,Niy b){cout<<"--- "<<a<<" "<<b<<endl;};
template<class Ver,class Niy, class Hbk>
inline void debug(Ver a,Niy b,Hbk c){cout<<"--- "<<a<<" "<<b<<" "<<c<<endl;};

#define grav 9.8
#define pi 3.14159265

void st()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}


int main()
{
	VERNIY;
	in(ver);
  	if(ver<1200)
      out("ABC");
  	else if(ver<2800)
      out("ARC");
  	else
      out("AGC");
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int main (){
    int x; cin >> x;
    int sosu;
    int d=0;
    int b;
     int c;
    for(int j = 0;;j++){
        sosu = x + j;
        d = 0;
        for(int i=0; i<sosu-2;i++){
       
        c = sosu % (i+2);
        if (c == 0){
             b = 1;}
        else{
        b = 0;}
        d = d + b;
        }
        if(d == 0) 
        break;
    }
    cout << sosu;
}

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

void printLeapYear(int, int);
bool judgeLeapYear(int);

int main(void)
{
    int start_year, end_year;
    bool first_data = true;
    
    while (true) {
        scanf("%d%d", &start_year, &end_year);
        
        if (start_year == 0 && end_year == 0) {
            break;
        }
        
        if(first_data) {
            first_data = false;
        } else {
            printf("\n");
        }
        printLeapYear(start_year, end_year);

    }
    
    return 0;
}

void printLeapYear(int start_year, int end_year)
{
    bool exist_leap_year = false;
    
    for (int year = start_year; year <= end_year; year++) {
        if (judgeLeapYear(year)) {
            exist_leap_year = true;
            printf("%d\n", year);
        }
    }

    if(!exist_leap_year) {
        printf("NA\n");
    }
}

bool judgeLeapYear(int year)
{
    if (year % 400 == 0) {
        return true;
    } else if (year % 100 == 0) {
        return false;
    } else if (year % 4 == 0) {
        return true;
    } else {
        return false;
    }
}

Measured memory_bytes: 1044
/*input
7
3 3 4 5 4 5 3
5 3 4 4 2 3 2
*/
#include <bits/stdc++.h>
using namespace std;

int arr[2][1123];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[0][i];
    }
    for(int i=0;i<n;i++){
        cin>>arr[1][i];
    }
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            if(i && j)arr[i][j] += max(arr[i-1][j], arr[i][j-1]);
            else if(i)arr[i][j] += arr[i-1][j];
            else if(j)arr[i][j] += arr[i][j-1];
        }
    }
    cout<<arr[1][n-1]<<endl;
    
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        if(a % 2 != 0 && b % 2 == 0){
            long c = ((b-a-1)/2) % 2;
            System.out.println(a^b^c);
        }else if(a % 2 != 0){
            long c = ((b-a)/2) % 2;
            System.out.println(a^c);
        }else if(b % 2 == 0){
            long c = ((b-a)/2) % 2;
            System.out.println(b^c);
        }else{
            long c = ((b-a+1)/2) % 2;
            System.out.println(c);
        }
    }
}


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

int main()
{
    int i, n, intC=0, extC=0;
    char str[20];
    scanf("%s", str);
    n = strlen(str);
    if(str[0]!='A'){
        printf("WA");
        return 0;
    }
    for(i=0; i<n; i++){
        if(i>=2&&i<n-1){
            if(str[i]=='C')intC++;
        }
        if((i>=0&&i<2)||i==n-1){
            if(str[i]=='C')extC++;
        }
        if(str[i]>='B'&&str[i]<='Z'&&str[i]!='C'){
            printf("WA");
            return 0;
        }
    }
    if(intC!=1||extC>0){
        printf("WA");
        return 0;
    }
    printf("AC");
    return 0;
}


Measured memory_bytes: 128
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, L, T = map(int, readline().split())
    position = []
    #0をL-1からーに時計回りに超える場合は+1
    #0からL-1に反時計回りに超える場合は-1
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
            count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    count %= N
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 8944
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	for(int i=0;i<N;i++){
		if(A[i]%2==1)continue;
		if(A[i]%3!=0&&A[i]%5!=0){
			cout<<"DENIED"<<endl;
			return 0;
		}
	}
	
	cout<<"APPROVED"<<endl;
	
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

    while(true) {
      int n = sc.nextInt();
      if(n == 0) {
        break;
      }

      int[] scores = new int[100];
      int sum = 0;
      int max = 0;
      int min = 1000;

      for(int i = 0; i < n; i++) {
        int score = sc.nextInt();
        scores[i] = score;
        if(max < score) {
          max = score;
        }
        if(score < min) {
          min = score;
        }
        sum += score;
      }

      int average = (sum - min - max) / (n - 2);
      System.out.println(average);
    }
  }
}

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

int main( )
{
    int a, b, i;
    while( scanf("%d %d", &a, &b) != EOF )
    {
        int k = 0, flag = 0;
        for( i = a; i <= b; i++ )
        {
            if( i < 0 )
                k++;
            if( i == 0)
            {
                flag = 1;
                break;
            }
        }
        if( flag == 1 )
            printf("Zero\n");
        else if( k % 2 == 0)
            printf("Positive\n");
        else printf("Negative\n");
    }
    return 0;
}


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

int main(){
	string str;
	int max,i,n,j;
	while(cin >> str){
		max = str.size();
		n = 0;
		for(i = 0;i < max;++i){
			if(n == 0){
				if(str[i] == '@'){
					++i;
					n = (int)(str[i] - '0');
				}
				else {
					cout << str[i];
				}
			}
			else {
				for(j = 0;j < n;j++){
					cout << str[i];
				}
				n = 0;
			}
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 0
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [chars; n],
        b: [chars; m],
    }

    // println!("{:?}", a);
    // println!("{:?}", b);

    for (i, a_row) in a.iter().enumerate() {
        if b.len() != 1 && (a.len() - i+1) < b.len() {
            break;
        }

        let ref b_first = b[0];
        let len = b_first.len();

        for (j, pair) in a_row.windows(len).enumerate() {
            if &pair.to_vec() == b_first {
                // println!("{} {}", i, j);
                // println!("a {:?}", pair);
                // println!("b {:?}", b_first);

                if ((i + 1)..(i + len))
                    .into_iter()
                    .enumerate()
                    .all(|(b_i, row_index)| {
                        let a_next = &a[row_index][j..j + len];
                        let ref b_next = b[b_i + 1];
                        // println!("{:?}", row_index);
                        // println!("a next {:?}", a_next);
                        // println!("b next {:?}", b_next);
                        // println!("{:?}", &a_next.to_vec() == b_next);
                        &a_next.to_vec() == b_next
                    })
                {
                    println!("Yes");
                    return
                }
            }
        }
    }

    println!("No");
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 r;
  cin >> r;
  cout << r*r << endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    int a[n], b, c;
    vector<pair<int, int> > cb(m);
    rep(i, n) cin >> a[i];
    
    rep(i, m) {
        cin >> b >> c;
        cb[i] = make_pair(c, b);
    }    
    sort(a, a + n);
    sort(cb.begin(), cb.end());
    reverse(cb.begin(), cb.end());
    
    int idx = 0;
    bool fin = false;
    rep(i, m) {
        while (cb[i].second--) {
            if (a[idx] < cb[i].first) {
                a[idx++] = cb[i].first;
            } else {
                fin = true;
                break;
            }
            if (idx >= n) {
                fin = true;
                break;
            }
        }
        if (fin) break;
    }

    ll sum = 0;
    rep(i, n) sum += a[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N;
  string S;
  cin >> N;
  vector<ll> judge(4, 0);
  for(ll i = 0; i < N; i++) {
    cin >> S;
    if(S == "AC") judge.at(0)++;
    else if(S == "WA") judge.at(1)++;
    else if(S == "TLE") judge.at(2)++;
    else judge.at(3)++;
  }
  cout << "AC x " << judge.at(0) << endl;
  cout << "WA x " << judge.at(1) << endl;
  cout << "TLE x " << judge.at(2) << endl;
  cout << "RE x " << judge.at(3) << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <algorithm>

#define ll long long
#define pii pair<int, int>
#define pll pair<long, long>

using namespace std;

int main(){
	int N; cin >> N;
	vector<vector<int>> dp(N, vector<int>(3)), gains(N, vector<int>(3));

	for(int i = 0; i < N; i++){
		cin >> gains[i][0] >> gains[i][1] >> gains[i][2];
	}

	dp[N-1] = gains[N-1];

	for(int i = N - 2; i >= 0; i--){
		dp[i][0] = gains[i][0] + max(dp[i+1][1], dp[i+1][2]);
		dp[i][1] = gains[i][1] + max(dp[i+1][0], dp[i+1][2]);
		dp[i][2] = gains[i][2] + max(dp[i+1][0], dp[i+1][1]);
	}

	int ans = -1;

	for_each(dp[0].begin(), dp[0].end(), [&ans](int& i){
		if(i > ans) ans = i;
	});

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

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    ll n;
    cin>>n;
    vector< tuple<string,int,int>>v(n);
    loop(i,0,n)
    {
        string s;
        ll p;
        cin>>s>>p;
        get<0>(v[i]) = s;
        get<1>(v[i]) = -p;
        get<2>(v[i]) = i+1;
    }
    sort(all(v));

    loop(i,0,n)
    {
        cout<<get<2>(v[i]),nl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int i,n,m,c,j,solve=0,num;
  cin>>n>>m>>c;
  int b[m];
  for(i=0;i<m;i++)
    cin>>b[i];
  int a[n][m];
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  for(i=0;i<n;i++){
    num=c;
    for(j=0;j<m;j++){
      num=num+a[i][j]*b[j];
    }
    if(num>0)
      solve++;
  }
  cout<<solve;
  return 0;
}

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

max = 0
ignore = 0
temp = 0

for i, value in enumerate(li):
  if value > max:
    max = value
    ignore = i

for i, value in enumerate(li):
  if i == ignore:
    continue
  else:
    temp += value
    
if max < temp:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import itertools
n,m = (int(i) for i in input().split())
a = [[int(i) for i in input().split()] for i in range(m)]
b,c,answer = [],[],0
for i in range(2,n+1):
	c.append(i)
for i in range(n):
	x = []
	for j in a:
		if j[0]==i+1:
			x.append(j[1])
		elif j[1]==i+1:
			x.append(j[0])
	b.append(x)
for i in list(itertools.permutations(c,n-1)):
	if i[0] in b[0] and all(i[j+1] in b[i[j]-1] for j in range(n-2)):
		answer += 1
print(answer)

Measured memory_bytes: 3572
#include<stdio.h>
	int main(){
		int a[10],x,y,k,m,n,i;
		while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&x,&y)!=EOF){
			k=0;
			m=1;
			n=0;
			for(i=0;i<10;i++)
				k+=a[i];
			for(i=0;i<10;i++){
				n+=a[i];
				if(x*k<=n*(x+y))
					break;
				m++;
				
			}
			printf("%d\n",m);
		}
		return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int a, b;
    double t;
    cin>>a>>b>>t;
    t+=0.5;
    int ans=0;
    for(int i=1; i<t; i++){
        if(i%a==0) ans+=b;
    }
    cout<<ans<<endl;
}


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

int f(int x) {
    int s = 0;
    while (x) {
        s += x % 10;
        x /= 10;
    }
    return s;
}

int main() {
    int n;
    cin >> n;
    if (n % f(n)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
} 

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

int main(){
    int a,b, sum;
    while(cin >> a >> b){
        //int sum = a+b;
        //double result = ceil(log10(sum+1));
        cout << to_string(a+b).length() << endl;
    }
    return 0;
}


Measured memory_bytes: 3208
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

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

	private void solveD() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		Map<Integer, Set<Integer>> cMap = new HashMap<>();
		for (int i = 1; i <= N; i++) {
			cMap.put(i, new HashSet<>());
		}
		for (int i = 0; i < N - 1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			cMap.get(a).add(b);
			cMap.get(b).add(a);
		}
		int[] parentMap = new int[N + 1];
		Map<Integer, Set<Integer>> childMap = new HashMap<>();
		for (int i = 1; i<= N; i++) {
			parentMap[i] = 0;
			childMap.put(i, new HashSet<>());
		}
		List<Integer> list = new ArrayList<>();
		list.add(1);
		int depth = 1;
		int sDepth = 0;
		while (!list.isEmpty()) {
			List<Integer> nextList = new ArrayList<>();
			for (int parent : list) {
				for (int i : cMap.get(parent)) {
					if (parentMap[parent] != i ) {
						parentMap[i] = parent;
						nextList.add(i);
						if (i == N) {
							sDepth = depth;
						}
						childMap.get(parent).add(i);
					}
				}
			}
			list = nextList;
			depth++;
		}
		int jNode = N;
		for (int i = 0; i < (sDepth - 1) / 2; i++) {
			jNode = parentMap[jNode];
		}
		int sNum = getChildNum(jNode, childMap);
		int fNum = N - 2 - sNum;
		if (fNum > sNum) {
			System.out.println("Fennec");
		} else {
			System.out.println("Snuke");
		}
	}

	private int getChildNum(int node, Map<Integer, Set<Integer>> childMap) {
		int sum = 0;
		for (int child : childMap.get(node)) {
			sum += getChildNum(child, childMap) + 1;
		}
		return sum;
	}
}

Measured memory_bytes: 165492
#include <stdio.h>
#include <stdlib.h>

int Cmp(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int Max(int N, int X, int x[N]){
  int i, j, a, min;
  min = abs(X - x[N-1]);
  for(i = 0;i < N - 1;i++){
    a = x[i+1] - x[i];
    if(min > a) min = a;
    a = abs(X - x[i]);
    if(min > a) min = a;
  }
  for(i = min;i > 1;i--){
    if(min % i != 0) continue;
    for(j = 0;j < N;j++) if((double) (X - x[j]) / i != (X - x[j]) / i) break;
    if(j == N) return i;
  }
  return 1;
}

void Do(int N, int X){
  int i;
  int x[N];
  for(i = 0;i < N;i++) scanf("%d", &x[i]);
  qsort(x, N, sizeof(int), Cmp);
  printf("%d\n", Max(N, X, x));
}

int main(void){
  int N, X;
  scanf("%d %d", &N, &X);
  Do(N, X);
  return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] c1 = sc.next().split("");
        String[] c2 = sc.next().split("");

        for (int i = 0; i < c1.length; i++) {
            if (!c1[i].equals(c2[c2.length - i - 1])) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

}


Measured memory_bytes: 21844
x, y = map(int, input().split())

cnt = float('inf')
for first, add_cnt_f in (-1, 1), (1, 0):
    xx = x * first
    for last, add_cnt_l in (-1, 1), (1, 0):
        yy = y * last
        if yy >= xx:
            cnt = min(cnt, add_cnt_f + add_cnt_l + yy - xx)
print(cnt)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        while (a>0&&c>0){
            c = c-b;
            a = a-d;
        }
        if(c<=0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define maxn 200005
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector <i64> v , u ;
i64 a[2005] ;

int main()
{
    i64 i , j , k , l , m , n , q ;

    scanf("%lld %lld %lld",&n,&k,&q) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;
    a[n+1] = -1 ;

    i64 ans = 2000000000LL ;

    for(i=1 ; i<=n ; i++)
    {
        i64 m  = a[i] ;
        for(j=1 ; j<=n+1 ; j++)
        {
            if( a[j]<m )
            {
                i64 sz = (i64)v.size() ;

                sort(v.begin(),v.end()) ;

                if( sz >= k ) for(l=1 ; l+k-1 <= sz ; l++) u.pb(v[l-1]) ;
                v.clear() ;
              //  for(l=0 ; l<v.size() ; l++) printf("%lld ",v[l]) ;
              //  printf("\n") ;

                continue ;
            }
            v.pb( a[j] ) ;
        }
        sort(u.begin(),u.end()) ;
        if( (i64)u.size() >= q ) ans = min(ans,u[q-1]-u[0]) ;
        u.clear() ;
    }

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

    return 0 ;
}


Measured memory_bytes: 256
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a<=b:
    if (a+v*t>=b+w*t) :
        print("YES")
    else:
        print("NO")
else:
    if (a-v*t<=b-w*t) :
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9180
a = []
while True:
    d = list(map(int,input().split()))
    if d == [0,0]:
        break
    a.append(d)

for H,W in a:
    for i in range(0,H):
        s = ''
        for j in range(0,W):
            if (i - j) % 2 == 0:
                s += '#'
            else:
                s += '.'
        print(s)
    print('')

Measured memory_bytes: 7656
#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N = int(input())
A = [int(input()) for _ in range(N)]

c = Counter(A)

ct = 0
for i in c.values():
    if i % 2 != 0:
        ct += 1

print(ct)

Measured memory_bytes: 18364
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	int a, b, m;
	cin >> a >> b >> m;
	vector<int> p;
	int i;
	int minp, minq;
	for(i=0; i<a; i++){
		int n;
		cin >> n;
		p.push_back(n);
		//minp = min(minp, n);
	}
	vector<int> q;
	for(i=0; i<b; i++){
		int n;
		cin >> n; 
		q.push_back(n);
		//minq = min(minq, n);
	}
	minp = *min_element(p.begin(), p.end());
	minq = *min_element(q.begin(), q.end());
	//map<int, int> s;
	//int m;
	//cin >> m;
	//sort(p.begin(), p.end());
	//sort(q.begin(), q.end());
	int ans = minp+minq;
	for(i=0; i<m; i++){
		int j, k, l;
		cin >> j >> k >> l;
		j--, k--;
		//s[j]++;
		//s[k]++;
		//if(s[j]>1 || s[k]>1) break;
		//else{
		//cout << p[j-1] << " " << q[k-1] << endl;
		//tmp = p[j-1]  + q[k-1] - l;
		ans = min(ans, p[j]+q[k]-l);
	}
	cout << ans << endl;
	return 0;
}
		


Measured memory_bytes: 4276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc089b
{
    class Abc089b
    {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var ss = Console.ReadLine().Split();
            Console.WriteLine(ss.Contains("Y") ? "Four" : "Three");
        }
    }
}

Measured memory_bytes: 11220
n = int(input())
a = 0
b = n
m = 1000000
for i in range(n//2):
    a += 1
    b -= 1
    s = sum(list(map(int, list(str(a))))) + sum(list(map(int, list(str(b)))))
    m = min(m, s)
print(m)


Measured memory_bytes: 3064