akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    string s;
    cin>>s;
    Vec cnt(2);
    rep(i,s.length()){
        cnt[s[i]-'0']++;
    }
    ll ans = min(cnt[0],cnt[1])*2;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
int a;
cin >> a;
int ans = 0;
vector<int> b(a);
for(int i=0;i<a;i++){
  cin >> b[i];
}
for(int i=1;i<a-1;i++){
    if(b[i]>b[i-1]&&b[i]<b[i+1]){
      ans++;
    }else if(b[i]>b[i+1]&&b[i]<b[i-1]){
      ans++;
    }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
	int n,d[100000]={};
	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>d[i];
	}
	sort(d,d+n);
	int ans=d[n/2]-d[(n/2)-1];
	cout<<ans<<"\n";



	return 0;
}



Measured memory_bytes: 640
def print_array(A, N):
    for i in xrange(N - 1):
        print str(A[i]),

    print A[N - 1]


def bubbleSort(A, N):
    swap_num = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

    return swap_num


def main():
    N = int(raw_input())
    A = []

    for num in raw_input().split():
        A.append(int(num))

    temp = bubbleSort(A, N)
    print_array(A, N)

    print temp


if __name__ == "__main__":
    main()

Measured memory_bytes: 6448
class Cell:
    def __init__(self, x, y, num):
        self.x = x
        self.y = y
        self.num = num
        self.opened = False

    def open(self) -> None:
        self.opened = True

    def punch(self, called_number: int) -> None:
        if called_number == self.num:
            self.open()


class Line:
    """タテ・ヨコ・ナナメいずれかのライン"""

    def __init__(self, values):
        self.values = values

    def __post_init__(self):
        # 気分で書いたけど、今回はなくても良いと思う
        if len(self.values) != 3:
            raise ValueError('今回は3つ以外ありえないよ〜')

    def is_bingo(self) -> bool:
        return all([c.opened for c in self.values])


class Cells:
    """Boardって概念もあると思うけど、単純にCellのコレクションでいく"""

    def __init__(self, values):
        self.values = values

    def punch(self, called_numbers) -> None:
        for called_number in called_numbers:
            for cell in self.values:
                cell.punch(called_number)

    def has_one_more_bingo(self) -> bool:
        # タテ
        tate1 = Line([c for c in self.values if c.y == 1])
        tate2 = Line([c for c in self.values if c.y == 2])
        tate3 = Line([c for c in self.values if c.y == 3])

        # ヨコ
        yoko1 = Line([c for c in self.values if c.x == 1])
        yoko2 = Line([c for c in self.values if c.x == 2])
        yoko3 = Line([c for c in self.values if c.x == 3])

        # ナナメ
        # 左上から右下に向かってのナナメ(＼)
        diag1 = Line([c for c in self.values if c.x == c.y])

        # 右上から左下に向かってのナナメ(／)
        diag2 = Line([c for c in self.values if (((c.x, c.y) == (1, 3)) or
                                                 ((c.x, c.y) == (2, 2)) or
                                                 ((c.x, c.y) == (3, 1)))])

        return any([tate1.is_bingo(), tate2.is_bingo(), tate3.is_bingo(),
                    yoko1.is_bingo(), yoko2.is_bingo(), yoko3.is_bingo(),
                    diag1.is_bingo(), diag2.is_bingo()])

    @classmethod
    def create(cls, A):
        cells = []

        for row, line in enumerate(A, start=1):
            for col, num in enumerate(line, start=1):
                cell = Cell(x=row, y=col, num=num)
                cells.append(cell)

        return Cells(cells)


def actual(n, A, B):
    cells = Cells.create(A)

    cells.punch(B)

    if cells.has_one_more_bingo():
        return 'Yes'

    return 'No'

line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
line3 = list(map(int, input().split()))

A = [line1,
     line2,
     line3]

n = int(input())
B = []

for _ in range(n):
	b = int(input())
	B.append(b)
    

print(actual(n, A, B))

Measured memory_bytes: 3192
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000009
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
#define top(i,j) val[i*m+j]
typedef long long lli;
typedef unsigned short int usi;

int main()
{
    int n, a, b;
    scanf("%d %d %d",&n,&a,&b);
    int x = MIN(a,b);
    int y = MAX(a+b-n,0);
    printf("%d %d",x,y);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pa;

int main()
{
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    ll MIN=A[P-1], ans=0;
    if(V-P<=0){
        for(int i=0; i<N; i++){
            if(MIN<=A[i]+M) ans++;
        }
        cout << ans << endl;
        return 0;
    }

    ll R=N-1;
    ll tmp=A[R]+M;
    ll remain=(V-P)*M;
    bool ok=false;
    for(int i=N-1; i>=P-1; i--){
        if(i==R)continue;
        if(tmp<A[i]){
            ok=false;
            remain = 10;
            break;
        }
        ll r = tmp-A[i];
        if(r>=M) remain-=M;
        else remain-=r;
    }
    if(remain<=0) ok=true;
    if(ok){
        cout << N << endl;
        return 0;
    }
    ll L=P-1;
    while(R-L>=2){
        ll mid=(R+L)/2;
        tmp = A[mid]+M;
        ll remain=(V-P)*M;
        bool ok=false;
        for(int i=N-1; i>=P-1; i--){
            if(i==mid)continue;
            if(tmp<A[i]){
                ok=false;
                remain = 10;
                break;
            }
            ll r=tmp-A[i];
            if(r>=M) remain-=M;
            else{
                remain-=r;
            }
        }

        if(remain<=0) ok=true;
        if(ok) L=mid;
        else R=mid;
    }
    cout << L+1 << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];

    bool dp[k+1]={false};
     
    for(int l=0;l<=k;l++)
    {
    for(int i=0;i<n;i++)
    {
    if(a[i]<=l&&!dp[l-a[i]])
    {
    dp[l]=true;
    break;
    }
    }
    }

    if(dp[k]==true)
    cout<<"First";
    else
    cout<<"Second";  

    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vllp vector< pll >
#define F first
#define S second
#define MAX 1000000007
     
using namespace std;
     
int a[10000000]={1};
void sieve()
{
	for(int i=2;i*i<=10000000;++i)
	{
		if(a[i]==1)
		{
			for (int j=i*i;j<=10000000;j=j+i)
			{
				a[j]=0;
			}
		}
	}
}


int prime(int n)
{
    if(n==1||n==2)return 1;
    for(int i=2;i<=sqrt(n);++i)
    {
    	if(n%i==0){return 0;}
    }
    return 1;
}
     
ll mini(ll a,ll b)
{
    return a<b?a:b;
}
     
ll maxi(ll a,ll b)
{
    return a>b?a:b;
}
     
bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    if(a.first==b.first){return a.second>b.second;}
    else return a.first<b.first;
}

ll power(ll x,ll a)
{
	ll p=1;
	for (int i = 0; i < a; ++i)
	{
		p=p*x;
	}
	return p;
}


int main()
{
	
	ll n,W;
	cin>>n>>W;
	ll values[n+1]={0},weights[n+1]={0};

	for (int i = 1; i <=n; ++i)
	{
		cin>>weights[i]>>values[i];
	}

	ll knapsack[n+1][W+1]={0};

	for (int i=0;i<=n;++i)
	{
		for (int j=0;j<=W;++j)
		{
			if(i==0||j==0){knapsack[i][j]=0;continue;}
			if(weights[i]<=j)
			knapsack[i][j]=maxi(knapsack[i-1][j-weights[i]]+values[i],knapsack[i-1][j]);
			
			else
			{
				knapsack[i][j]=knapsack[i-1][j];	
			}		
		}
	}


	cout<<knapsack[n][W]<<endl;
	

	return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int di[] = {-1, 1, 0, 0}, dj[] = {0, 0, 1, -1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];

    VVI d(h, VI(w, -1));
    queue<P> que;
    REP(i,h) REP(j,w){
        if (s[i][j] == '#'){
            d[i][j] = 0;
            que.push(P(i, j));
        }
    }
    while (!que.empty()){
        P p = que.front();
        que.pop();
        int i = p.first, j = p.second;
        REP(k,4){
            int ii = i + di[k], jj = j + dj[k];
            if (ii < 0 || ii >= h || jj < 0 || jj >= w || d[ii][jj] != -1) continue;
            d[ii][jj] = d[i][j] + 1;
            que.push(P(ii, jj));
        }
    }
    int ans = 0;
    REP(i,h) REP(j,w) ans = max(ans, d[i][j]);
    cout << ans << endl;
    return 0;
}


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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  string s;
  cin >> s;
  if ( s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I' ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
   int x, i, j, t;
   x = A[r];
   i = p-1;
   for(j=p;j<r; j++){
      if( A[j] <= x){
         i++;
      t=A[i]; A[i]=A[j];A[j]=t;
      }
   }
   t=A[i+1];A[i+1]=A[r];A[r] = t;
   return i+1;
}

int main(){
   int i,q;

   scanf("%d", &n);
   for(i=0; i<n; i++) scanf("%d", &A[i]);

   q=partition(0, n-1);
   
   for(i=0; i<n; i++){
      if( i) printf(" ");
      if( i == q) printf("[");
      printf("%d", A[i]);
      if(i ==q) printf("]");
   }
   printf("\n");

   return 0;
}


Measured memory_bytes: 2172
#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-1); i >= 0; --i)

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    N %= 10;

    if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
        puts("hon");
    }
    if (N == 0 || N == 1 || N == 6 || N == 8) {
        puts("pon");
    }
    if (N == 3) {
        puts("bon");
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

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

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	int N,T; cin >> N >> T;
	V<int> a;
	REP(i,N){
		int c, t; cin >> c >> t;
		if (t <= T) a.push_back(c);
	}
	if(a.size()==0){
		cout << "TLE" << endl;
	}
	else{
		sort(ALL(a));
		cout << a[0] << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect

MOD = 998244353  # type: int

class BitIndexedTree(object):
    def __init__(self, N):
        self.V = [0] * N
        self.N = N
    
    def __getitem__(self, key):
        return self.sum(key, key+1)
    
    def __setitem__(self, key, value):
        diff = value - self[key]
        self.add(diff, key)

    def add(self, w, a):
        if w == 0:
            return
        x = a
        while x <= self.N:
            self.V[x-1] += w
            x += x & -x
    
    def sum(self, start=0, end=0):
        if end <= start:
            return 0
        if start > 0:
            return self.sum(0, end) - self.sum(0, start)
        x = end
        ret = 0
        while x > 0:
            ret += self.V[x-1]
            x -= x & -x
        return ret


def solve(N: int, P: "List[tuple]"):
    res = 0
    power = [1] * N
    for i in range(1, N):
        power[i] = power[i-1] * 2 % MOD

    P.sort(key=lambda x: x[1])
    for i, p in enumerate(P):
        p[1] = i
    
    P.sort()
    for i, p in enumerate(P):
        p[0] = i
    left = BitIndexedTree(N)
    right = BitIndexedTree(N)

    ll = [0] * N
    lg = [0] * N
    gl = [0] * N
    gg = [0] * N

    for i, p in enumerate(P):
        ll[i] = left.sum(0, p[1])
        lg[i] = i-ll[i]
        left.add(1, p[1]+1)

    for i, p in enumerate(P[::-1]):
        gl[-1-i] = right.sum(0, p[1])
        gg[-1-i] = i-gl[-1-i]
        right.add(1, p[1]+1)

    for a1, a2, a3, a4 in zip(gg, lg, ll, gl):
        b1 = power[a1]
        b2 = power[a2]
        b3 = power[a3]
        b4 = power[a4]

        res += (b1 - 1) * (b3 - 1) * b2 * b4
        res += (b2 - 1) * (b4 - 1) * b1 * b3

        res -= (b1 - 1) * (b2 - 1) * (b3 - 1) * (b4 - 1)

        res += power[N-1]

        res %= MOD
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [()] * (N)  # type: "List[tuple]" 
    for i in range(N):
        x = int(next(tokens))
        y = int(next(tokens))
        P[i] = [x, y]
    solve(N, P)

if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll K, T;
    cin >> K >> T;
    priority_queue<ll> A;
    REP(i,0,T) {
        ll a;
        cin >> a;
        A.push(a);
    }

    ll a = A.top(); A.pop();
    REP(i,0,K) {
        --a;
        if(a > 0 && SZ(A) > 0) {
            ll b = A.top(); A.pop();
            A.push(a);
            a = b;
        }
        else if(a == 0 && SZ(A) > 0) {
            ll b = A.top(); A.pop();
            a = b;
        }
        else if(SZ(A) == 0) {
            PR(a);
            break;
        }
    }
    

    return 0;
}

/*



*/

Measured memory_bytes: 3572
public class Main {
    public static void main(String[] args) {

        // ??????????????????????????????.
        java.util.Scanner sc = new java.util.Scanner(System.in);

        // ???????????????????????´??°??? 2 ???????????????.
        // ?????? 2 ?????¨??? 0 ????????????.
        while (true) {
            int count = 0;
            int n = sc.nextInt();
            int x = sc.nextInt();
            if (n == 0 && x == 0) { break; }

            // 1 ??\??? n ??\?????§?????? x ??¨?????? 3 ??????????????????????????°??????.
            for (int i = 1; i <= n; i ++) {
                for (int j = i + 1; j <= n; j ++) {
                    for (int k = j + 1; k <= n; k ++) {
                        if (i + j + k == x) { count ++; }
                    }
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 26684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int L=a+b, R=c+d;
	if(L>R) puts("Left");
	else if(L<R) puts("Right");
	else puts("Balanced");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, k, q;
    scanf("%d%d%d", &n, &k, &q);
    int a[q], p[100100] = {};
    for(int i = 0; i < q; i++) scanf("%d", &a[i]);
    
    for(int i = 0; i < q; i++) p[a[i]-1]++;
    for(int i = 0; i < n; i++) {
        if(k-(q-p[i]) <= 0) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

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

int main(){
  int N, Pe=0, Wh=0, Gr=0, Ye=0;
  string S, count;
  cin >> N;
  rep(i ,N){
    cin >> S;
    if(S == "P") Pe = 1;
    if(S == "W") Wh = 1;
    if(S == "G") Gr = 1;
    if(S == "Y") Ye = 1;
  }
  if(Pe + Wh + Gr + Ye == 3) count = "Three";
  else count = "Four";
  cout << count << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n):
    p[i] -= 1
ans = -float('inf')
for st in range(n):
    x = st
    score = []
    tot = 0
    while True:
        x = p[x]
        score.append(c[x])
        tot += c[x]
        if x == st:
            break
    l = len(score)
    now = 0
    t = 0
    for i in range(l):
        t += score[i]
        if i + 1 > k:
            break
        now = t
        if tot > 0:
            cycle_num = (k - (i + 1)) // l
            now += tot * cycle_num
        ans = max(ans, now)
print(ans)


Measured memory_bytes: 81160
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Hotel
// 2013/09/10
public class Main{
	Scanner sc=new Scanner(System.in);

	long B=1000000000L;

	int m, n;
	int[][] a;

	void run(){
		m=sc.nextInt();
		n=sc.nextInt();
		a=new int[n][m];
		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				a[j][i]=sc.nextInt();
			}
		}
		solve();
	}

	long[][] dp;

	void solve(){
		dp=new long[n][m];
		for(int i=0; i<n; i++){
			fill(dp[i], -1);
		}
		long min=Long.MAX_VALUE;
		for(int i=0; i<m; i++){
			min=min(min, rec(i, 0));
		}
		println(min/B+" "+min%B);
		int now=-1;
		for(int j=0; j<n; j++){
			int next=0;
			for(int i=0; i<m; i++){
				if(rec(i, j)+(i==now?0:1)<rec(next, j)+(next==now?0:1)){
					next=i;
				}
			}
			now=next;
			println(next+1+"");
		}
	}

	long rec(int i, int j){
		if(dp[j][i]>=0){
			return dp[j][i];
		}
		long min;
		if(j<n-1){
			min=Long.MAX_VALUE;
			for(int k=0; k<m; k++){
				min=min(min, rec(k, j+1)+(k==i?0:1));
			}
		}else{
			min=0;
		}
		return dp[j][i]=min+a[j][i]*B;
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 25832
import java.util.Scanner;

import static java.lang.System.in;

public final class Main {
	static Scanner sc = new Scanner(in);
	static final long MOD = 998244353;

	public static void main(String[] args) {
		int N = sc.nextInt();
		long[] comb = new long[N / 2 + 1];
		long[] cs = new long[comb.length];
		long[] css = new long[comb.length];
		comb[0] = 1;
		css[0] = cs[0] = comb[0];
		long pow2 = 1;
		for (int i = 1; i < comb.length; i++) {
			pow2 *= 2;
			pow2 %= MOD;
			comb[i] = comb[i - 1] * (N / 2 + 1 - i) % MOD;
			comb[i] *= inv(i);
			comb[i] %= MOD;
			cs[i] = comb[i] * pow2;
			cs[i] %= MOD;
			css[i] = (css[i - 1] + cs[i]) % MOD;
		}
		long invalid = 0;
		for (int i = 0; i < N / 2; i++) {
			invalid += cs[i] * css[N / 2 - 1 - i];
			invalid %= MOD;
		}
		invalid *= 2;
		invalid %= MOD;
		long ans = 1;
		for (int i = 0; i < N; i++) {
			ans *= 3;
			ans %= MOD;
		}
		ans += MOD - invalid;
		System.out.println(ans % MOD);
	}

	static long inv(long v) {
		return pow(v, MOD - 2);
	}

	static long pow(long b, long p) {
		if (p == 0) return 1;
		if (p == 1) return b;
		long ret = pow(b, p / 2);
		ret *= ret;
		ret %= MOD;
		if (p % 2 == 1) {
			ret *= b;
			ret %= MOD;
		}
		return ret;
	}
}


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

int main(void) 
{
  int w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;
  if(x >= r && y >= r && x <= w - r && y <= h - r) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}




Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  int N;cin>>N;
  ll A[N];
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  
  sort(A,A+N);
  ll median = A[N/2];
  ll med = A[N/2-1];
  ll a = median -med;
  
  cout << a;
  
}





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

typedef long long ll;
#define int ll

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    int k;
    cin>>s>>k;
    char p=0;
    vector<int> v;
    for(char&c:s)
    {
        if(c==p)
            v.back()++;
        else
            v.push_back(1);
        p=c;
    }
    int ans=0;
    if(s.front()!=s.back())
    {
        for(int x:v)
            ans+=x/2;
        ans*=k;
    }
    else if(v.size()==1)
        ans=v.front()*k/2;
    else
    {
        for(int x:v)
            ans+=x/2;
        ans-=v.front()/2+v.back()/2;
        ans*=k;
        ans+=v.front()/2+v.back()/2;
        ans+=(v.front()+v.back())/2*(k-1);
    }
    cout<<ans;
}


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

using namespace std;
using ll = long long;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

const long long MOD = 1e9+7;
const long long MAX = 3e5+1;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll N, K;
    in(N); in(K);
    vector<int> A(N);
    rep(i, N) {
        in(A[i]);
        A[i]--;
    }

    int idx = 0;
    ll cnt = 0;
    unordered_map<int, int> visited;
    visited[idx] = 0;
    rep(i, N+1) {
        cnt++;
        idx = A[idx];
        if (cnt == K || visited.find(idx) != visited.end()) break;
        visited[idx] = cnt;
    }
    if (cnt == K) {
        out(idx+1);
        exit(0);
    }
    K -= visited[idx];
    ll loop = cnt - visited[idx];
    K %= loop;
    rep(i, K) {
        idx = A[idx];
    }
    out(idx+1);

    return 0;
}


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

const int N = 21;

// 最高位代表其长度 1 << i -> 长度为 i 

int *dp[1 << N], tp[2][1 << N], fir[1 << N]; char s[1 << N];

int main() {
    int n, k; scanf("%d%d", &n, &k);
    dp[1] = new int[1 << n + 1], dp[1][0] = 0;
    for (int i = 1; i < 1 << n + 1; i++) fir[i] = fir[i >> 1] + 1;
    for (int i = 0; i <= n; i++) {
        scanf("%s", s); int base = 1 << i;
        for (int j = 0; j < base; j++) 
            dp[1][base | j] = s[j] - '0';
        int all = base - 1;
        for (int j = 0; j < base; j++) 
            tp[1][base | j] = j;
        tp[0][base * 2 - 1] = 0;
        for (int j = 0; j + 1 < base; j++) {
            int t = all ^ j, pos = fir[t]; 
            tp[0][base | j] = (1 << pos - 1) | (j & ((1 << pos - 1) - 1));
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        int base = 1 << i;
        for (int s = base - 1; s >= 0; s--) {
            dp[base + s] = new int[1 << n + 1 - i];
            for (int j = 0; j < (1 << n + 1 - i); j++) dp[base + s][j] = 0;
            for (int j = 1; j < 1 << (n + 1 - (i - 1)); j++) if (tp[s & 1][j])
                dp[base + s][tp[s & 1][j]] += dp[(base + s) >> 1][j];
            int tot = 0;
            for (int j = 1; j < (1 << n + 1 - i); j++) tot += dp[base + s][j];
            if (tot >= k) res = base + s;
        }
    }
    int len = fir[res];
    for (int i = len - 1; i >= 1; i--) {
        if (res & (1 << i - 1)) putchar('1');
        else putchar('0');
    }
    return 0;
}

Measured memory_bytes: 255872
a = 0

s = input()
sw = s+s

t = input()

l = [0 for i in range(len(t))]

for i in range(len(s)):
 if s[i] == t[0]:
  for j in range(len(t)):
   l[j] = sw[i+j]
  m = "".join(map(str, l)) 
  if m == t:
    print("Yes")
    a += 1
    break
if a == 0:
  print("No")


Measured memory_bytes: 5568
// AOJ 0549: A Traveler
// 2017.8.31 bal4u@uu
// 2018.1.18

#include <stdio.h>

#define M 100000

int s[100003];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		n = -n;
	} else {
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
	}
	return n;
}

int main()
{
	int n, m, i, p1, p2, x, ans;

	n = in(), m = in();
	s[1] = 0; for (i = 2; i <= n; i++) {
		s[i] = s[i-1] + in();
	}
	ans = 0, p1 = 1;
	while (m--) {
		p2 = p1 + in();
		x = s[p2] - s[p1]; if (x < 0) x = -x;
		ans = (ans + x) % M;
		p1 = p2;
	}
	printf("%d\n", ans);
	return 0;
}



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

int main(){
  int n,y;
  cin >> n>> y;
  int a,b,c;
  for(a=0;a<=n;a++){
    for(b=0;b<=n-a;b++){
      for(c=0;c<=n-a-b;c++){
        if(10000*a+5000*b+1000*c == y && a+b+c==n){cout << a << " " << b << " " << c << endl;
                                      return 0;}
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

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


int main(){

long long int a;cin>>a;
long long int b;cin>>b;

if(b!=1){
   long long  int t=a;
   long long  int sol=1;
    while(a<b){
        sol++;
        a=t-1+a;
    }
    cout<<sol<<endl;

}
else{
    cout<<0<<endl;
}
return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int a, b;
    cin >> a >> b;
    for (int c = 1; c <= 3; c++){
        if (a*b*c % 2 != 0){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3604
#include<stdio.h>

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


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

long long int N, a[114514], b, i;

int main(){
    scanf("%lld", &N);
    for(; i < N; ++i){
        scanf("%lld", &b);
        ++a[b];
        if(b)++a[b - 1];
        ++a[b + 1];
    }
    cout << *max_element(a, a + 114514) << endl;
    return 0;
}


Measured memory_bytes: 1024
from itertools import combinations, accumulate
n,m = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
ls = [0]*2001
for i in a:
  ls[i] += 1
accls = list(accumulate(ls))
for i,j in combinations(a,2):
  if i>j:
    ans += 1
ans = ans*m%mod
for i in range(1,2001):
  if ls[i]>=1:
    ans = (ans + ls[i]*accls[i-1]*m*(m-1)//2)%mod
print(ans)

Measured memory_bytes: 3188
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int count(int N)
{
        int cnt = 0;
        while (N)
        {
                cnt += N % 10;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int N, x;
        cin >> N >> x;
        vector<int> a(N + 1);
        rep(i, N) cin >> a[i];
        sort(a.begin(), a.begin() + N);
        // rep(i,  N)
        // {
        //         cout << a[i] << ' ';
        // }
        // cout << endl;

        ll ans = 0;
        rep(i, N - 1)
        {
                if (x >= a[i])
                {
                        x -= a[i];
                        ans++;
                }
                else
                {
                        break;
                }
        }
        if (x == a[N - 1])
        {
                ans++;
        }

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


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

int n, ans = 0;
vector<int> a;

void solve(int l, int r);

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  solve(0, n);
  for(int i = 0; i < n; ++i) {
    if(i != 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << ans << endl;
  return 0;
}

void solve(int l, int r) {
  if(r - l <= 1) return;
  solve(l, (l + r) / 2);
  solve((l + r) / 2, r);
  vector<int> dummy(r - l, 0);
  int lid = l, rid = (l + r) / 2, half = (l + r) / 2;
  for(int i = 0; i < r - l; ++i) {
    ++ans;
    if(lid < half && rid < r) {
      if(a[lid] < a[rid])
        dummy[i] = a[lid++];
      else
        dummy[i] = a[rid++];
    }
    else if(lid < half)
      dummy[i] = a[lid++];
    else
      dummy[i] = a[rid++];
  }
  for(int i = 0; i < r - l; ++i) a[l + i] = dummy[i];
}


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

int main() {

	int x[3],i,j,k;

	for (i = 0; i < 3; i++) {
		cin >> x[i];
	}

	for (i = 0; i < 3; i++) {
		for (j = 0; j < 2; j++) {
			if (x[j] < x[j + 1]) {
				k = x[j];
				x[j] = x[j + 1];
				x[j + 1] = k;
			}
		}
	}
	
	cout << x[0] - x[1] + x[1] - x[2];

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int T,card[16];

bool is_same_number(int a,int b,int c){
	if(a==b&&b==c)return true;
	return false;
}
bool is_sequence(int a,int b,int c){
	if(a+2==b+1&&b+1==c)return true;
	return false;
}
bool is_good_set(int a,int b,int c){
	return is_same_number(a,b,c)||is_sequence(a,b,c);
}

bool is_all_good_set(){
	return is_good_set(card[0],card[1],card[2])
			&&is_good_set(card[3],card[4],card[5])
			&&is_good_set(card[6],card[7],card[8]);
}

int win(){
	sort(card,card+9);
	do{
		if(is_all_good_set())return 1;
	}while(next_permutation(card,card+9));
	return 0;
}

int main(){
	cin >>T;
	for (int t = 0; t < T; ++t){
		for (int i = 0; i < 9; ++i){
			cin>>card[i];
		}
		string color;
		for (int i = 0; i < 9; ++i){
			cin>>color;
			if(color=="G")card[i]+=10;
			else if(color=="B")card[i]+=20;
		}
		cout<<win()<<endl;
	}
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	int n,count=0;
	double BMI,w,h;
	char x,y;
	while(true){
		cin>>n>>x>>w>>y>>h;
		if (cin.eof())break;
		BMI=w/(h*h);
		if(BMI>=25){
			cout<<n<<endl;
			count++;
		}
	}
}

Measured memory_bytes: 3204
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	int n, l[1010], r[1010], wa = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
	    cin >> l[i] >> r[i];
	    wa = wa + r[i] - l[i] + 1;
	}
	cout << wa;
	return 0;
}


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

int main(){ 
  int n;
  cin >> n;
  int res = 1e9;
  for (int a = 1; a < n; a++) {
    int b = n - a;
    string sa = to_string(a), sb = to_string(b);
    int sum = 0;
    for (int i = 0; i < sz(sa); i++) sum += sa[i] - '0';
    for (int i = 0; i < sz(sb); i++) sum += sb[i] - '0';
    res = min(res, sum);
  }
  cout << res << endl;
  return 0;
} 

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

ll gcd(ll a, ll b){
    if(b==0) return a;
    else return gcd(b, a%b);
}
int main(){
    ll n, x; cin >> n >> x;
    vector<ll> p;
    for(int i=0; i<n; i++){
        ll tmp=0;
        cin >> tmp;
        p.push_back(tmp);
    }
    p.push_back(x);
    sort(p.begin(), p.end());
    ll p_size = n + 1;
    vector<ll> dis;
    for(int i=0; i<p_size-1; i++){
        dis.push_back(p[i+1]-p[i]);
    }
    sort(dis.begin(), dis.end());

    ll el = gcd(dis[0], dis[1]);
    for(int i=2; i<p_size-1; i++){
        el = gcd(el, dis[i]);
    }
    cout << el << endl;
    return 0;
}

Measured memory_bytes: 5616
//
// LCA (by Doubling)
//
// verified:
//   AOJ Course GRL_5_C Tree - Lowest Common Ancestor
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C&lang=jp
//


#include <iostream>
#include <vector>
using namespace std;


using Graph = vector<vector<int> >;
struct LCA {
    vector<vector<int> > parent; // parent[d][v] := 2^d-th parent of v
    vector<int> depth;
    LCA() { }
    LCA(const Graph &G, int r = 0) { init(G, r); }
    void init(const Graph &G, int r = 0) {
        int V = (int)G.size();
        int h = 1;
        while ((1<<h) < V) ++h;
        parent.assign(h, vector<int>(V, -1));
        depth.assign(V, -1);
        dfs(G, r, -1, 0);
        for (int i = 0; i+1 < (int)parent.size(); ++i)
            for (int v = 0; v < V; ++v)
                if (parent[i][v] != -1)
                    parent[i+1][v] = parent[i][parent[i][v]];
    }
    void dfs(const Graph &G, int v, int p, int d) {
        parent[0][v] = p;
        depth[v] = d;
        for (auto e : G[v]) if (e != p) dfs(G, e, v, d+1);
    }
    int get(int u, int v) {
        if (depth[u] > depth[v]) swap(u, v);
        for (int i = 0; i < (int)parent.size(); ++i)
            if ( (depth[v] - depth[u]) & (1<<i) )
                v = parent[i][v];
        if (u == v) return u;
        for (int i = (int)parent.size()-1; i >= 0; --i) {
            if (parent[i][u] != parent[i][v]) {
                u = parent[i][u];
                v = parent[i][v];
            }
        }
        return parent[0][u];
    }
};



int main() {
    int N; cin >> N;
    Graph G(N);
    for (int i = 0; i < N; ++i) {
        int num; cin >> num;
        for (int j = 0; j < num; ++j) {
            int c; cin >> c;
            G[i].push_back(c);
            G[c].push_back(i);
        }
    }
    LCA lca(G);
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int u, v; cin >> u >> v;
        cout << lca.get(u, v) << endl;
    }
}



Measured memory_bytes: 18132
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[110][200000];
int main(){
int n,W;
cin>>n>>W;
vector<ll> w(n),v(n);
for(int i=0;i<n;i++)cin>>w.at(i)>>v.at(i);
for(int i=n-1;i>=0;i--){
    for(int j=0;j<=W;j++){
        if(j>=w.at(i)){
            dp[i][j]=max(dp[i+1][j],dp[i+1][j-w.at(i)]+v.at(i));
        }
        else  dp[i][j]=dp[i+1][j];
    }
}
cout<<dp[0][W]<<endl;
}

Measured memory_bytes: 155136
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)

#define vll    vector<ll>
#define vvll   vector<vector<ll>>
#define all(x) (x).begin(),(x).end()

int main()
{	
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;

	vector<ll> p(A);
	rep(i, A) cin >> p[i];

	vector<ll> q(B);
	rep(i, B) cin >> q[i];

	priority_queue<ll> r;
	rep(i, C)
	{
		ll tmp;
		cin >> tmp;
		r.push(tmp);
	}


	//pの大きい方からX個、qの大きい方からY個とって降順に並べる
	sort(all(p), greater<ll>());
	sort(all(q), greater<ll>());
	
	priority_queue<ll, vector<ll>, greater<ll>> pq;

	rep(i, X) pq.push(p[i]);
	rep(i, Y) pq.push(q[i]);


	//貪欲法で小さい方から処理（大きいりんごを残した方が有利）
	ll ans = 0;
	
	while (!pq.empty())
	{
		auto x = pq.top(); pq.pop();

		if (!r.empty() && x < r.top())
		{
			x = r.top(); r.pop();
		}

		ans += x;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4724
n,*as=$<.read.split.map &:to_i
if n.odd?
  t=0
  s=[]
  (n/2).downto(0){|i|
     s[i]=t+=as[i*2]
  }
  y=[as[n-2],as[n-1]].max
  x=[as[n-3],y].max
  b=n-3
  while 0<=b-=2 
    y=[as[b+1]+y,s[b/2+1]].max
    x=[as[b]+x,y].max
  end
  puts x
else
  t=0
  s=[]
  (n/2-1).downto(0){|i|
     s[i]=t+=as[i*2+1]
  }
  x=[as[n-2],as[n-1]].max
  b=n-2
  while 0<=b-=2 
    x=[as[b]+x,s[b/2]].max
  end
  puts x
end


Measured memory_bytes: 30504
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

now = 1
visited = []
visited_set = set()
flag = False

for i in range(1, K+1):
    visited.append(now)
    visited_set.add(now)
    now = A[now]
    if now in visited_set:
        loop_start = visited.index(now)
        loop_length = i - loop_start
        flag = True
        break
else:
    print(now)

if flag:
    print(visited[loop_start + (K - loop_start) % loop_length])


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

using namespace std;

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define INF 0x3f3f3f3f
#define f1(n) for(int i=0 ; i<n ; i++)
#define f2(m) for(int j=0 ; j<m ; j++)
#define ll long long
typedef pair<int, int> iPair;
const double epsilon = 1e-7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  char c;
  cin >> c;
  if (c >= 'a' and c <= 'z')
    cout << "a" << endl;
  else cout << "A" << endl;
  return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 998244353;
const int maxn = 262144;

int n, q;
int pw[maxn]; 

class SegmentTree{
private:
	static const int siz = 262144;
	int dat[siz << 1], tag[siz << 1], bas[siz << 1];
public:
	inline int size(){ return siz; }
	inline void init(int x, int l, int r){
		tag[x] = 0;
		if(l == r){
			dat[x] = (l < n ? 1 * pw[l] : 0);
			bas[x] = 1 * pw[l];
			return;
		}
		int md = l + r >> 1;
		init(x << 1, l, md);
		init(x << 1 | 1, md + 1, r);
		dat[x] = (dat[x << 1] + dat[x << 1 | 1]) % INF;
		bas[x] = (bas[x << 1] + bas[x << 1 | 1]) % INF;
		return;
	}
	inline void pushDown(int x){
		if(tag[x]){
			tag[x << 1] = tag[x << 1 | 1] = tag[x];
			dat[x << 1] = 1ll * tag[x] * bas[x << 1] % INF;
			dat[x << 1 | 1] = 1ll * tag[x] * bas[x << 1 | 1] % INF;
			tag[x] = 0;
		}
		return;
	}
	inline void update(int x, int l, int r, int s, int t, int k){
		if(l >= s && r <= t){
			dat[x] = 1ll * k * bas[x] % INF;
			tag[x] = k;
			return;
		}
		int md = l + r >> 1;
		pushDown(x);
		if(s <= md)
			update(x << 1, l, md, s, t, k);
		if(t > md)
			update(x << 1 | 1, md + 1, r, s, t, k);
		dat[x] = (dat[x << 1] + dat[x << 1 | 1]) % INF;
		return;
	}
	inline int query(){ return dat[1]; }
}seg;

int main(){
	scanf("%d%d", &n, &q);
	pw[0] = 1;
	FOR(i, 1, maxn)
		pw[i] = 1ll * pw[i - 1] * 10 % INF;
	seg.init(1, 0, seg.size() - 1);
	FOR(i, 0, q){
		int l, r, k; scanf("%d%d%d", &l, &r, &k);
		l = n - l; r = n - r;
		swap(l, r);
		seg.update(1, 0, seg.size() - 1, l, r, k);
		printf("%d\n", seg.query());
	}
	return 0;
}


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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<bool> done(N);
  vector<int> wa(N);
  ll ac = 0;
  for (int i = 0; i < M; i++) {
    int p; cin >> p; p--;
    string s; cin >> s;
    if (done.at(p)) continue;
    if (s == "WA") {
      wa.at(p)++;
    }else if (s == "AC") {
      ac++;
      done.at(p) = true;
    }else {
      assert(false);
    }
  }
  ll nwa = 0;
  for (ll i = 0; i < N; i++) {
    if (done.at(i)) nwa += wa.at(i);
  }
  cout << ac << " " << nwa << endl;

  return 0;
}



Measured memory_bytes: 640
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/



void solve() {
	string n; cin >> n;
	int x = 0;
	for (char i : n)
		x += ((int)(i - '0'));
	if (x % 9 == 0) cout << "Yes\n";
	else cout << "No\n";
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 3744