akhauriyash/Code-Regression huggingface dataset:
import math
from collections import defaultdict

def is_prime(n: int)-> bool:
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    # when n is a prime number
    # x^(n-1) ≡ 1 (mod n)
    return pow(2, (n-1), n) == 1


def prime_factorize(n: int):
    prime_factors = defaultdict(int)

    for i in range(2, int(math.sqrt(n)) + 1):
        if not is_prime(i):
            continue
        while True:
            div, mod = divmod(n, i)
            if mod == 0:
                prime_factors[i] += 1
                n = div
            else:
                break
        if n == 1:
            break
    if n != 1:
        prime_factors[n] = 1

    return prime_factors


def main():
    N, P = map(int, input().split())
    prime_factors = prime_factorize(P)

    gcd = 1
    for k, v in prime_factors.items():
        v_cnt = v // N
        gcd *= pow(k, v_cnt)

    print(gcd)
    return

main()

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

int main(){
    int N;
    cin >> N;
    char S[N];
    long long r = 0;
    long long g = 0;
    long long b = 0;
    for (int l = 0; l < N; l++)
    {
        cin >> S[l];
        if (S[l] == 'R')
        {
            r++;
        } else if (S[l] == 'G')
        {
            g++;
        } else
        {
            b++;
        }

    }
    long long ans = 0;
    ans = r * g * b;

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int k = 2 * j - i;
            if(k>=N || k<=j){
                continue;
            }
            if ((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k]))
            {
                ans = ans -1;
            }
            
        }
        
    }

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

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

int main(){
  int a,b,c;
  map<int,int> data;
  
  cin>>a>>b;
  for(int i=1;i<a+1;i++){
    data[i]=0;
  }
  for(int i=0;i<b;i++){
    cin>>a;
    for(int j=0;j<a;j++){
      cin>>c;
      
      data[c]=1;
      
    }
  }

  a=0;
  for(int i=1;i<1+data.size();i++){
    
    if(data[i]==0)a+=1;
  }
  cout<<a;
}

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

typedef long long int ll;


ll n;ll a,b,c,d;
string s;

int main(){

  std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


    string s;
    cin>>s;

    ll n = s.size();
    ll pre[n+1];
    memset(pre,0,sizeof(pre));
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='A')
          pre[1+i] = 1;

    }
    ll ans = 0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='A')
        pre[i+1] += pre[i];
        //cout<<i<<" "<<pre[i+1]<<" "<<pre[i]<<" "<<ans<<endl;
        if(i>=2)
        {
            //cout<<"TO"<<endl;
            if(s[i]=='C')
            {
                //cout<<"IO"<<endl;
                if(s[i-1]=='B')
                {
                    if(s[i-2]=='A')
                    {
                       // cout<<"YES"<<endl;
                        ans += pre[i-1];
                        pre[i+1] += pre[i-1];
                        pre[i-1] = 0;
                        s[i]='A';
                    }
                }
            }
        }
    }
    cout<<ans<<endl;





}


Measured memory_bytes: 2196
class UnionFind:
    def __init__(self, num):
        self.rank = [0] * num
        self.par = [i for i in range(num)]
        self.n = num
 
    def find_root(self, node):
        if self.par[node] == node:
            return node
        else:
            self.par[node] = self.find_root(self.par[node])
            return self.par[node]
 
    def same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)
 
    def union(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1


N,M = map(int,input().split())

UF = UnionFind(N)
for i in range(M) :
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    UF.union(x, y)

ans = 0
for i in range(N) :
    if i != UF.par[i] :
        continue
    else :
        ans += 1
print(ans)


Measured memory_bytes: 7856
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int in;
    cin >> in;
    mp[in]++;
  }
  vector<bool> chk(1e6+5, false);
  for(auto p : mp){
    auto [i, x] = p;
    for(int j = i+i; j < chk.size(); j += i){
      chk.at(j) = true;
    }
  }
  int ans = 0;
  for(auto p : mp){
    if(p.second > 1) continue;
    if(chk.at(p.first) == false) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12984
#include<stdio.h>
int compare(const void *a,const void *b){
	int *pa=(int*)a;
	int *pb=(int*)b;
	int num1=*pa;
	int num2=*pb;
	return num1-num2;
}
int main(){
	int n,j,i,flag=1;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	qsort(a,n,sizeof(int),compare);
	for(i=1;i<n;i++){
		if(a[i-1]==a[i]){
			flag=0;
			break;
		}
	}
	if(flag)printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 1788
#include<iostream>
#include<fstream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define int long long
#define mod 1000000009
#define inf 4444444444444444444
#define mn 150005

int M, D;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>M>>D;
	int ans=0;
	for (int m=1; m<=M; m++) for (int d=1; d<=D; d++)
	{
		int d1=d%10, d2=d/10;
		if (d1<2||d2<2) continue;
		if (d1*d2==m) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100000 + 100;
int A, B, cnt, f[110][110];

void Init()
{
	scanf("%d%d", &A, &B);
	memset(f, 0, sizeof(f));
	for(int i = 1; i <= 50; ++i)
		for(int j = 1; j <= 100; ++j)
			f[i][j] = 1;
}

void Solve()
{
	cnt = 0;
	for(int i = 1; i <= 50; ++i)
		for(int j = 1; j <= 100; ++j)
		{
			if(cnt == A-1) break;
			if(i & j & 1) cnt++, f[i][j] = 0;
		}
	cnt = 0;
	for(int i = 100; i >= 51; --i)
		for(int j = 1; j <= 100; ++j)
		{
			if(cnt == B-1) break;
			if(i & j & 1) cnt++, f[i][j] = 1;
		}
	printf("100 100\n");
	for(int i = 1; i <= 100; ++i)
	{
		for(int j = 1; j <= 100; ++j)
			printf("%c", f[i][j] ? '#' : '.');
		printf("\n");
	}
}

int main()
{
	Init(), Solve();
}

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

#define INF 1E18



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

    int n = s.length();
    int no0 = 0;
    int no1 = 0;

    rep(i,n){
        if(s[i] == '0') no0++;
        else no1++;
    }

    cout << min(no0,no1)*2 <<endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
ll n, ans[10000010], cnt = 0;
int main() {
	cin >> n;
	ll f = n;
	for (ll i = n; i >= 1; i--) {
		if (f > (i)*(i - 1) / 2) {
			ans[cnt] = i;
			cnt++;
			f -= i;
		}
	}
	for (ll i = cnt - 1; i >= 0; i--)cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 256
# AtCoder Beginner Contest 076
# D - AtCoder Express
# https://atcoder.jp/contests/abc076/tasks/abc076_d


def solve(T, V, velocity):
    accT = 1
    for t, max_v in zip(T, V):
        for i in range(accT, accT+2*t):
            velocity[i] = min(velocity[i], velocity[i-1]+0.5, max_v)
        accT += 2*t


def main():

    N, *A = map(int, open(0).read().split())
    T = A[:N]
    V = A[N:]

    INF = 10**10

    velocity = [INF]*(sum(T)*2+1)
    velocity[0] = 0
    velocity[-1] = 0
    solve(T, V, velocity)
    velocity = velocity[::-1]
    solve(T[::-1], V[::-1], velocity)

    ans = 0
    pre_v = velocity[0]
    for v in velocity[1:]:
        ans += (pre_v + v) * 0.25
        pre_v = v

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int cnt=-1,ans;
    FOR(i,1,n+1){
        int now=0,x=i;
        while(x%2==0){
            now++;
            x/=2;
        }
        if(chmax(cnt,now)) ans=i;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
  vector<int> list;
  
  for (int i = 0; i < 3; i++) {
    int cost;
    
    cin >> cost;
    
    list.push_back(cost);
  }
  
  sort(list.begin(), list.end());
  
  int sum = 0;
  
  for (int i = 1; i < 3; i++) {
    sum += list[i] - list[i - 1];
  }
  
  cout << sum << endl;
  
  return 0;
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  string h = S.substr(0, 2);
  string l = S.substr(2, 2);
  const char* result = "NA";
  if (("01" <= h) && (h <= "12") &&
      ("01" <= l) && (l <= "12")) {
    result = "AMBIGUOUS";
  } else if (("01" <= h) && (h <= "12")) {
    result = "MMYY";
  } else if (("01" <= l) && (l <= "12")) {
    result = "YYMM";
  }
  cout << result << endl;
  return 0;
}


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

int main() {
    int n;
    int y, m, d;

    int Millennium = 1;
    for(int i = 1; i <= 999; i++) {
        if(i % 3 == 0) {
            Millennium += 10 * 20;
        }
        else {
            Millennium += 5 * 20 + 5 * 19;
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> y >> m >> d;
        int sum = 0;
        for(int j = 1; j <= y-1; j++) {
            if(j % 3 == 0) {
                sum += 10 * 20;
            }
            else {
                sum += 5 * 20 + 5 * 19;
            }
        }
        for(int j = 1; j <= m-1; j++) {
            if(y % 3 == 0 || j % 2 == 1) {
                sum += 20;
            }
            else {
                sum += 19;
            }
        }
        sum += d;

        cout << Millennium - sum << endl;
    }


    return 0;
}


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

int GCD(long long x, long long y){
    if(x<y){
        long tmp;
        tmp=x;
        x =y;
        y =tmp;
    }
 
    long r=x%y;
    while(r!=0){
        x=y;
        y=r;
        r=x%y;
    }
 
    return y;
}

int main(){
    long long A,B,C,D,E;
    long long ncl,ncr,ndl,ndr;
    long long nel,ner;
    cin >> A >> B >> C >> D;
    E = (C*D)/GCD(C,D);
    ncr = B/C;
    //if(B%C==0) ncr-=1;
    ncl = A/C;
    if(A%C==0) ncl-=1;
    ndr = B/D;
    //if(B%D==0) ndr-=1;
    ndl = A/D;
    if(A%D==0) ndl-=1;
    ner = B/E;
    nel = A/E;
    if(A%E==0) nel-=1;    

    long long ans = (B-A+1) - (ncr-ncl) - (ndr-ndl) + (ner-nel);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int,input().split(" ")))
M = int(input())
P = [0]*M
X = [0]*M
s = sum(T)
for i in range(M):
    P[i],X[i]=map(int,input().split(" "))
    X[i] -= T[P[i]-1]
    X[i] += s

for i in range(M):
    print(X[i])

Measured memory_bytes: 3064
import queue
qu = queue.PriorityQueue()
visited = set()
s = input()
K = int(input())
for i,v in enumerate(list(s)):
    qu.put((v,i,1))
counter = []
while not qu.empty() and len(counter) < K:
    string,index,length = qu.get()
    if string not in visited:
        counter.append(string)
    visited.add(string)
    if index + length < len(s):
        qu.put((s[index:index+length+1], index, length + 1))
print(counter[-1])



Measured memory_bytes: 4720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define no {cout<<"NO"<<endl;return;}
#define yes {cout<<"YES"<<endl;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=2e5;
int arr[maxn+2];

void solve(){

    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    arr[0]=0;
    int pre=0;
    ll tot=0;
    for(int i=1;i<=n;i++){

        if(arr[i]>=arr[i-1]) continue;
        else{
            tot+=arr[i-1]-arr[i];
            arr[i]=arr[i-1];
        }
    }
   // for(int i=1;i<=n;i++) cout<<arr[i];
    cout<<tot;
}

int main(){
    IO

    //TEST
    solve();

    return(0);
}



Measured memory_bytes: 4416
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long long,long long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<pair<P, int>> pref(m);
	rep(i, m) {
		cin >> pref[i].first.first >> pref[i].first.second;
		pref[i].second = i;
	}
	sort(pref.begin(), pref.end());
	pref.push_back(pair<P, int>(P(0, 0), 0));
	int cnt = 0;
	rep(i, m) {
		cnt++;
		pref[i].first.second = cnt;
		if (pref[i].first.first != pref[i + 1].first.first)cnt = 0;
	}
	vector<P>ans(m);
	rep(i, m) {
		ans[pref[i].second] = P(pref[i].first.first, pref[i].first.second);
	}
	rep(i, m) {
		cout << setfill('0') << setw(6) << ans[i].first << setw(6) << ans[i].second << endl;
	}
	return 0;
}

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

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

#define MOD 1000000007

int main(void) {
    ll X;
    cin >> X;
    for(ll i = X;;i++) {
        for(ll j = 2;j < i;j++) {
            if(i % j == 0) goto aaa;
        }
        cout << i << endl;
        return 0;
        aaa:;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int d=n/k;

    if (n%k==0) {
      System.out.println(0);
    }else{
      System.out.println(1);
    }
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
const int MN=1000+5;
const int P=1000000007;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,m,N;ll k;
int a,b,c,d,s;char mp[MN][MN];
struct mat{
	ll a[2][2];
	mat(){memset(a,0,sizeof a);}
	ll*operator[](int x){return a[x];}
	mat operator*(mat b){
		mat c;
		for(int k=0;k<N;++k)for(int i=0;i<N;++i)for(int j=0;j<N;++j)
			c[i][j]=(c[i][j]+a[i][k]*b[k][j])%P;
		return c;
	}
}res,sum;
ll qp(ll a,ll b){ll c=1;for(;b;b>>=1,a=a*a%P)if(b&1)c=c*a%P;return c;}
void input(){
	IN(n),IN(m),IN(k);N=2;
	for(int i=1;i<=n;++i){
		scanf("%s",mp[i]+1);
		for(int j=1;j<=m;++j)
			s+=mp[i][j]=='#';
	}
	for(int i=1;i<=n;++i)a+=(mp[i][1]==mp[i][m]&&mp[i][1]=='#');
	for(int i=1;i<=m;++i)b+=(mp[1][i]==mp[n][i]&&mp[1][i]=='#');
	if((a&&b)||!k)return puts("1"),void();
	if(!a&&!b)return printf("%lld\n",qp(s,k-1)),void();
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j){
		c+=(mp[i][j]==mp[i][j+1]&&mp[i][j]=='#');
		d+=(mp[i][j]==mp[i+1][j]&&mp[i][j]=='#');
	}
	if(a)sum[0][0]=s,sum[0][1]=c,sum[1][1]=a;
	else sum[0][0]=s,sum[0][1]=d,sum[1][1]=b;
	k--;res[0][0]=res[1][1]=1;
	while(k){
		if(k&1)res=res*sum;
		sum=sum*sum;k>>=1;
	}
	printf("%lld\n",(res[0][0]-res[0][1]+P)%P);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 1280
#include<cstdio>

int a[200005], b[200005];

int main()
{

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

	int left = 100000, right = left + 1;

	for (i = 0; i < n; i++)
	{
		if ((n + i) % 2 != 0)
		{
			b[left] = a[i];
			left--;
		}
		else
		{
			b[right] = a[i];
			right++;
		}

	}
	for (i = left + 1; i < right; i++)
	{
		printf("%d ", b[i]);
	}
	return 0;
}

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

int cmp(const void * n1, const void * n2)
{
	if (*(double *)n1 > *(double *)n2)
	{
		return -1;
	}
	else if (*(double *)n1 < *(double *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  int n;
  scanf("%d", &n);
  double v[n];
  for (int i = 0; i < n; i++) {
    scanf("%lf", &v[i]);
  }

  double new;

  for (int i = n; i > 2; i--) {
    qsort(v, i, sizeof(double), cmp);
    new = v[i-1]+v[i-2];
    new /= 2;
    v[i-2] = new;
  }

  double answer = v[0]+v[1];
  answer /= 2;
  printf("%lf\n", answer);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int a,b;
    std::cin >> a >> b;
    std::cout << "a ";
    if(a==b){
        std::cout << "==";
    }
    else if(a<b){
        std::cout << "<";
    }
    else{
        std::cout << ">";
    }
    std::cout << " b" << std::endl;
    return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    n, m = map(int, input().split())
    H = tuple(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in range(m)]

    ans = [True] * n
    for i in range(m):
        if H[AB[i][0]-1] > H[AB[i][1]-1]:
            ans[AB[i][1]-1] = False
        elif H[AB[i][0]-1] < H[AB[i][1]-1]:
            ans[AB[i][0]-1] = False
        elif H[AB[i][0]-1] == H[AB[i][1]-1]:
            ans[AB[i][0]-1] = False
            ans[AB[i][1]-1] = False

    print(sum(ans))


if __name__ == '__main__':
    main()



Measured memory_bytes: 27748
def check(x):
  if len(str(x))!=N:
    return False
  for i in range(M):
    if str(x)[S[i]]!=str(C[i]):
      return False
  return True

N,M=map(int,input().split())
S=[]
C=[]
for i in range(M):
  s,c=map(int,input().split())
  s-=1
  S.append(s)
  C.append(c)
#print(S,C)
for i in range(1000):
  if check(i):
    print(i)
    exit()   
print(-1)    

Measured memory_bytes: 3064
N,W=map(int,input().split())

v=[]
w=[]
for i in range(N):
    w_i,v_i=map(int,input().split())
    w.append(w_i)
    v.append(v_i)

sum_v=sum(v)+1
dp=[[float('inf')]*(sum_v) for i in range(N+1)] 
dp[0][0]=0

for i in range(N):
    for j in range(sum_v):
        if dp[i+1][j] > dp[i][j]:
            dp[i+1][j] = dp[i][j]
        if j >= v[i]:
            if dp[i+1][j] > dp[i][j-v[i]]+w[i]:
                dp[i+1][j] = dp[i][j-v[i]]+w[i]

ans=0
for i in range(1,sum_v):
  if dp[N][i] <= W:
    ans = i
print(ans)

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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << "a ";
	if (a < b) {
		cout << '<';
	} else if (a > b) {
		cout << '>';
	} else {
		cout << "==";
	}
	cout << " b" << endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	LL n,m;
	cin >> n >> m;
	if (n > m-1) {
		cout << 0 << endl;
		return 0;
	}
	VL x(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}
	SORT(x);
	VL d(m-1);
	for (int i = 0; i < m-1; i++) {
		d[i] = x[i+1] - x[i];
	}
	sort(RALL(d));
	LL ans = x[m-1] - x[0];
	for (int i = 0; i < n-1; i++) {
		ans -= d[i];
	}
	cout << ans << endl;
	return 0;


}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std ;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,cnt=1,fl=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    fl=a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]>=fl)
        {
            fl=a[i];
            cnt++;
        }
    }
    cout<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
typedef long long lld;
const int MAXN = 2e5+5;
int A[MAXN];
int B[MAXN];
int pos[MAXN];
int N;
lld K;

int solve() {
  int cur = 1;
  pos[cur] = 0;
  B[pos[cur]] = cur;
  while (pos[A[cur]] == -1) {
    pos[A[cur]] = pos[cur] + 1;
    cur = A[cur];
    B[pos[cur]] = cur;
  }
  int init = pos[A[cur]];
  int loop = pos[cur] - init + 1;
  if (K <= init) {
    return B[K];
  }
  return B[(K - init) % loop + init];
}

int main() {
  scanf(" %d%lld", &N, &K);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    pos[i] = -1;
  }
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 5408
use std::io::{self};
use std::convert::TryFrom;
use std::convert::TryInto;

fn main() {
    let mut buffer1 = String::new();
    let (n, m, k): (u64, u64, u64) = match io::stdin().read_line(&mut buffer1) {
        Ok(_) => {
            let vec: Vec<&str> = buffer1.trim().split(' ').collect();
            (vec[0].parse::<u64>().ok().expect("woops"), 
             vec[1].parse::<u64>().ok().expect("woops"),
             vec[2].parse::<u64>().ok().expect("woops")
            )
        },
        Err(_) => panic!()
    };        
    let mut buffer2 = String::new();
    let a_vec: Vec<u64> = match io::stdin().read_line(&mut buffer2) {
        Ok(_) => {
            let a_str_vec: Vec<&str> = buffer2.trim().split(' ').collect();
            a_str_vec.iter().map(|a_str| a_str.parse::<u64>().ok().expect("woops")).collect::<Vec<u64>>()
        },
        Err(_) => panic!()
    };

    let mut buffer3 = String::new();
    let b_vec: Vec<u64> = match io::stdin().read_line(&mut buffer3) {
        Ok(_) => {
            let b_str_vec: Vec<&str> = buffer3.trim().split(' ').collect();
            b_str_vec.iter().map(|a_str| a_str.parse::<u64>().ok().expect("woops")).collect::<Vec<u64>>()
        },
        Err(_) => panic!()
    };

    let ans = exec_calc(n, m, k, a_vec, b_vec);

    println!("{:?}", ans);
    return;
}

fn exec_calc(n: u64, m: u64, k: u64, a_vec: Vec<u64>, b_vec: Vec<u64>) -> u64 {
    let mut a_reduced = Vec::<u64>::with_capacity(usize::try_from(n + 1).unwrap());
    a_reduced.push(0);
    for ind_a in 0 .. a_vec.len() {
        a_reduced.push((&a_vec)[ind_a] + (&a_reduced)[ind_a]);
    }

    let mut b_reduced = Vec::<u64>::with_capacity(usize::try_from(m + 1).unwrap());
    b_reduced.push(0);
    for ind_b in 0 .. b_vec.len() {
        b_reduced.push((&b_vec)[ind_b] + (&b_reduced)[ind_b]);
    }

    let mut count : u64 = 0;
    let mut b_ind = b_reduced.len() - 1;

    for a_ind in 0 .. a_reduced.len() {
        if a_reduced[a_ind] > k {
            break
        }
        while a_reduced[a_ind] + b_reduced[b_ind] > k && b_ind > 0 {
            b_ind -= 1;
        }
        if a_ind + b_ind > count.try_into().unwrap() {
            count = (a_ind + b_ind).try_into().unwrap();
        }
    }
    return count
}

Measured memory_bytes: 12512
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string S; cin >> S;
  string T = S;
  ll K; cin >> K;
  auto len = S.size();
  S += S;
  ll res0{}, res1{};
  for (size_t i = 1; i < S.size(); ++i) {
    if (S[i - 1] == S[i]) {
      if (i < len) {
        ++res0;
    } else {
        ++res1;
      }
      if (i < S.size() - 1) {
        S[i] = S[i + 1] - 1;
      }
    }
  }
  set<char> t{T.begin(), T.end()};
  if (t.size() == 1) {
    cout << (T.size() * K) / 2 << CRLF;
    return;
  }

  auto ans = res0 + res1 * (K - 1);
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> vec(N,0);
    for(int i=0; i<N-1; i++){
        int a;
        cin >> a;
        a--;
        vec[a]++;
    }

    for(auto v:vec){
        cout << v << endl;
    }
}

Measured memory_bytes: 4000
#include <iostream>

using namespace std;

int main()
{
   int a, b;
   cin >> a >> b;
   if (a == b)
   cout <<"a == b"<< endl;
   else if (a<b)
   cout <<"a < b"<<endl;
   else if (a>b)
   cout <<"a > b"<<endl;
}


Measured memory_bytes: 3092
import math
a, b = input().split()
a1 = int(a)
b1 = int(b[0])
b2 = int(b[2])*10 + int(b[3])
if a1*b2 > 100:
    p = a1*b2//100
    print(a1*b1+p)
else:
    print(a1*b1)


Measured memory_bytes: 9172
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int poolSize = Integer.parseInt(scanner.nextLine());
		String[] cards = scanner.nextLine().split(" ");
		List<Integer> sortedCards = new ArrayList();

		for (String card: cards) {
			sortedCards.add(Integer.parseInt(card));
		}
		sortedCards.sort(Collections.reverseOrder());


		Object c[] = sortedCards.toArray();
		int alice = 0;
		int bob = 0;

		for(int i=0; i<poolSize; i+=2) {
			alice += (int)c[i];
		}
		for(int i=1; i<poolSize; i+=2) {
			bob += (int)c[i];
		}

		System.out.println(alice - bob);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>

#define LIM 300020
using namespace std;

int main(){
	
	int n, k, m;
	
	while(cin>>n>>k>>m, (n||k||m)){
		
		vector<int> vc;
		
		for(int i=1; i<=n; ++i){
			vc.push_back(i);
		}
		
		int ptr = m-1;
		
		while(vc.size()>1){
		
			vc.erase(vc.begin()+ptr);
			ptr = (ptr+k-1)%(vc.size());
		}
		
		cout << vc[0] << endl;
	}
	
	return 0;
}
			
			

Measured memory_bytes: 1324
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 500001;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int a[MAXN];
int cnt[MAXN];
int ans = 0, n, m;
 
void remove(int idx) {
   // cout << idx << " REMOVE\n";
    int t = a[idx];
    cnt[t]--;
    if (cnt[t] == 0) ans--;
}
 
void add(int idx) {
    // cout << idx << " ADD\n";
    int t = a[idx];
    if (cnt[t] == 0) ans++;
    cnt[t]++;
}
 
int get_answer() {
    return ans;    
}
 
const int block_size = 710;
 
struct Query {
    int l, r, idx;
    bool operator<(Query other) const
    {
        return make_pair(l / block_size, r) < 
               make_pair(other.l / block_size, other.r);
    }
};
 
vector<int> mo_s_algorithm(vector<Query> queries) {
    vector<int> answers(queries.size());
    sort(queries.begin(), queries.end());
 
    for (int i = 0; i < MAXN; i++) {
        cnt[i] = 0;
    }
 
    int cur_l = 0;
    int cur_r = -1;
    // invariant: data structure will always reflect the range [cur_l, cur_r]
    for (Query q : queries) {
        while (cur_l > q.l) {
            cur_l--;
            add(cur_l);
        }
        while (cur_r < q.r) {
            cur_r++;
            add(cur_r);
        }
        while (cur_l < q.l) {
            remove(cur_l);
            cur_l++;
        }
        while (cur_r > q.r) {
            remove(cur_r);
            cur_r--;
        }  
       // cout << q.l << ' ' << q.r << ' ' << ans << endl << endl;
        answers[q.idx] = get_answer();
    }
    return answers;
}
 
signed main() {
    cin >> n;
    cin >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
 
    vector<Query> q(m);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        q[i] = {l - 1, r - 1, i};
    }
 
    for (int x: mo_s_algorithm(q)) {
        cout << x << '\n';
    }
} 

Measured memory_bytes: 38304
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int K, T;
int A[101010];

int main()
{
	scanf("%d%d", &K, &T);
	for (int i = 0; i < T; ++i) scanf("%d", A + i);
	int mx = 0;
	for (int i = 0; i < T; ++i) mx = max(mx, A[i]);

	if (mx * 2 - 1 <= K) {
		puts("0");
	} else {
		printf("%d\n", mx * 2 - K - 1);
	}

	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOGE if(DEBUG)cout<<endl;

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


int main(){
    // cout << fixed << setprecision(5);

    lli m;
    cin>>m;

    cout<<24-m+24<<endl;

    return 0;
}


Measured memory_bytes: 3616
n,m,c=map(int,input().split())
b=list(map(int, input().split()))
a=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n):
  sum=c
  for j in range(m):
    sum+=b[j]*a[i][j]
  if sum>0:
    count+=1
print(count)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    int N;
    cin >> N;
    vi a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
            ans++;
    }

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

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

int main(){
	string s;
	int n;
	cin>>n;
	cin>>s;
	int max=0;
	int x=0;
	for(int i=0;i<n;i++){
		if(s[i]=='I'){
			x++;
			if(x>max){
				max=x;
			}
		}else if(s[i]=='D'){
			x--;
			if(x>max){
				max=x;
			}
		}
	}
	cout<<max;
	return 0;
}

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

using namespace std;
const int qq = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
int num[qq];

#define LL long long
#define mst(a, b)	memset(a, b, sizeof a)

int main() {
	int n;	scanf("%d", &n);
	int cnt1, cnt2;
	cnt1 = cnt2 = 0;
	for(int i = 0; i < n; ++i) {
		scanf("%d", num + i);
		if(num[i] >= 0)	cnt1++;
		else	cnt2++;
	}
	int id1 = max_element(num, num + n) - num;
	int id2 = min_element(num, num + n) - num;
//	printf("%d %d\n", id1, id2);
	printf("%d\n", n - 1 + n - 1);
	if (abs(num[id1]) >= abs(num[id2])) {
		for(int i = 0; i < n; ++i) {
			if(i == id1)	continue;
			printf("%d %d\n", id1 + 1, i + 1);
		}
		for(int i = 1; i < n; ++i) {
			printf("%d %d\n", i, i + 1);
		}
	} else {
		for(int i = 0; i < n; ++i) {
			if(i == id2)	continue;
			printf("%d %d\n", id2 + 1, i + 1);
		}
		for(int i = n; i >= 2; --i) {
			printf("%d %d\n", i, i - 1);
		}
	}
	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 REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    int x, y; cin >> x >> y;
    vi n(13, 0);
    n[4] = n[6] = n[9] = n[11] = 1;
    n[2] = 2;

    if(n[x] == n[y]) Yes;
    else No;
}

Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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



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

  ll N; cin>>N;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  ll ans=0;
  
  ll count=0;
  rep(i,N){
    if(A[i]==0) {ans+=count/2; count=0;}
    else count+=A[i];
  }
  ans+=count/2;
  
  cout<<ans<<'\n';
  
  return 0;
}

Measured memory_bytes: 3992
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e5 + 5;
ll arr[N];

int ox,oy,ot,x,y,t,n;
bool flage=true;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d%d%d",&t,&x,&y);
		flage&=(abs(x-ox)+abs(y-oy)<=abs(t-ot) && (abs(t-ot)-abs(x-ox)-abs(y-oy))%2 == 0);
		ox=x,oy=y,ot=t;
	}
	puts(flage?"Yes":"No");
}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}










Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
		String s;
		String sl[];

		s = r.readLine();
		sl = s.split(" ");

		int n = Integer.parseInt(sl[0]);
		int m = Integer.parseInt(sl[1]);

		ArrayList<ArrayList<Integer>> g = new ArrayList<>();
		boolean b[] = new boolean[300000];

		for (int i = 0; i < 3 * n; i++) {
			g.add(new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			s = r.readLine();
			sl = s.split(" ");
			int u = Integer.parseInt(sl[0]) - 1;
			int v = Integer.parseInt(sl[1]) - 1;
			g.get(u).add(v + n);
			g.get(u + n).add(v + 2 * n);
			g.get(u + 2 * n).add(v);
		}

		// System.out.println(g);
		s = r.readLine();
		sl = s.split(" ");

		int start = Integer.parseInt(sl[0]) - 1;
		int term = Integer.parseInt(sl[1]) - 1;

		ArrayDeque<Integer> qv = new ArrayDeque<>();
		ArrayDeque<Integer> qd = new ArrayDeque<>();

		qv.offer(start);
		qd.offer(0);

		while (!qv.isEmpty()) {
			int v = qv.poll();
			int d = qd.poll();
			// System.out.println(v + ", " + d);
			if (v == term) {
				System.out.println(d / 3);
				System.exit(0);
			}
			for (Integer e : g.get(v)) {
				if (!b[e]) {
					qv.offer(e);
					qd.offer(d + 1);
					b[e] = true;
				}
			}
		}
		System.out.println(-1);
	}

}


Measured memory_bytes: 101424
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

vector<string> ans;

void dfs(string S, char max_c, int N) {
	if (S.size() == N) {
		ans.push_back(S);
		return;
	}

	for (char c='a'; c<=max_c; c++) {
		if (c == max_c) {
			dfs(S + c, max_c + 1, N);
		} else {
			dfs(S + c, max_c, N);
		}
	}
}

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

	string S = "";
	dfs(S, 'a', N);

	for (string s : ans) {
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 7796
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int X, A;
	cin >> X >> A;

	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}




}


Measured memory_bytes: 3608
import Control.Monad
main = do
  n <- read <$> getLine
  xy <- forM [1..n] $ \i -> do
    a <- read <$> getLine
    forM [1..a] $ \j -> do
      [x,y] <- map read . words <$> getLine
      return (x,y)
  print $ maximum $ length <$> filter (ok xy) (powerset [1..n])

powerset :: [Int] -> [[Int]]
powerset = filterM (const [True,False])

ok ::[[(Int,Int)]] -> [Int] -> Bool
ok xys kinds = and [(y == 0) /= (x `elem` kinds) | i <- kinds,(x,y) <- xys !! (i-1)]

Measured memory_bytes: 6828
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int a,b;
int main() {
	//freopen("1.txt","r",stdin);
	read(a); read(b);
	if (a*500>=b) printf("Yes\n");
	else printf("No\n");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 256
#include <iostream>
#define N 8
using namespace std;
void Put(int,int);
void Judge();
void init();
int m,n,p,iny,inx,anst;
char data[N][N][N],turn;
string ans;

int main(){
  while(1){
    cin>>n>>m>>p;
    if(!n&&!m&&!p) break;
    init();
    for(int i=0;i<p;i++){
      cin>>inx>>iny;
      if(ans!="Draw") continue;
      anst++;
      Put(iny,inx);
      Judge();
      turn=='B'?turn='W':turn='B';
    }
    if(ans!="Draw") cout<<ans<<' '<<anst<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

void Judge(){
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int k=1;k<=n;k++)
	if(data[i][j][k]==turn)
	  for(int l=-1;l<2;l++)
	    for(int o=-1;o<2;o++)
	      for(int q=-1;q<2;q++){
		if(!l&&!o&&!q) continue;
		int cnt=0,y=i,x=j,z=k;
		while(1<=y&&y<=n&&1<=x&&x<=n&&1<=z&&z<=n&&data[y][x][z]==turn){
		  cnt++;
		  y+=l;
		  x+=o;
		  z+=q;
		}
		if(cnt>=m){
		  if(turn=='B') ans="Black";
		  else ans="White";
		}
	      }
}

void init(){
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int k=1;k<=n;k++) data[i][j][k]='E';
  ans="Draw";
  turn='B';
  anst=0;
}

void Put(int y,int x){
  for(int i=1;i<=n;i++)
    if(data[y][x][i]=='E'){
      data[y][x][i]=turn;
      break;
    }
}

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

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

    if(s == t.erase(t.size()-1)){
        cout << "Yes" << endl;
        return 0;
    }


    cout << "No" << endl;



    return 0;
}

Measured memory_bytes: 3632
N,M = map(int , input().split())
A=[map(int , input().split()) for _ in range(M)]
L_min = 0
R_max = N
for L,R in A:
	L_min = max(L_min , L)
	R_max = min(R_max , R)

if R_max - L_min+1 >=0:
	print(R_max - L_min+1)
else:
	print(0)

Measured memory_bytes: 50832
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;

  
int main() {
  int N,p;
  cin >> N >> p;
  string s;
  cin >> s;
  if(10%p==0) {
    ll ans = 0;
    rep(i,N) {
      if((s[i]-'0')%p==0) {
        ans += i+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
  vi dp(N+1,0);
  int k = 1;
  drep(i,N) {
    int x = (s[i]-'0')*k%p;
    dp[i] = (dp[i+1] + x) % p;
    k *= 10;
    k %= p;
  }
  vi cnt(p,0);
  ll ans = 0;
  drep(i,N+1) {
    ans += cnt[dp[i]];
    cnt[dp[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1412
'use strict';

function Main(input) {
  const N = Number(input.split('\n')[0].split(' ')[0]);
  let x = Number(input.split('\n')[0].split(' ')[1]);
  let alist = input.split('\n')[1].split(' ').map(num => Number(num));
  alist.sort((a,b) => a < b ? -1 : 1);
  let aPointer = 0;

  while(aPointer < N) {
    if(x >= alist[aPointer]) {
      x -= alist[aPointer];
      if(aPointer + 1 !== N || x === 0) {
        aPointer++;
      }
     } else {
      break;
    }
  }

  console.log(aPointer);

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21192