akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, C = -1;
vector<vector<int>> graph(100001);
bitset<100001> bit;
vector<int> cnt(100001, 0);
vector<int> root(100001, 0);

int rec(int corrent = 1, int count = 0){
    if(C == -1){
        root[count] = corrent;
        if(corrent == N) C = count;
    }
    for(int i = 0; i < graph[corrent].size(); ++i){
        int next = graph[corrent][i];
        if(!bit[next]){
            bit[next] = true;
            cnt[corrent] += rec(next, count + 1);
        }
    }
    return (cnt[corrent]) ? cnt[corrent] + 1 : 1;
}

int main(void){
	
	scanf("%d", &N);
	for(int i = 0; i < N - 1; ++i){
	    int a, b; scanf("%d %d", &a, &b);
	    graph[a].push_back(b), graph[b].push_back(a);
	}
	
	bit[1] = true;
    rec();
    
    int black = 0;
    for(int i = 0; i <= C / 2; ++i){
        int a = cnt[root[i]] + 1, b = cnt[root[i + 1]] + 1;
        black += (a >= b) ? a - b : 0;
    }
    int white = cnt[root[C / 2 + 1]] + 1;
    
    if(black > white) printf("Fennec\n");
    else printf("Snuke\n");
    
    return 0;
}


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

//const int M[6]= {};

const int maxn = 2e5+10;

int f[maxn];


int dp(int x) {
	if (x == 0) return 1;
	if (x < 0) return 0;
	
	if (f[x] != -1) return f[x];
	
	int res = 0;
	
	for(int i=0;i<6;i++) {
		res |= dp(x - 100 - i);	
	}
	
	f[x] = res;
	return res;
}

int main() {
//	freopen("inp.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = 0;
	cin >> n;
	memset(f, -1, sizeof(f));
	cout << dp(n);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N=2e5+10;
int n,an,bn;
ll k,a[N],b[N],l,r,ans;
inline ll check(ll x)
{
	ll tot=0;
	int l=0,r=0;
	if(x>0)
    {
		tot=1LL*an*bn;
		r=bn;
		fup(l,1,bn)
		{
			while(l<r&&b[l]*b[r]>=x)
				--r;
			if(l==r)break;
			tot+=r-l;
		}
		l=1;
		fdw(r,an,1)
		{
			while(l<r&&a[l]*a[r]>=x)
				++l;
			if(l==r)break;
			tot+=r-l;
		}
	}
	else
    {
		r=1;
		fup(l,1,an)
		{
			while(r<=bn&&a[l]*b[r]>=x)
				++r;
			if(r>bn)break;
			tot+=bn-r+1;
		}
	}
	return tot;
}
int main()
{
	sync;
	cin>>n>>k;
	fup(i,1,n)
		cin>>a[i];
	sort(a+1,a+n+1);
	while(an<n&&a[an+1]<0)
		++an;
	for(int i=an+1;i<=n;i++)
		b[++bn]=a[i];
	l=-1e18-1,r=1e18+1;
	while(l<r)
    {
		ll mid=(l+r)>>1;
		if(check(mid)<k)
			ans=mid,l=mid+1;
		else
			r=mid;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
using namespace std;
int main()
{
    int n,x,l[100+5],sum=0,ans=1;
    scanf("%d %d",&n,&x);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&l[i]);
        sum+=l[i];
        if(sum<=x)
            ans++;

    }
    printf("%d\n",ans);

    return 0;

}


Measured memory_bytes: 128
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;
  cin>>s;
  ll dp[s.size()][13];
  rep(i,s.size()) rep(j,13) dp[i][j]=0;
  if(s[0]=='?') rep(i,10) dp[0][i]=1;
  else dp[0][s[0]-'0']=1;
  rep(i,s.size()-1){
    if(s[i+1]=='?'){
      rep(j,13){
        rep(k,10){
          dp[i+1][(10*j+k)%13]+=dp[i][j];
          dp[i+1][(10*j+k)%13]%=MOD;
        }
      }
    }else{
      rep(j,13){
        dp[i+1][(10*j+(s[i+1]-'0'))%13]+=dp[i][j];
        dp[i+1][(10*j+(s[i+1]-'0'))%13]%=MOD;
      }
    }
  }
  cout<<dp[s.size()-1][5]<<endl;
}

Measured memory_bytes: 10704
import sys
while True:
  a=int(input())
  if a==0: break
  soug,tt,te=[0]*a,[],0
  for i in range(a):
    hoge=map(int,raw_input().split())
    te=0
    for j in range(a):
      te+=hoge[j]
      soug[j]+=hoge[j]
      sys.stdout.write("%5d"%hoge[j])
    else: sys.stdout.write("%5d"%te) ; print""
  else:
    te=0
    for i in range(a):
      sys.stdout.write("%5d"%soug[i])
      te+=soug[i]
    else: sys.stdout.write("%5d"%te)   ; print""

Measured memory_bytes: 5216
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int n,k;cin>>n>>k;
if(n%k==0) cout<<0;
else cout<<1;




return 0;
}


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

/*s[i]ツつゥツづァツ督ッツつカツ閉カツ篠堋つェツ連ツ堕アツつオツづつ「ツづゥツ青板づーツ陛板つキ*/
int seqlen(string &s,int i){
	char c = s[i];
	int ret=0;
	while(s[i++]==c)ret++;
	return ret;
}

int main(){
	int n;
	int flag = 0;
	string s;
	cin >> n;
	while(n--){
		flag = 0;
		cin >> s;
		/*A*/
		if(s[0]=='>' && s[1]==39){
			int x=2;
			x += seqlen(s,x);
			if(s[x]!='#')flag = 1;
			x ++ ;
			if(seqlen(s,2) != seqlen(s,x))flag = 1;
			x += seqlen(s,x);
			if(s[x]!='~')flag = 1;
			if(!flag)flag='A';
		}
		else if(s[0]=='>' && s[1]=='^'){
			int pointa = 0;
			for(int i=2;i<s.length()-2;i++){
				if(i%2){
					if(s[i] != '=')flag = 1;
					else pointa++;
				}else{
					if(s[i] != 'Q')flag = 1;
					else pointa++;
				}
			}
			if(s[s.length()-2] != '~' || s[s.length()-1] != '~')flag = 1;
			if(!flag && pointa>=2)flag='B';
			else flag = 1;
		}
		else {flag = 1;}
		
		if(flag != 1)cout << (char)flag << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

const int m = 100;

int main() {
	int h;
	int w;
	int n;
	int c[m * m] = {};
	int b[m][m];

	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}

	int x = 0;
	for (int i = 0; i < h; i++) {
		int s = i % 2 == 0 ? 0 : w - 1;
		int f = i % 2 == 0 ? w : -1;
		int d = i % 2 == 0 ? +1 : -1;

		for (int j = s; j != f; j += d) {
			b[i][j] = (x + 1);

			c[x]--;
			if (!c[x]) {
				x++;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << b[i][j] << (j == w - 1 ? "\n" : " ");
		}
	}

	return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer arr[] = new Integer[n];
        for(int i=0; i<n; i++){
           arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        long sum=0;
        for(int i=0; i<n-k; i++){
            sum += arr[i];
        }

        out.println(sum);
    }
    private static boolean isprime(int x){
        if(x==2)
            return true;
        int sqs = (int)Math.sqrt(x);
        for(int i=2; i<=sqs; i++){
            if(x%i==0)
                return false;
        }
        return true;
    }

    private static int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd (b, a % b);
    }
    private static long helper(long x){
        long ans = (x * (x-1))/2;
        return ans;
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair {
    int x;
    long y;

    Pair(int x, long y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        Pair pair = (Pair) o;
        return this.x < pair.x && this.y==pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}

Measured memory_bytes: 53536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main
{
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int hight[];
		hight = new int[10];
		for(int i = 0; i < 10; i++){
			hight[i] = Integer.parseInt(br.readLine());
		}
		Arrays.sort(hight);
		for(int i = 0; i < 3; i++){
			System.out.println(hight[9 - i]);
		}
	}
}

Measured memory_bytes: 24316
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n"
#define CNO cout << "No" \
                 << "\n"
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

int main()
{
    vector<vector<pair<int, bool>>> v(3, vector<pair<int, bool>>(3));
    for (size_t i = 0; i < 3; i++)
    {
        for (size_t j = 0; j < 3; j++)
        {
            int a;
            cin >> a;
            v[i][j] = {a, false};
        }
    }
    int n;
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        for (size_t j = 0; j < 3; j++)
        {
            for (size_t k = 0; k < 3; k++)
            {
                if (b == v[j][k].first)
                {
                    v[j][k].second = true;
                }
            }
        }
    }


    for (size_t i = 0; i < 3; i++)
    {
        vector<bool> f(3, false);
        for (size_t j = 0; j < 3; j++)
        {
            if (v[i][j].second)
                f[j] = true;
        }
        if (f[0] && f[1] && f[2]) {
            cout << "Yes" << "\n";
            return 0;
        }
    }

    for (size_t i = 0; i < 3; i++)
    {
        vector<bool> f(3, false);
        for (size_t j = 0; j < 3; j++)
        {
            if (v[j][i].second)
                f[j] = true;
        }
        if (f[0] && f[1] && f[2]) {
            cout << "Yes" << "\n";
            return 0;
        }
    }

    if (v[0][0].second && v[1][1].second && v[2][2].second) {
        cout << "Yes" << "\n";
        return 0;
    }
    if (v[2][0].second && v[1][1].second && v[0][2].second) {
        cout << "Yes" << "\n";
        return 0;
    }
    cout << "No" << "\n";
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    S = input()
    print('x'*len(S))



main()


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

int main() {
    vector<int> n(4);
    rep(i, 4) {
        cin >> n.at(i);
    } 
   sort(n.begin(), n.end());

   string s="1479";

   rep(i, 4) {
       if (s.at(i)-'0' != n.at(i)) {
           puts("NO");
           return 0;
       }
   }
   puts("YES");
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		while(stdIn.hasNext()) {
			int num = stdIn.nextInt();
			int numClone = num;
			for(int r = 0; r < 10; r++) {
				if(((num >> r) & 1) == 1) {
					int pow = (int)Math.pow(2, r);
					if(num - pow < 0) break;
					System.out.print(pow);
					numClone -= pow;
					if(r != 9 && numClone != 0) System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 17220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
vector<int> x(10),y(10);

double dis(int i,int j){
    double dx = x.at(i) - x.at(j);
    double dy = y.at(i) - y.at(j);
    return pow(dx * dx + dy * dy, 0.5);
}
int conb(int x){
    int a=1;
    for(int i=1;i<=x;i++){
        a *= i;
    }
    return a;
}

int main(){
    cin >> n;
    int p = conb(n);
    double sum =0.0;
    for(int i=0;i<n;i++){
        cin >> x.at(i) >> y.at(i);
    }
    vector<int> v(n);
    for(int i=0;i<n;i++) v.at(i) = i;
    do{
        for(int i=0;i<n-1;i++){    
            sum += dis(v.at(i),v.at(i+1));
            //cout << sum << endl;
        }
    }while(next_permutation(v.begin(),v.end()));

    //cout << sum << " " << p << endl;
    cout <<fixed<<setprecision(10)<< sum / double(p) << endl;

}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, A; cin >> N >> A;
    cout << ((N % 500 <= A) ? "Yes" : "No") << '\n';
}

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

    solve();

    return 0;
}

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

long gcd(long a, long b){
	if (a % b == 0){
		return b;
	}
	else {
		return (gcd(b, a%b));
	}
}
long lcm(long a, long b){
	long gc = gcd(a,b);
	long x = a*b;
	x = x / gc;
	return x;

}

int main(){
	long a,b;
	while (cin >> a >> b){
		long gc = 0;
		if (a >= b){
			gc = gcd(a, b);
		}
		else{
			gc = gcd(b,a);
		}
		long lc = 0;
		if (a >= b){
			lc = lcm(a, b);
		}
		else{
			lc = lcm(b,a);
		}
		cout << gc << " " << lc << endl;

		

	}



	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>
#include <vector>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
typedef pair<int, int> pii;

int const dx[] = { 1, 0, -1, 0 };
int const dy[] = { 0, 1, 0, -1 };

int main(){
    int n;
    while (cin >> n && n){
        pii m[500];
        m[0] = pii(0, 0);
        rep(i, n-1){
            int k, d;
            cin >> k >> d;
            pii p = m[k];
            p.first += dx[d];
            p.second += dy[d];
            m[i + 1] = p;
        }
        int mx = 500, my = 500, Mx = -500, My = -500;
        rep(i, n){
            pii& p = m[i];
            mx = min(p.first, mx);
            my = min(p.second, my);
            Mx = max(p.first, Mx);
            My = max(p.second, My);
        }
        cout << Mx - mx + 1 << " " << My - my + 1 << endl;
    }
}

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

using namespace std;

int main(){
string S; cin >> S;  int k = S.size(); int cnt =0;

for(int j = 0; j < k ; j++){
 if(S[j] == 'o'){ cnt++;}}

if( 15 - k + cnt >= 8){ cout << "YES" << endl;}
else{ cout <<"NO" << endl;} return 0;}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main(){
  int i,j,s,t,n[10000],q[500],cnt=0;
  scanf("%d",&s);
  for(i=0;i<s;i++){
    scanf("%d",&n[i]);
  }
  scanf("%d",&t);
  for(i=0;i<t;i++){
    scanf("%d",&q[i]);
    //printf("%d ",q[s]);
  }
  for(j=0;j<t;j++){
    for(i=0;i<s;i++)
      if (q[j]== n[i]) {cnt++;//printf("%d %d / %d %d\n",n[i],i,q[j],j);
	break;}
  }
  printf("%d\n",cnt);

  
  
}



Measured memory_bytes: 2052
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main()
{
	ll N;
	ll ans = 0;
	cin >> N;
	rep(i, N)
	{
		ans += i + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 998244353
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        if(p1.first!=p2.first)return p1.first<p2.first;
        else return p1.second<p2.second;
    }
}; 

int main(){
    fio;
    ll n;cin>>n;
    if(n%1000==0)cout<<0<<endl;
    else cout<<1000-n%1000<<endl;
}


Measured memory_bytes: 3648
object Main extends App {
  val n = io.StdIn.readLine.toInt
  val ans = Iterator.continually(io.StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray.par
    .map(in => {
      val Array(t, x, y) = in
      if ((x + y > t) || ((t-x-y) & 1) == 1) false else true
    })
    .takeWhile(_ == true)
    .size

  println(if (ans == n) "Yes" else "No")
}

Measured memory_bytes: 60224
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Question question = new Question();
        question.solve(sc);
    }

    static class Question {
        public void solve(Scanner sc) {
            int len = sc.nextInt();
            int n = sc.nextInt();
            int[] distances = new int[n];
            for (int i = 0; i < n; ++i) {
                distances[i] = sc.nextInt();
            }
            int m = 0;
            for (int i = 0; i < n; ++i) {
                int t = (i + 1) % n;
                int dist = distances[t] - distances[i];
                m = Math.max(m, Math.min(Math.abs(dist), len - Math.abs(dist)));
            }
            System.out.println(len - m);
        }
    }
}


Measured memory_bytes: 65476
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt() , a = s.nextInt();
        if( n % 500 == 0 || n % 500 <= a ) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


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

const int p=1000000007;

int N;
int f[5005];
int lnk[5005];
int pre[100005],tgt[100005],cnt;
void add_E(int u,int v){
	pre[++cnt]=lnk[u],tgt[cnt]=v,lnk[u]=cnt;
}
int g[5005][5005];int tmp[5005];
int siz[5005];
void Solve(int x,int fa){
	siz[x]=1;g[x][1]=1;
	for(int e=lnk[x];e;e=pre[e])if(tgt[e]!=fa){
		int y=tgt[e];
		Solve(y,x);
		for(int i=1;i<=siz[x]+siz[y];i++) tmp[i]=0;
		for(int i=1;i<=siz[x];i++)
		for(int j=1;j<=siz[y];j++)
			tmp[i]=(tmp[i]-1LL*g[x][i]*g[y][j]%p*f[j]%p+p)%p,
			tmp[i+j]=(tmp[i+j]+1LL*g[x][i]*g[y][j]%p)%p;
		for(int i=1;i<=siz[x]+siz[y];i++)
			g[x][i]=tmp[i];
		siz[x]+=siz[y];	
	}
}

int main(){
	scanf("%d",&N);
	f[0]=1;
	for(int i=2;i<=N;i+=2) f[i]=1LL*f[i-2]*(i-1)%p;
	for(int i=1;i<N;i++){
		int u,v;scanf("%d%d",&u,&v);
		add_E(u,v);add_E(v,u);
	}
	Solve(1,0);
	int ans=0;
	for(int i=2;i<=N;i+=2) ans=(ans+1LL*g[1][i]*f[i]%p)%p;
	printf("%d\n",ans);
}

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

int main() {
  int N;
  cin >> N ;
  
  for (int i = 0; i < N; i++){
    string S;
    cin >> S;
    
    if (S == "Y"){
      cout << "Four" << endl;
      break;
    }
      
    else if (i == N-1){  
      cout << "Three" << endl;
    }
    
    else{
       continue;
    }
    
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int n, k;
vector<int> a;
bool solve(vector<int> &ret){
	int p = -1;
	for(int _=0;_<=k;_++){
		int mi = 10000;
		int maki = -1;
		for(int i=0;i<n;i++){
			if(i == p) continue;
			if(mi >= a[i]) mi = a[i], maki = i;
		}
		for(int i=0;i<n;i++){
			if(i == p || i == maki) continue;
			ret.pb(i+1);
			a[i]--;
			if(a[i] < 0) return false;
		}
		ret.pb(maki + 1);
		a[maki]--;
		if(a[maki] < 0) return false;
		p = maki;
	}
	return true;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<int> ret;
    if(!solve(ret)) cout << -1 << endl;
    else{
    	cout << ret.size() << endl;
    	for(auto& i: ret) cout << i << " ";
    	cout << endl;
    } 
    return 0;
}



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

const int MAX = 2000, MOD = 1e9+7;
long long fac[MAX], finv[MAX], inv[MAX];

void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long com(int n, int k) {
  if (n < k || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  init();

  for (int i = 1; i <= K; i++) cout << com(N - K + 1, i) * com(K - 1, i - 1) % MOD << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
//#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


const ll MOD=1e9+7;
const int N=500000;
ll modpow(ll x,ll n,ll mod){
    ll ret=1;
    while(n){
        if(n&1) ret=ret*x%mod;
        x=x*x%mod; n>>=1;
    }
    return ret;
}
ll sum(ll a,ll r,ll n,ll mod){
    if(n==0)return 0;
    if(n==1) return a%mod;
    ll x=sum(a,r,n/2,mod);
    ll ret=(x+modpow(r,n/2,mod)*x%mod)%mod;
    if(n&1) ret=(a+r*ret%mod)%mod;
    return ret;
}
ll sum2(ll a,ll r,ll n,ll mod){
    if(n==0)return 0;
    if(n==1) return 0;
    if(n&1){
        return (sum2(a,r,n-1,mod)+sum(a,r,n-1,mod))%mod;
    }
    ll x=sum2(a,r,n/2,mod);
    // cout<<r<<" "<<n<<" "<<x<<endl;
    x=(x*(modpow(r,n/2,mod)+1ll)%mod+(n/2ll)%mod*sum(a,r,n/2,mod)%mod)%mod;
    // cout<<r<<" "<<n<<" "<<x<<endl;
    return x;
}

main(){
    ll l,a,b;
    cin>>l>>a>>b;
    ll m=lin();
    ll res=0,keta=1;
    ll ans=0;
    ll now=10;
    while(now<=(ll)1e18){
        ll next=(now-1-a)/b;
        if(next>l-1)next=l-1;
        if(next*b>=now-a){
            keta++;now*=10;
            continue;
        }
        ll cnt=next-res+1;
        ll A=(a%m+(res%m)*(b%m)%m)%m,B=b%m;
        ll s=keta,t=cnt;
        ll T=modpow(10,s,m);
        ans=ans*modpow(T,t,m)%m;
        ans=(ans+A*sum(1,T,t,m)%m)%m;
        // cout<<ans<<" ";
        ans=(ans+B*sum2(1,T,t,m)%m)%m;
        // cout<<ans<<endl;
        keta++;
        if(now==1e18)break;
        now*=10;
        res=next+1;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int n,ans=0;
    cin >> n;
    if(n/1000==2)ans++;
    if((n/100)%10==2)ans++;
    if((n/10)%10==2)ans++;
    if(n%10==2)ans++;
    cout << ans << endl;
}

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

int main(){
   int n;
   int b[4]={0};
   for(int i=0;i<6;i++){
      cin >> n;
      b[n-1]++;
   }
   int odd=0;
   for(int i=0;i<4;i++){
      if(b[i]%2==1){
         odd++;
      }
   }
   cout << (odd==2?"YES":"NO");
   return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split(' '))
S = input()

b = '1'

l = []
c = 0
for s in S:
	if b == s:
		c = c + 1
	else:
		l.append(c)
		c = 1
		b = '1' if b == '0' else '0'

l.append(c)
if S[-1] == '0':
	l.append(0)

n = len(l)//2
if n <= K:
	print(N)
	exit()

size = len(l)
cand = []
k = 2*K+1
cd = sum(l[0:k])
cand.append(cd)
for i in range(0,size-k,2):
	cd = cd - l[i]-l[i+1] + l[i+k] + l[i+k+1]
	cand.append(cd)
print(max(cand))





Measured memory_bytes: 5404
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

ll gcd(ll a,ll b){
  if(a%b==0) return b;
  else return gcd(a,a%b);
}

ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a/g*b;
}

int main(){
  string s;
  cin >> s;
  if(s.at(s.size()-1)=='s'){
    cout << s << "es" << endl;
  }else{
    cout << s << "s" << endl;
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(void){
    // Your code here!
    long long int n;
    cin >> n;
    
    long long int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    long long int sum=0;
    for(int i=0;i<n-1;i++){
        if(a[i+1] < a[i]){
            sum += (a[i]-a[i+1]);
            a[i+1] = a[i];
        }
    }
    
    cout << sum << endl;
    
    
    
}

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

using namespace std;

int main()
{
    int n,i,j,sum=0;
    cin>>n;
    int a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
        if(a[i]>b[i])
        {
            sum=sum+a[i]-b[i];
        }
    }
    cout<<sum<<endl;
}


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

using namespace std;

#define ll long long
#define int ll

typedef pair<int, int> pii; 

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define syso(n) cout<<n<<endl;  
#define sysom(message, n) cout<<message<<n<<endl;
#define all(c) c.begin(), c.end() 
#define tr(container, it )\
for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(aint(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 
#define all(c) c.begin(), c.end() 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

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

int lcm(int fir, int sec){
    return (fir*sec)/(gcd(fir, sec));
}

const int MOD = 1e9+7;

// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(26) << f << '\n';

// sort(arr, arr+n, greater<int>());

const int maxN = 2*1e5 + 12;
const int maxVal = 1e18;

signed main(){
	fastio;
	int n, k;
	cin>>n>>k;
	std::vector<int> arr(n);
	for (int i = 0; i < n; ++i){
		cin>>arr[i];
	}
	if(n==k){
		cout<<1<<endl;
		return 0;
	}
	int ans = 1;
	int so = k;
	while(so<n){
		ans++;
		so += k-1;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
    int high;
		int low;
		int sa;
		
    public void solve(){
		Scanner sc=new Scanner(System.in);
		
		
    
		for(int i=0;i<7;i++){
			
        high=sc.nextInt();
        low=sc.nextInt();
		sa=high-low;
   
	System.out.println(sa);
    
    }
	
    }

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

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

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

int N;
int A[200000];

int main() {
  scanf("%d", &N);
  REP(i,N) {
    scanf("%d", &A[i]);
    A[i] -= (i + 1);
  }

  sort(A, A+N);
  int med = A[(N/2)];
  
  unsigned long long result = 0;
  REP(i,N) result += abs(A[i] - med);
  printf("%llu\n", result);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<pair<int,int>> v(n,make_pair(0,0));
    rep(i,n){
        cin >>v[i].first;
        v[i].second = i+1;
    }
    sort(all(v));
    rep(i,n){
        cout << v[i].second << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main(){
  string S;cin>>S;
  int N = S.size();
  reverse(S.begin(),S.end());
  S += '0';
  ll ans = 0;
  bool dig = false;
  rep(i,N+1){
    int now = S[i] - '0';
    if(dig) now++;
    dig = false;
    int nxt = 0;
    if(i+1 <= N) nxt = S[i+1] - '0';
    if(now > 5 || (now == 5 && nxt >= 5)) {
      ans += 10 - now;
      dig = true;
    } else {
      ans += now;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5312
#include <iostream>

using namespace std;

int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s){
        a--;
    }
    else{
        b--;
    }
     cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[5000001], invf[5000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
ll solve(int a, int b, int p, int q){
	ll ret=0;
	for(int i=0; i<=q; i++){
		(ret+=(p+i+1)*comb(p+i, p)%MOD*comb(a-p-1+b-i, a-p-1))%=MOD;
	}
	for(int i=0; i<=p; i++){
		(ret+=(q+i+1)*comb(q+i, q)%MOD*comb(b-q-1+a-i, b-q-1))%=MOD;
	}
	return ret;
}
ll solve(int a, int b, int p, int q, int r, int s){
	return (solve(a, b, q, s)-solve(a, b, p-1, s)-solve(a, b, q, r-1)+solve(a, b, p-1, r-1)+2*MOD)%MOD;
}
int main()
{
	int x[6], y[6];
	for(int i=0; i<6; i++) cin>>x[i];
	for(int i=0; i<6; i++) cin>>y[i];
	x[0]--; y[0]--; x[5]++; y[5]++;
	fac(2000000);
	ll ans=0;
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			for(int k=4; k<6; k++){
				for(int l=4; l<6; l++){
					int p=((i+j+k+l)&1);
					ll myon=solve(x[k]-x[i], y[l]-y[j], x[2]-x[i], x[3]-x[i], y[2]-y[j], y[3]-y[j]);
					if(p) ans+=MOD-myon;
					else ans+=myon;
					if(ans>=MOD) ans-=MOD;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}

int N,M;
vector<int> G[100010];
int dp[100010];

int dfs(int v) {
    if(dp[v] != -1) return dp[v];
    int res = 0;
    for(auto nv :G[v]) {
        chmax(res, dfs(nv)+1);
    }
    return dp[v] = res;
}

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

cin >> N >> M;
rep(i,M) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    G[x].push_back(y);
}
rep(v,N) dp[v] = -1;

int ans = 0;
rep(v,N) chmax(ans, dfs(v));
cout << ans << endl;
return 0;
}

Measured memory_bytes: 8192
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		
		int ans = A - 2 * B;
		if(ans < 0)
			ans = 0;
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 22612
import copy

N = int(input())
H = list(map(int, input().split()))

ctr = 0
while H:
	# print(H)
	if H[0] == 0:
		H.pop(0)
	else:
		H[0] -= 1
		for i in range(1, len(H)):
			if H[i] != 0:
				H[i] -= 1
			else:
				break
		ctr += 1
	
				
print(ctr)

Measured memory_bytes: 39408
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int X, A, B;
    cin >> X >> A >> B;
    if(B <= A) cout << "delicious" << "\n";
    else if(B-A <= X) cout << "safe" << "\n";
    else cout << "dangerous" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int main()
{
  int N, M;
  while(cin >> N >> M,N,M) {
    int cnt[505] = {0};
    int A[10005], B[10005];
    cnt[0] = 1;
    Rep(i,M) {
      cin >> A[i] >> B[i];--A[i],--B[i];
      if(!A[i])cnt[B[i]] = 1;
    }
    Rep(i,M) {
      if(cnt[A[i]] == 1) {
	if(!cnt[B[i]])cnt[B[i]] = 2;
      }else if(cnt[B[i]] == 1) {
	if(!cnt[A[i]])cnt[A[i]] = 2;
      }
    }
    int sum = 0;
    Rep(i,N) {
      sum += cnt[i] >= 1;
    }
    cout << sum - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
s = input()
n = len(s)
flag = True
for i in range(n):
    if s[i] != s[n - i - 1]:
        flag = False

for i in range((n - 1) // 2):
    if s[i] != s[(n - 1) // 2 - i - 1]:
        flag = False

for i in range((n + 3) // 2, n):
    if s[i] != s[n - i - 1]:
        flag = False
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38460
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
		// 整数の入力
        int hp= sc.nextInt();
        int n = sc.nextInt();
        int sum = 0;
        for(int i = 0; i < n ; i++ ){
            sum += sc.nextInt();
        }

        if(hp <= sum){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
        
       


    
	}
}

Measured memory_bytes: 46104
# ABC150C - Count Order

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

a,b=0,0

l=[i for i in range(1,n+1)]

for i in range(n-1):
    for j in range(n):
        if l[j]==p[i]:
            l.pop(j)
            break
    tmp=j
    for j in range(1,n-i):
        tmp*=j
    a+=tmp

#print(a)

l=[i for i in range(1,n+1)]

for i in range(n-1):
    for j in range(n):
        if l[j]==q[i]:
            l.pop(j)
            break
    tmp=j
    for j in range(1,n-i):
        tmp*=j
    b+=tmp

#print(b)
        
print(abs(a-b))

Measured memory_bytes: 3064
from heapq import heappop,heappush
INF = float("inf")
white = 0; gray = 1; black =2

def dijkstra(s):
    # 頂点sをrootに設定
    dist[s] = 0 
    heappush(PQ,(0,s))
    color[s] = gray

    while PQ:
        #最短経路木に頂点(最短経路木とつながる最小コストの辺を持つ頂点)を追加
        mincost,u = heappop(PQ)
        color[u] = black
        if dist[u] < mincost: continue # 最短じゃなかったら無視

        # 追加した頂点uの隣接頂点についてsからの最小コストを更新
        for v,cost in adj[u]:
            if color[v] == black: continue # 確定済み
            if dist[v] > dist[u] + cost:
                dist[v] = dist[u] + cost
                heappush(PQ,(dist[v],v))
                color[v] = gray

if __name__ == "__main__":
    n = int(input())
    adj = [[] for _ in range(n)]
    for i in range(n):
        inp = [int(x) for x in input().split()]
        u = inp[0]
        for v,c in zip(inp[2::2],inp[3::2]): adj[u].append((v,c))
    color = [white]*n #各頂点の訪問状態 （white:未訪問 gray:暫定 black:確定）
    dist = [INF]*n # 始点sからの最小コスト
    PQ = []
    dijkstra(0)
    for i in range(n): print("{} {}".format(i,dist[i]))


Measured memory_bytes: 68792
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef tuple<int, int> ii;
typedef tuple<int, int, int> iii;
const int INF = 900000;
const ll INFL = 9000000;

#define vi vector<int>
#define vii vector<vector<int> >
#define vi_def(n) vector<int>((n))
#define vii_def(n,m) vector<vector<int> >((n), vector<int>((m)))
#define vi_def_dflt(n, def) vector<int>((n), (def))
#define vii_def_dflt(n, m, def) vector<vector<int> >((n), vector<int>((m), (def)))

#define rep(i, n) for(int i=0; i < (n); ++i)
#define per(i, n) for(int i=(n)-1; i >= 0; --i)
#define range(i, begin, end) for(int i=(begin); i < (end); ++i)

#define ALL(vec) vec.begin(), vec.end()

#ifdef DBG_FLAG
#define pdbg(msg) cout << (msg)
#define pdbgl(msg) cout << (msg) << endl
#define dbg if(true)
#else
#define pdbg(msg) ;
#define pdbgl(msg) ;
#define dbg if(false)
#endif

int N, K;
vi p;
int main(){
  cin >> N >> K;
  p = vi_def(N);
  rep(i, N) cin >> p[i];

  sort(ALL(p));

  int sum = 0;
  rep(i, K){
    sum += p[i];
  }

  cout << sum << endl;
}


Measured memory_bytes: 3624
N = int(input())
H = [int(i) for i in input().split(' ')]

last_i = len(H) - 1
last_high = 100000000000
counter = 0
best = 0
for j in range(len(H)):
    i = last_i - j
    if H[i] >= last_high:
        counter += 1
        last_high = H[i]
    else:
        if best < counter:
            best = counter
        counter = 0
        last_high = H[i]

if best < counter:
    best = counter

print(best)


Measured memory_bytes: 14252