akhauriyash/Code-Regression huggingface dataset:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def soinsubunkai_e(n,m): #高速素因数分解 m[n]=nを割ることの出来る最小の素数
    a = set()
    i = 1
    while n>1:
        a.add(m[n])
        n=n//m[n]
    nokori=n
    a.add(nokori)
    return a

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def era(n): #b[n]=nを割ることの出来る最小の素数　の配列を生成　エラトステネスの篩
    b=[i for i in range(n+1)]
    for i in range(2,int(math.sqrt(n)+10)):
        j=1
        temp=i*j
        while temp<=n:
            b[temp]=min(i,b[temp])
            temp+=i
    return b


def main():
    #l,r,d=map(int,input().split())
    MODT=998244353
    n,k=map(int,input().split())
    step=[]
    for i in range(k):
        l,r=map(int,input().split())
        step.append([l,r])
    dp=[0 for i in range(n*2+2)]
    dp[1]=1
    dp[2]=-1
#    print(step)
    for i in range(1,n+1):
  #      print(dp)
        dp[i]+=dp[i-1]
        dp[i]%=MODT
        for j in range(k):
            dp[i+step[j][0]]+=dp[i]%MODT
            dp[i+step[j][1]+1]-=dp[i]%MODT
 #   print(dp)
  #  print(dp)
    print(dp[n]%MODT)






if __name__ == "__main__":

    main()


Measured memory_bytes: 101656
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int sz = 1e7+5;
ll int arr[sz]={0},arr1[sz]={0},arr2[sz]={0};
//ll int arr[100][100]= {0};
int prime[10005]= {0};
//vector <ll int> vec,vec1,vec2;
vector<string> vec,vec1;
vector<int> edges[10000];
set <char> st;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
map<string, string> mp;

int main()
{
    //fastio;
    int n;
    cin>>n;

    if(n%2==0)
        cout<<"-1\n";
    else
    {

        int rem = 0,m;
        for(int i=1;i<=1e6;i++)
        {
            ll int k = rem*10+7;

            rem = k%n;
            if(rem==0)
            {
                m = i;
                break;
            }

        }

        if(rem!=0)
            cout<<"-1\n";
        else
            cout<<m<<endl;
    }
}


Measured memory_bytes: 3876
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int t=min(n,1000);
		int a,b,cd;
		int ans=0;
		for(int a=0;a<=t;a++)
		{
			for(int b=0;b<=t;b++)
			{
				if(a+b>n)continue;
				cd=n-a-b;
				if(cd<0)continue;
				if(cd>2000)continue;
				if(cd<=1000)ans+=cd+1;
				else ans+=2001-cd;//1000-(cd-1000)+1
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <utility>
#include <string>

using namespace std;

int ar[2000000];

void up(int r, int l1, int l2, int q, int v){
	if(q<l1||q>l2)return;
	if(l1==l2){
		ar[r] = v;
		return;
	}
	int m = (l1+l2)/2;
	up(r<<1,l1,m,q,v);
	up((r<<1)+1,m+1,l2,q,v);
	ar[r] = max(ar[r<<1],ar[(r<<1)+1]);
}

int qu(int r, int l1, int l2, int q1, int q2){
	if(q1>l2||q2<l1)return -1;
	if(q1<=l1&&q2>=l2)return ar[r];
	int m = (l1+l2)/2;
	return max(qu(r<<1,l1,m,q1,q2), qu((r<<1)+1,m+1,l2,q1,q2));
}

typedef pair<int,int> ii;

const int MOD = 998244353;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	vector <ii> mv(n);
	for(int i=0;i<n;i++){
		cin>>mv[i].first>>mv[i].second;
	}
	sort(mv.begin(),mv.end());
	int dp[n+1];
	dp[n] = 1;
	dp[n-1] = 2;
	up(1,0,n-1,n-1,n);
	int l1,l2,m,ne;
	for(int i=n-2;i>=0;i--){
		if(mv[i].second+mv[i].first<=mv[i+1].first){
			dp[i] = (dp[i+1]*2)%MOD;
			up(1,0,n-1,i,i+1);
		}
		else{
			l1 = i+1;
			l2= n-1;
			while(l1<l2){
				m = (l1+l2+1)/2;
				if(mv[m].first<mv[i].second+mv[i].first)l1 = m;
				else l2 = m-1;
			}
			ne = qu(1,0,n-1,i+1,l1);
			up(1,0,n-1,i,ne);
			dp[i] = (dp[i+1]+dp[ne])%MOD;
		}
	}
	cout<<dp[0]<<endl;
	
	return 0;
}

Measured memory_bytes: 6656
#include<iostream>

using namespace std;

int main() {
    int A, B;

    cin >> A >> B;

    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

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

using namespace std;

int main() {

	int N;//人数
	int K;//初期ポイント
	int Q;//問題数

	cin >> N;
	cin >> K;
	cin >> Q;
	vector<int> A(Q);
	vector<int> score(N,0);

	for (int i = 0; i < Q; i++)
	{
		cin >> A[i];
		score[A[i]-1] += 1;//スコアが減らなかった人
		
	}

	for (int i = 0; i < N; i++)
	{
		if (score[i] + K - Q > 0)
		{
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <queue>
#include <algorithm>
#define INF (1<<27)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
struct State {
	int x,y,l,r,o,cost;
	State(int _x,int _y,int _l,int _r,int _o,int _cost) {
		x=_x,y=_y,l=_l,r=_r,o=_o,cost=_cost;
	}
	bool operator >(const State& S) const {
		return (this->cost)>S.cost;
	}
};
int W,H,f,m,o,mp[10][10],cost[10][10][10][10][51];
int main() {
	while(scanf("%d %d",&W,&H),W) {
		fill((int*)cost,(int*)(cost+10),INF);
		scanf("%d %d %d",&f,&m,&o);
		rep(y,H)rep(x,W) {
			scanf("%d",&mp[x][y]);
		}
		if(o<2) {printf("NA\n"); continue;}
		priority_queue<State,vector<State>,greater<State> > Q;
		rep(x,W) {
			int ncost=0,no=o-1;
			if(mp[x][0]<0)ncost-=mp[x][0];
			else no=min(m,no+mp[x][0]);
			cost[x][0][x][x][no]=ncost;
			Q.push(State(x,0,x,x,no,ncost));
		}
		int ans=INF;
		while(!Q.empty()) {
			State S(Q.top());Q.pop();
			if(S.o==0) continue;
			if(S.o==1&&S.y<(H-1))continue;
			if(S.y==(H-1)){ans=S.cost;break;}
			if(cost[S.x][S.y][S.l][S.r][S.o]<S.cost)
				continue;
			if(S.x>0) {
				int no=S.o-1,ncost=S.cost,nl=S.l;
				if((S.x-1)<S.l) {
					if(mp[S.x-1][S.y]<0)ncost-=mp[S.x-1][S.y];
					else no=min(m,no+mp[S.x-1][S.y]);
					nl--;
				}
				if(cost[S.x-1][S.y][nl][S.r][no]>ncost) {
					cost[S.x-1][S.y][nl][S.r][no]=ncost;
					Q.push(State(S.x-1,S.y,nl,S.r,no,ncost));
				}
			}
			if(S.x<(W-1)) {
				int no=S.o-1,ncost=S.cost,nr=S.r;
				if((S.x+1)>S.r) {
					if(mp[S.x+1][S.y]<0)ncost-=mp[S.x+1][S.y];
					else no=min(m,no+mp[S.x+1][S.y]);
					nr++;
				}
				if(cost[S.x+1][S.y][S.l][nr][no]>ncost) {
					cost[S.x+1][S.y][S.l][nr][no]=ncost;
					Q.push(State(S.x+1,S.y,S.l,nr,no,ncost));
				}
			}
			if(S.y<(H-1)) {
				int no=S.o-1,ncost=S.cost;
				if(mp[S.x][S.y+1]<0)ncost-=mp[S.x][S.y+1];
				else no=min(m,no+mp[S.x][S.y+1]);
				if(cost[S.x][S.y+1][S.x][S.x][no]>ncost) {
					cost[S.x][S.y+1][S.x][S.x][no]=ncost;
					Q.push(State(S.x,S.y+1,S.x,S.x,no,ncost));
				}
			}
		}
		if(ans>f)printf("NA\n");
		else printf("%d\n",ans);
	}
}

Measured memory_bytes: 3164
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int h,n;
	int sum=0;
	cin >> h >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	if(h-sum <= 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
const int MAX=1e5+10;
char a[55][55];
int b[4][2]={0,1,0,-1,1,0,-1,0};
int mp[55][55];
struct lll
{
    int x,y,bushu;
}s;
int main()
{
    int n,m;
    memset(mp,0,sizeof(mp));
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i]+1;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
                sum++;
        }
    }
    sum=n*m-sum;
    s.x=1;
    s.y=1;
    s.bushu=1;
    queue<lll>TM;
    mp[1][1]=1;
    TM.push(s);
    while(!TM.empty())
    {
        if(TM.front().x==n&&TM.front().y==m)
            break;
        for(int i=0;i<4;i++)
        {
            s.x=TM.front().x+b[i][0];
            s.y=TM.front().y+b[i][1];
            s.bushu=TM.front().bushu+1;
            if(s.x>0&&s.x<=n&&s.y>0&&s.y<=m&&a[s.x][s.y]!='#'&&mp[s.x][s.y]==0)
            {
                mp[s.x][s.y]=1;
                TM.push(s);
            }
        }
        TM.pop();
    }
    if(mp[n][m]==0)
        cout<<"-1"<<endl;
    else
        cout<<sum-TM.front().bushu<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using llint = long long int;
using namespace std;

int main() {
    fastIO;
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    int tap = 1;
    while (true) {
        if (b <= tap)
            break;
        tap = tap - 1 + a;
        cnt++;
    }
    // cout << tap << endl;
    cout << cnt << endl;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n, m;
	cin >> n >> m;
	priority_queue<int> pq;
	rep(i,n) {
		int a;
		cin >> a;
		pq.push(a);
	}

	rep(i,m) {
		int a = pq.top();
		pq.pop();
		pq.push(a / 2);
	}
	long long ans = 0;
	rep(i,n){
		int a = pq.top();
		pq.pop();
		ans += a;
	}
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 892
N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())
	A[i] -= 1
	B[i] -= 1
inf = 123456789123456789123456789
dist = [ -inf ] * N
dist[0] = 0
bounded = True
for i in range(max(2 * N - 3, 4)):
	for j in range(M):
		if dist[B[j]] < dist[A[j]] + C[j]:
			dist[B[j]] = dist[A[j]] + C[j]
			if B[j] == N - 1 and i >= N:
				bounded = False
if not bounded:
	print("inf")
else:
	print(dist[N - 1])

Measured memory_bytes: 3188
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    a: [usize; n]
    }
    let mut ans = a[0];
    for i in 0..n {
        ans = gcd(&ans, &a[i]);
    }
    println!("{}", ans);

}

// O(log(N))
fn gcd(a: &usize, b: &usize) -> usize {
    let (mut x, mut y) = if a < b { (*b, *a) } else { (*a, *b) };
    let mut r = x % y;
    while r != 0 {
        x = y;
        y = r;
        r = x % y;
    }
    y
}


Measured memory_bytes: 3744
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)
    {
        int tem;
        tem = a;
        a = b;
        b = tem;

    }
    int i;
    for(i = 0;i < a;i++)
        printf("%d",b);
    printf("\n");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  int acNum = 0;
  int waNum = 0;
  cin >> n >> m;
  vector<bool> ac(n+1);
  vector<int> wa(n+1);
  for(int i = 0; i < n; i++){
    ac.at(i) = false;
    wa.at(i) = 0;
  }
  for(int i = 0; i < m; i++){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(s == "AC" && !(ac.at(p))){
      ac.at(p) = true;
      acNum++;
      waNum += wa.at(p);
    }else{
      wa.at(p) += 1;
    }
  }
  cout << acNum << " " << waNum << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i,M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> ans(N, -1);
    ans[0] = 0;
    queue<int> que;
    que.emplace(0);
    while(!que.empty()) {
        int p = que.front(); que.pop();
        for(int v : G[p]) {
            if(ans[v] == -1) {
                ans[v] = p;
                que.emplace(v);
            }
        }
    }
    rep(i,N) {
        if(ans[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    repi(i,1,N) {
        cout << ans[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10156
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<assert.h>

typedef long long ll;

int main()
{
    int a = 0;
    char s[101] = { 0 };
    gets(s);
    int len = strlen(s);

    for (size_t i = 0; i < len / 2; i++)
    {
        a += s[i] != s[len - i - 1];
    }
    printf("%d", a);

    return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    vector<int> answer(N, 0);

    for (int i = 0; i < Q; i++) { 
        int Ai;
        cin >> Ai;
        answer[Ai - 1]++;
    }

    for (int i = 0; i < N; i++) {
        int score = K - (Q - answer[i]);
        if (score > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
w = input()
double_set = set()
double_set.add(w)
finish_str = w[-1]

for i in range(1, n):
    w = input()
    if w not in double_set and w[0] == finish_str:
        double_set.add(w) 
        finish_str = w[-1]
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 9120
n,m=map(int,input().split())
from collections import defaultdict
a=list(map(int,input().split()))
dic={i:[2,5,5,4,5,6,3,7,6][i-1]for i in range(1,10)}
s={}
for i in a:
    if dic[i] in s:
        s[dic[i]]=max(s[dic[i]],i)
    else:
        s[dic[i]]=i
ok=list(s.items())#hon,digit
dp=[-float('inf')]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for h,d in ok:
        if h<=i:
            dp[i]=max(dp[i],dp[i-h]+1)
from operator import itemgetter as it 
ok.sort(reverse=1,key=it(1))
ans=''
now=n
keta=dp[n]
while keta>1:
    for h,d in ok:
        if now>h and dp[now]==dp[now-h]+1:
            ans+=str(d);now-=h;keta-=1;break
print(ans+str(s[now]))

Measured memory_bytes: 74500
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
#define n (int)(1e6)
signed main()
{
    int x, flag = 0;
    cin >> x;
    vb sieve(n + 1, true);
    for (int i = 2; i * i <= n; i++)
    {
        if (sieve[i])
        {
            for (int j = i * i; j <= n; j += i)
                sieve[j] = false;
        }
    }
    for (int i = 2; i <= n; i++)
    {
        if (sieve[i])
        {
            if (i >= x)
            {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
var
	N,i,j:Longint;
	ans:int64;
begin
	read(N);
	j:=round(sqrt(N));
	if j*j>N then dec(j);
	for i:=1 to j do inc(ans,(N div i)*(N div i+1)*i-i*i*i);
	writeln(ans);
end.

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

int main() {
  char s[3][5];
  scanf("%s", s[0]);
  scanf("%s", s[1]);
  if(s[0][0]==s[1][2] && s[1][0]==s[0][2] && s[0][1]==s[1][1])
    puts("YES");
  else puts("NO");
  
  return 0;
}


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

a=sorted(a)
m=max(a)
dp=[0]*(m+1)
d={}
cnt=0
for i in range(n):
    b=a[i]
    if b in d:
        d[b]+=1
        continue
    else:
        d[b]=1
    j=b
    while b<=m+b:
        if b>m:
            break
        dp[b]+=1
        b+=j
        


for i in a:
    if dp[i]==1 and d[i]==1:
        cnt+=1

print(cnt)

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

int main() {
    ll N, M;
    cin >> N >> M;
    if (N == 1) N = 3;
    if (M == 1) M = 3;
    cout << (N-2) * (M-2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if(s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }

    if(n < 26) {
        for(char c = 'a'; c <= 'z'; c++) {
            int k = 0;
            rep(i, n) {
                if(s[i] == c) {
                    k++;
                }
            }
            if(k == 0) {
                s += c;
                cout << s << endl;
                return 0;
            }
        }
    }
    else if(n == 26) {
        for(int i = 25; i >= 1; i--) {
            if(s[i] > s[i-1]) {
                string t = s.substr(i, 26-i);
                int m = t.size();
                char q;
                for(int j = m-1; j >= 0; j--) {
                    if(t[j] > s[i-1]) {
                        q = t[j];
                        break;
                    }
                }

                cout << s.substr(0, i-1) + q << endl;
                return 0;            
            }
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	static int V = 100005;
	static boolean[] visited = new boolean[V*2];
	static ArrayList<LinkedList<Integer>> _to;
	static int[] cnt;
	static void dfs(int v) {
		if (visited[v]) {
			return;
		}
		visited[v]=true;
		cnt[v/V]++;
		for (Integer u: _to.get(v)) {
			dfs(u);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		_to = new ArrayList<LinkedList<Integer>>();
		for (int i=0;i<V*2;i++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			_to.add(tmp);
		}
		for (int i=0;i<N;i++) {
			int x=Integer.parseInt(sc.next());
			int y=Integer.parseInt(sc.next());
			y+=V;
			_to.get(x).add(y);
			_to.get(y).add(x);
		}
		long ans = 0L;
		for (int i=0;i<2*V;i++) {
			if (visited[i]) {
				continue;
			}
			cnt = new int[2];
			dfs(i);
			ans += (long)cnt[0]*cnt[1];
		}
		ans-=N;
		System.out.println(ans);
	}
}

Measured memory_bytes: 90184
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

// ll calc(const ll x) {
//     if (x % 2 == 0) {
//         ll cnt = x / 2;
//         if (cnt % 2 == 0) {
//             return x;
//         } else {
//             return x ^ 1;
//         }
//     } else {
//         ll cnt = (x + 1) / 2;
//         return cnt % 2;
//     }
// }

ll calc(const ll x) {
    if (x % 4 == 0) return x;
    else if (x % 4 == 1) return 1LL;
    else if (x % 4 == 2) return x ^ 1LL;
    else return 0LL;
}

ll solve(const ll A, const ll B) {
    ll v_a = calc(A - 1);
    ll v_b = calc(B);
    return v_a ^ v_b;
}

int main(void) {
    ll A, B;
    cin >> A >> B;

    cout << solve(A, B) << endl;

    return 0;
}


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

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

int T, N;
vector<int> K, L, R, G;
vector<pi> lG, rG;
priority_queue<pi> Q;

void input_init(void) {
	cin >> N;
	K.clear();	K.resize(N);
	L.clear();	L.resize(N);
	R.clear();	R.resize(N);
	G.clear();	G.resize(N, 0);
	lG.clear();	rG.clear();
	for (int i = 0; i < N; ++i) {
		cin >> K[i] >> L[i] >> R[i];
		if (L[i] > R[i]) {
			lG.push_back(make_pair(K[i], i));
			G[i] = -1;
		}
		else if (L[i] < R[i]) {
			if (K[i] < N) {
				rG.push_back(make_pair(K[i] + 1, i));
				G[i] = 1;
			}
			else {
				lG.push_back(make_pair(K[i], i));
				G[i] = -1;
			}
		}
	}
	sort(lG.begin(), lG.end());
	sort(rG.begin(), rG.end(), greater<pi>());
}

void check_data_l(void) {
	if (lG.size() == 0)
		return;
	while (!Q.empty())
		Q.pop();
	int day = lG.back().first;
	for (int i = day; i >= 1; --i) {
		while (lG.size() > 0) {
			if (lG.back().first != i)
				break;
			int id = lG.back().second;
			lG.pop_back();
			Q.push(make_pair(L[id] - R[id], id));
		}
		if (!Q.empty()) {
			int id = Q.top().second;
			Q.pop();
			G[id] = -1;
		}
	}
	while (!Q.empty()) {
		int id = Q.top().second;
		Q.pop();
		G[id] = 2;
	}
}

void check_data_r(void) {
	if (rG.size() == 0)
		return;
	while (!Q.empty())
		Q.pop();
	int day = rG.back().first;
	for (int i = day; i <= N; ++i) {
		while (rG.size() > 0) {
			if (rG.back().first != i)
				break;
			int id = rG.back().second;
			rG.pop_back();
			Q.push(make_pair(R[id] - L[id], id));
		}
		if (!Q.empty()) {
			int id = Q.top().second;
			Q.pop();
			G[id] = 1;
		}
	}
	while (!Q.empty()) {
		int id = Q.top().second;
		Q.pop();
		G[id] = -2;
	}
}

void solve(void) {
	check_data_l();
	check_data_r();
}

ll calcu(void) {
	ll sum = (ll)0;
	for (int i = 0; i < N; ++i) {
		if (G[i] < 0 && G[i] >= -2)
			sum += L[i];
		else if (G[i] <= 2 && G[i] >= 0)
			sum += R[i];
	}
	return sum;
}

int main(void) {
	cin >> T;
	for (int i = 0; i < T; ++i) {
		input_init();
		solve();
		ll ans = calcu();
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 8304
n = int(input())
s = input()
ans = 0
for i in range(1000):
  i = str(i).zfill(3)
  flag = 0
  for l in range(n):
    if s[l] == i[flag]:
      flag += 1
      if flag == 3:
        ans += 1
        break
print(ans)

Measured memory_bytes: 40940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c=0;
  cin>>n>>m;
  set<int> se;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    if(a==1){
      se.insert(b);
      c++;
    }
    if(b==n){
      se.insert(a);
      c++;
    }
  }
  cout<<(c==se.size()?"IMPOSSIBLE":"POSSIBLE");
}

Measured memory_bytes: 9600
/*
 * atcoder/abc109_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

ll N;
vector<ll> X, D;
void solve() {
  ll x;
  cin >> N >> x;
  X.push_back(x);
  loop(n,0,N) {
    cin >> x;
    X.push_back(x);
  }
  N++;
  sort(X.begin(), X.end());
  loop(n,0,N-1) {
    D.push_back(X[n+1] - X[n]);
  }
  ll ans = 0;
  for (auto&& d: D) {
    ans = gcd(ans, d);
  }
  cout << ans << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


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

void pass(){
    cout << "Yes" << endl;
}

void fail(){
    cout << "No" << endl;
}

int main()
{
    int n, a, b;
    string str;
    cin >> n >> a >> b >> str;

    int k = a + b;

    int cb = 0;
    int cp = 0;

    for(int i = 0; i < n; i++){
        if(str[i] == 'a'){
            if(cp < k){
                pass();
                cp++;                
            }else{
                fail();
            }
        }else if(str[i] == 'b'){
            if(cb < b && cp < k){
                pass();
                cb++;
                cp++;
            }else{
                fail();
            }
        }else{
            fail();
        }

    }
    
}

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

using namespace std;
map<string,int> mp;
map<string,int>::iterator itr;

int main()
{
    //freopen("in.txt", "r", stdin);
    int n, q, val;
    string key,L,R;
    cin>>n;
    while(n--){
        cin>>q;
        switch (q)
        {
            case 0:
                cin>>key>>val;
                //mp.insert(make_pair(key,val));
                mp[key]=val;
                break;

            case 1:
                cin>>key;
                itr=mp.find(key);
                if(itr!=mp.end()) cout<<itr->second<<endl;
                else cout<<0<<endl;
                break;
            case 2:
                cin>>key;
                mp.erase(key);
                break;
            case 3:
                cin>>L>>R;

                map<string,int>::iterator end,it;
                it=mp.lower_bound(L);
                end=mp.upper_bound(R);
                for(;it!=end;it++)
                    cout<<(*it).first<<" "<<(*it).second<<endl;
                break;
        }
    }
    return 0;
}



Measured memory_bytes: 27724
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <stack>
#include <map>
#include <unordered_map>
#include <climits>
using namespace std;
const int INF = 1e9;
#define ll long long
#define int ll
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define testcase \
    int t;       \
    cin >> t;    \
    while (t--)
#define pb push_back
#define endl "\n"
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define deb4(x, y, z, w) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << " | " << #w << ": " << w << endl
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(a) int((a).size())
#define pii pair<int, int>
#define fi first
#define se second
#define ld long double
#define vii vector<int>
#define all(v) v.begin(), v.end()
#define prec(n) fixed << setprecision(n)
const int MOD = (int)1e9 + 7;
const int MOD2 = 1007681537;
const ll LINF = (ll)1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-12;
inline ll gcd(ll a, ll b)
{
    ll r;
    while (b)
    {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline ll fpow(ll n, ll k, int p = MOD)
{
    ll r = 1;
    for (; k; k >>= 1)
    {
        if (k & 1)
            r = r * n % p;
        n = n * n % p;
    }
    return r;
}
template <class T>
inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; }
template <class T>
inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; }
inline void addmod(int &a, int val, int p = MOD)
{
    if ((a = (a + val)) >= p)
        a -= p;
}
inline void submod(int &a, int val, int p = MOD)
{
    if ((a = (a - val)) < 0)
        a += p;
}
inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline void get_arr(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cin >> arr[i];
}
inline void print_arr(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}

int32_t main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    get_arr(arr,n);
    int dp[n];
    // memset(dp,1e9,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        dp[i]=INF;
    }
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    // print_arr(dp,n);
    int a;
    for(int i=2;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j<0)
            {
                break;
            }
            a=abs(arr[i]-arr[i-j])+dp[i-j];
            // deb4(i,j,dp[i],a);
            dp[i]=min(dp[i],a);
        }
    }
    // print_arr(dp,n);
    cout<<dp[n-1]<<endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[100100];

int main() {
    li n;
    cin >> n;
    rin{cin >> a[i];}

    li sign = 0;
    li prev = a[0];
    li res = 0;
    repp(i, 1, n) {
        if (a[i] == prev)continue;
        if (sign == 0) {
            if (a[i] > prev)sign = 1;
            else sign = -1;
        } else if (sign == 1) {
            if (a[i] < prev) {
                sign = 0;
                res++;
            } else {}
        } else {
            // sign=-1
            if (a[i] > prev) {
                sign = 0;
                res++;
            } else {}
        }
        prev = a[i];
    }
    cout << res + 1 << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {

    int N;
    cin >> N;

    int cnt_a = 0, cnt_b = 0, cnt_ab = 0;
    int cnt_ab_string = 0;
    
    string s;

    for (int i = 0; i < N; i++) {
        cin >> s;
        for (int k = 0; k < s.size()-1; k++) {
            if (s[k] == 'A' and s[k+1] == 'B')
                cnt_ab++;
        }
        if (s[0] == 'B') cnt_b++;
        if (s[s.size() - 1] == 'A') cnt_a++;
        if (s[0] == 'B' and s[s.size() - 1] == 'A') cnt_ab_string++;
    }
    
    if (cnt_a != 0 and cnt_a == cnt_ab_string and cnt_b == cnt_ab_string)
        cout << cnt_ab + cnt_ab_string - 1 << '\n';
    else
        cout << cnt_ab + min(cnt_a, cnt_b) << '\n';
}



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

int main() {
  uint32_t K = 0, S = 0;
  std::cin >> K >> S;

  uint32_t count = 0;
  for (size_t X = 0; X <= K; X++) {
    for (size_t Y = 0; Y <= K; Y++) {
      if (S < X + Y) continue;

      uint32_t Z = S - (X + Y);
      if (Z <= K) count++;
    }
  }

  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int, int> P;
Int m, n, i, j, k, a, b, c, d;
main()
{
    Int l;
    cin >> n >> l;
    int a[200],ans = 0;
    for( int i = 0; i < n; i++ )
    {
        a[i] = l + i;
        ans += a[i];
    }
    int mi  = 1 << 30;
    for( int i = 0; i < n; i++ )
    {
        mi = min( mi, abs(a[i] ));
    }
    if( ans > 0 )    ans -= mi;
    else ans += mi;
    cout << ans << endl;
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

const int LIM = 1e5 + 5;
const ll INF = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, w;
  cin >> n >> w;
  V<pii> item(n);
  REP(i, n) cin >> item[i].fi >> item[i].se;
  VV<ll> dp(n + 1, V<ll>(LIM, INF));
  dp[0][0] = 0;
  REP(i, n) REP(j, LIM) if (dp[i][j] < INF) {
    MIN(dp[i + 1][j], dp[i][j]);
    MIN(dp[i + 1][j + item[i].se], dp[i][j] + item[i].fi);
  }
  REPD(i, LIM) if (dp[n][i] <= w) {
    cout << i << endl;
    return 0;
  }
  assert(0);
}


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

struct Node{
  int key;
  struct Node *a;
  struct Node *b;
  struct Node *c;
};
typedef struct Node * Nodepointer;

Nodepointer root,nil;

void insert(int i){
  Nodepointer x = root;
  Nodepointer y = nil; /*parent*/
  Nodepointer z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = i;
  z->b = nil;
  z->c = nil;

  while(x != nil){
    y = x;
    if(x->key > z->key) x = x->b;
    else x = x->c;
  }

  z->a = y;

  if(y == nil) root = z;
  else{
    if(y->key > z->key) y->b = z;
    else y->c = z;
  }

}

void pre(Nodepointer x){
    if(x == nil) return;
    printf(" %d",x->key);
    pre(x->b);
    pre(x->c);
}


void in(Nodepointer x){
    if(x == nil) return;
    in(x->b);
    printf(" %d",x->key);
    in(x->c);
}



int main(){
  int n,i,num;
  char ch[20];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",&ch);
    if(ch[0] == 'i'){
      scanf("%d",&num);
      insert(num);
    }
    else if(ch[0] == 'p'){
      in(root);
      printf("\n");
      pre(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int n, k, q, tmp;
    cin >> n >> k >> q;
    vector<long long> a(n, k - q);
    for(int i = 0; i < q; i++){
        cin >> tmp;
        a[tmp-1]++;
    }
    for(int i = 0;  i < n; i++){
        if(a[i]>0){
            cout << "Yes" <<endl;
        }else{
            cout <<"No"<<endl;
        }
    }
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s;
  cin >> s;
  vector<int> v(26);
  for (char c : s) ++v[c - 'a'];
  for (int i = 0; i < 26; ++i) {
    if (v[i] == 0) {
      cout << char(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}



Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            B();
        }

        static void B()
        {
            var KS = ReadSplitInt();
            var ans = 0;
            for (var X = 0; X <= KS[0]; X++)
            {
                for (var Y = 0; Y <= KS[0]; Y++)
                {
                    var Z = KS[1] - (X + Y);
                    if (Z >= 0 && Z <= KS[0] && X + Y + Z == KS[1])
                        ans++;
                }
            }
            Println(ans);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static IList<string> ReadSplit() => Read().Split().ToList();
        static IList<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();

        static void Print(object value = null) => Console.Write(value.ToString());
        static void Println(object value = null) => Console.WriteLine(value.ToString());
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

using namespace std;

typedef long long ll;

int main(){
    int n;
    long long x[99999];
    cin >> n;
    for(int a = 0; a < n; a++)cin >> x[a];
    sort(x, x+n);
    long long ans = 0;
    int a = 0; int b = n-1;
    ans += x[b]-x[a];
    while(a < b){
        if(a+2 == b){
            ans += max(x[b]-x[a+1], x[b-1]-x[a]);
            break;
        }
        ans += x[b]-x[a+1]+x[b-1]-x[a];
        a++; b--;
    }
    cout << ans << endl;
    return 0;
}

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

long N;
string ans;

int main(void) {

    cin >> N;

    list<long> r;
    do {
        N--;
        r.push_front(N%26);
        N /= 26;
    } while(N > 0);

    for (auto e: r) {
        // if (e == 0) e = 25;
        // else e = e % 26 - 1;
        ans += 'a' + e % 26;
    }

    cout << ans << endl;

    return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
a = LI()
cnt = 0
s = sum(a)
t = 1/(4*m)
s = s*t
for i in range(n):
    if a[i] < s:
        continue
    cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	string s;
	cin >> s;
	bool ok = false;
	for (int i = 0;i < 7;i++) {
		string x = s;
		x.erase(i,s.size()-7);
		if (x == "keyence") {
			ok = true;
		}
	}
	if (ok) cout << "YES";
	else cout << "NO";
	cout << endl;
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())
ans=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        a1=j-i
        a2=abs(x-i)+1+abs(y-j)
        a3=abs(y-i)+1+abs(x-j)    
        d=min(a1,a2,a3)
        ans[d]+=1
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 3444
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()
A = III()

x = defaultdict(int)

for i in range(N):
    x[A[i]] += 1

num = len(x.keys())

if num<=K:
    print(0)
else:
    x2 = list(x.values())
    x2.sort()
    n = num-K
    ans = 0
    for i in range(n):
        ans += x2[i]
    print(ans)

Measured memory_bytes: 93916
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; 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)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  string S, T;
  cin >> S >> T;
  int S_size = S.size();
  int T_size = T.size();

  int min_diff{T_size};

  rep(i, S_size - T_size+1) {
    int diff_cnt {};
    rep(j, T_size) {
      if (S[i+j]!=T[j]) ++diff_cnt;
    }
    mins(min_diff, diff_cnt);
  }
  cout << min_diff << '\n';
}


Measured memory_bytes: 3656