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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;

int N,M;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) {
		cin>>k;
		FOR(j,k) {
			cin>>r;
			uf(i,r+120000);
		}
	}
	FOR(i,N) if(uf[i]!=uf[0]) return _P("NO\n");
	_P("YES\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String stringA = sc.next();
		String stringB = sc.next();
		sc.close();
		int lengthA = stringA.length();	
		boolean match = false;
		char[] chars = new char[lengthA];
		for(int a = 0; a < lengthA; a++){
			chars[a] = stringA.charAt(a);
		}
		for(int move = 0 ; move < lengthA ; move++){
			char[] tmpStringAc = new char[lengthA];
			int inputPoint = 0;
			for(int inputChar = 0 ; inputChar < lengthA ; inputChar++){
				inputPoint = inputChar + move;
				if(inputPoint>=lengthA){
					inputPoint = inputPoint - lengthA;
				}
				tmpStringAc[inputPoint] = chars[inputChar];
			}
			String tmpStringA = new String(tmpStringAc);
			if(tmpStringA.equals(stringB)){
				match = true;
				break;
			}
		}
		System.out.println(match?"Yes":"No");
	}
}

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

string a,b;
int main(){
	cin>>a>>b;
	int i,j,num=0;
	
	for(i=0;i<a.size();i++)
		num=num*10+(a[i]-48);
		
	for(i=0;i<b.size();i++)
		num=num*10+(b[i]-48);
		
	if(sqrt(num)==int(sqrt(num))) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0; 
} 

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

 int main() {
   int l, r; cin>>l>>r;
   int ans=2019;
   // 選ばれた2つの整数i,jの余り同士の掛け算でよい
   // lとrの差が2019以上あるなら、答えは0
   if(r-l>=2019) {
     ans = 0;
   } else {
     for(int i=l; i<=r-1; i++) {
       for(int j=i+1; j<=r; j++) {
         int iMod = i%2019, jMod = j%2019;
         ans=min(ans,(iMod*jMod)%2019);
       }
     }
   }
   cout << ans << endl;
 }


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

using namespace std;
typedef long long ll;

int main() {
    vector<int> a(6);
    for (int i = 1; i <= 5; i++) {
        int x;
        cin >> x;
        a[x] = 1;
    }
    for (int i = 1; i <= 5; i++) {
        if (!a[i]) {
            cout << i;
            break;
        }
    }
}


Measured memory_bytes: 3540
n,k=map(int,input().split())
R,S,P=map(int,input().split())
dic={"s":R,"p":S,"r":P}
t=input()
ans=0
l=[t[i::k] for i in range(k)]
for j in l:
  V=[]
  unit=0
  for i in j:
    if len(V)==0 or V[-1][0]!=i:
      V.append([i,1])
    else:
      V[-1][1] += 1
  for i in V:
    ans+=dic[i[0]]*((i[1]+1)//2)
print(ans)

Measured memory_bytes: 57968
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

#define MAX 25
#define NIL -1
struct Node { int p, l, r; };
Node T[MAX];
int n, D[MAX], H[MAX];

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if (T[u].r != NIL) h1 = setHeight(T[u].r) + 1;
	if (T[u].l != NIL) h2 = setHeight(T[u].l) + 1;
	return H[u] = max(h1, h2);
}

void setDepth(int u,int d) {
	if (u == NIL) return;
	D[u] = d;
	setDepth(T[u].l, d + 1);
	setDepth(T[u].r, d + 1);
}

int findSibling(int u) {
	if (T[u].p == NIL) return NIL;
		if (T[T[u].p].l != u && T[T[u].p].l!=NIL) return T[T[u].p].l;
		if (T[T[u].p].r != u&&T[T[u].p].r != NIL) return T[T[u].p].r;
	return NIL;
}

inline int deg(int u) {
	return (T[u].l != NIL) + (T[u].r != NIL);
}

void print(int u) {
	cout << "node " << u << ": parent = " << T[u].p <<", sibling = "<<findSibling(u)<< ", degree = "<<deg(u)<<", depth = " << D[u] << ", height = "<<H[u];
	cout << ", ";
	if (T[u].p == NIL) cout << "root";
	else {
		if (deg(u) == 0) cout << "leaf";
		else cout << "internal node";
	}
	cout << "\n";
}

int main() {
	int root=0;
	int id = 0;
	int lft, rght;
	cin >> n;
	for (int i = 0; i < n; i++) T[i].p = NIL;
	for (int i = 0; i < n; i++) {
		cin >> id >> lft >> rght;
		T[id].l = lft;
		T[id].r = rght;
		if(lft !=NIL) T[lft].p = id;
		if(rght!=NIL) T[rght].p = id;
	}

	for (int i = 0; i < n; i++) if (T[i].p == NIL) root = i;
	setDepth(root, 0);
	setHeight(root);
	for (int i = 0; i < n; i++) print(i);
}

Measured memory_bytes: 3076
n=int(input())
p1=[list(map(int,input().split())) for _ in range(n)]
p2=[list(map(int,input().split())) for _ in range(n)]
p1=sorted(p1,key=lambda x:x[1])
p1=sorted(p1,key=lambda x:x[0])
p2=sorted(p2,key=lambda x:x[1])
p2=sorted(p2,key=lambda x:x[0])
ans=0
for i in range(n-1,-1,-1):
  pos=-1
  tmp=10**10
  for j in range(len(p2)-1,-1,-1):
    if p1[i][0]>=p2[j][0]:
      break
    else:
      if p1[i][1]<p2[j][1] and p2[j][1]<tmp:
        tmp=p2[j][1]
        pos=j
  if pos!=-1:
    ans+=1
    p2.pop(pos)
print(ans)

Measured memory_bytes: 3064
n, x = map(int, input().split())
index=0
count=0
listM=[]
while index<n:
    m=input()
    listM.append(int(m))
    x-=int(m)
    index+=1
    count+=1

miM=min(listM)
plusA=x//miM
count+=plusA
print(count)


Measured memory_bytes: 3060
from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque([1])
    while len(dq) != 0:
        v = dq.popleft()
        for c in G[v]:
            if d[c] != -1 : continue
            d[c] = d[v] + 1
            dq.append(c)
    for i, x in enumerate(d[1:], start=1):
        print(i, x)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
bfs()

Measured memory_bytes: 8076
#include <iostream>
#include <vector>
#include <cmath>
#define LIM 100002

using namespace std;

bool is_prime(int n) {
	if (n < 2) {
			return false;
	}
	if (n==2||n==3) {
		return true;
	}
	for (int i = 3; i < n; i = i+2) {
		if (n%i==0) {
			return false;
		}
	}
	return true;
}

int main(void) {
	vector<bool> prime(LIM);
	for (int i = 0; i < LIM; i++) {
		prime[i] = true;
	}
	prime[0] = false;
	prime[1] = false;
	for (int i = 2; i <= sqrt(LIM); i++) {
		if (is_prime(i)) {
			for (int j = 2; i*j < LIM; j++) {
				prime[i*j] = false;
			}
		}
	}
	for (int i = LIM; i > 2; --i) {
		if (prime[i]) {
			if(!(prime[(i+1)/2])) {
				prime[i] = false;
			}
		}
	}

	vector<int> data(LIM);
	data[1] = 0;
	for (int i = 3; i < LIM; i = i+2) {
		data[i] = data[i-2];
		if (prime[i]) {
			++data[i];
		}
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int l,r;
		cin >> l >> r;
		if (l != 1) {
			l -= 2;
		}
		cout << data[r]-data[l] << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict
import queue

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

inf = float("inf")
dp = [[inf]*W for _ in range(H)]
if c[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

n = dp[0][0]
for i in range(H-1):
    if c[i][0] == "." and c[i+1][0] == "#":
        n += 1
    dp[i+1][0] = n

m = dp[0][0]
for i in range(W-1):
    if c[0][i] == "." and c[0][i+1] == "#":
        m += 1
    dp[0][i+1] = m

for i in range(1, H):
    for g in range(1, W):
        if c[i-1][g] == "." and c[i][g] == "#":
            dp[i][g] = min(dp[i-1][g]+1, dp[i][g])
        else:
            dp[i][g] = min(dp[i-1][g], dp[i][g])

        if c[i][g-1] == "." and c[i][g] == "#":
            dp[i][g] = min(dp[i][g-1]+1, dp[i][g])
        else:
            dp[i][g] = min(dp[i][g-1], dp[i][g])

print(dp[H-1][W-1])


Measured memory_bytes: 44524
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

vector<int> prime;
bool is_prime[1000010];
void eratosthenes(int n){
	for(int i=0;i<=n;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
			prime.push_back(i);
		}
	}
}

int main(){
	int n;
	cin>>n;
	eratosthenes(1000000);
	int cnt=0;
	int i=0;
	while(cnt<n){
		if(prime[i]%5==1){
			cout<<prime[i];
			cnt++;
			if(cnt<n)cout<<" ";
		}
		i++;
	}
	cout<<endl;
	return 0;
}


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

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

	int n,temp;
	cin>>n;
	int arr[10005]={0};
	for (int i = 1; i < 100; ++i)
	{
		for (int j = 1; j < 100; ++j)
		{
			for (int k = 1; k < 100; ++k)
			{
				temp=i*i+j*j+k*k+i*j+j*k+k*i;
				if(temp<=10000)
					arr[temp]++;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<arr[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3676
/*
    It’s Always Darkest Before the Dawn
                This Time is that Darkness in you Life
                                                            */
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define pb push_back  
#define F first
#define S second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
 
const ll mod=1e9+7,di=998244353,N=3e5+1;
 
bool IsQuery=false; 
ll q=1,a[N];
 
map<int,vector<int>> edge;
map<int,bool> occ;
 
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
void solve(){
	
  	ll n,W;
  	cin>>n>>W;
  	
  	ll w[n],v[n];
  
  	for(int i=0;i<n;i++)
      cin>>w[i]>>v[i];
  	
  	ll dp[W+1]={0};
  
  	for(int i=0;i<n;i++){
    	
      for(int j=W-w[i];j>=0;j--){
        dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
      }
    }
    
  	
  	cout<<dp[W];
  
    return;   
} 
int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    if(IsQuery)
    cin>>q;
 
    for(int i=0;i<q;i++){
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4360
#include<iostream>
using namespace std;
string s,s1; 
int z,minn,maxx;
int main()
{
    cin>>s>>s1;
    if (s.size()>s1.size())
    {
    	z=1;
    	minn=s1.size();
    	maxx=s.size();
    }
    else 
    {
    	z=2;
    	minn=s.size();
    	maxx=s1.size();
    }
    for (int i=0;i<minn;i++)
    cout<<s[i]<<s1[i];
    if (z==1)
    {
    for (int i=minn;i<maxx;i++)
    cout<<s[i];
    }
    if (z==2)
    {
    for (int i=minn;i<maxx;i++)
    cout<<s1[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void)
{

	int n, d;
	cin >> n >> d;
	int sum = 0;
	int count = 0;
	vector<vector<int >> x(n,vector<int>(d));
	int i, t,m;
	int mm = 1;
	for (i = 0; i < n; i++)
	{
		for (t = 0; t < d; t++)
		{
			cin >> x[i][t];
		}
	}
	for (i = 0; i < n; i++)
	{
		
		for (m = i + 1; m < n; m++)
		{
			sum = 0;
			mm = 0;
			for (t = 0; t < d; t++)
			{
				sum =sum+ pow(abs(x[i][t] - x[m][t]), 2);
			}
			while (1)
			{
				if (pow(mm, 2) == sum)
				{
					count++;
					break;
				}
				else if (pow(mm, 2) > sum)
				{
					break;
				}
				mm++;
			}
		}
	}
	cout << count << endl;
	return 0;

}


Measured memory_bytes: 256
N = int(input())

if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(9 + (N-99))
elif N < 10000:
    print(909)
elif N < 100000:
    print(909 + (N-9999))
else:
    print(90909)

Measured memory_bytes: 2940
# まず始めカッコの数を確定させる
N = int(input())
S = input()

hazimekakko = 0
owarikakko = 0
sa = -1
for i in range(len(S)):
    if S[i] == "(":
        hazimekakko += 1
    else:
        owarikakko += 1
    sa = max(sa, owarikakko-hazimekakko)

S = sa*"(" + S

hazimekakko = 0
owarikakko = 0
for i in range(len(S)):
    if S[i] == "(":
        hazimekakko += 1
    else:
        owarikakko += 1
print(S + ")"*(hazimekakko-owarikakko))


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) {
    cout << s << endl;
  } else {
    string s1 = s.substr(0, k) + "...";
    cout << s1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
import math
N, H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]

a_max = max(a for a,b in AB)
B = [b for a,b in AB]
B.sort(reverse=True)

HP = H
ans =0
for b in B:
    if HP<=0:
        print(ans)
        exit()
    if b<a_max:
        break
    HP -=b
    ans+=1

#ans += HP//a_max+ bool(HP%a_max)
ans += math.ceil(HP/a_max)
print(ans)

Measured memory_bytes: 28596
#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Point {
	double x, y, z;
	Point() : x(0), y(0), z(0) {}
	Point(double x, double y, double z) : x(x), y(y), z(z) {}
	const Point operator+(const Point &p) const { return Point(x + p.x, y + p.y, z + p.z); }
	const Point operator-(const Point &p) const { return Point(x - p.x, y - p.y, z - p.z); }
	const double norm2() const { return x * x + y * y + z * z; }
	const double norm() const { return sqrt(norm2()); }
};

struct Dsu {
	vi dsu;
	Dsu(int n) {
		dsu = vi(n);
		rep(i, 0, n) dsu[i] = i;
	}
	int find(int u) {
		if (u == dsu[u]) return u;
		else return dsu[u] = find(dsu[u]);
	}
	bool merge(int u, int v) {
		u = find(u), v = find(v);
		if (u == v) return false;
		dsu[v] = u;
		return true;
	}
};

const double eps = 1e-8;

int main() {
	for (;;) {
		int n; cin >> n; if (!n) break;
		vector<Point> p(n);
		vector<double> r(n);
		rep(i, 0, n)
			cin >> p[i].x >> p[i].y >> p[i].z >> r[i];
		Dsu dsu(n);
		int components = n;
		rep(i, 0, n) rep(j, i + 1, n) {
			double dist = (p[i] - p[j]).norm();
			if (dist < r[i] + r[j] + eps) {
				if (dsu.merge(i, j)) components--;
				//printf("Mer %d %d\n", i, j);
			} else {
				//printf("Sep %d %d\n", i, j);
			}
		}
		vector<pair<double, pair<int, int>>> edges;
		rep(i, 0, n) rep(j, i + 1, n) if (dsu.find(i) != dsu.find(j)) {
			double adddist = (p[i] - p[j]).norm() - r[i] - r[j];
			edges.push_back({ adddist, { i, j } });
		}
		sort(all(edges));
		double ans = 0;
		for (auto edge : edges) {
			if (components == 1) break;
			int u, v;
			tie(u, v) = edge.second;
			if (dsu.find(u) != dsu.find(v)) {
				dsu.merge(u, v);
				ans += edge.first;
				components--;
			}
		}
		cout << fixed << setprecision(3) << ans << endl;
	}
}



Measured memory_bytes: 3300
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}

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

int main(){
    int N, K=1;
    cin >> N;
    int a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
        if(a[i] == K){
            K += 1;
        }
    }
    if(K == 1) cout << "-1" << endl;
    else cout << N - (K-1) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+7,mod=1e9+7;
int read() {
	int x=0,f=1;char s=getchar();
	for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
	for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
	return x*f;
}
char s[N];
int n,tot[30],ans;
int main() {
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n;++i) tot[s[i]-'a']++;
	ans=1;
	for(int i=0;i<26;++i) ans=1LL*ans*(tot[i]+1)%mod;
	cout<<ans-1<<"\n";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{ 
	string s;
	int n;
	cin>>s>>n;
	for(int i=0;i<s.size();i++)
	{
		if(i%n==0)
		cout<<s[i];
	}
	return 0;
}
  

Measured memory_bytes: 256
#include<iostream>
int main()
{
	int a[3000], b[3000];
	int i;
	int t, m;
	int j = 1;
	for ( int i = 1; i <= 3000; ++i )
	{
		    std::cin >> t >> m;
		    if ( t == 0 && m == 0 )
		    {
		    	break;
		    }
		    else
				if ( t <= m )
				{
					a[i] = t, b[i] = m;
					++j;
				}
				else
				{
		            a[i] = m, b[i] = t;
					++j;
	    	    }
		
	}
	for ( int i = 1; i < j; ++i )
	{		

		std::cout << a[i] << " " << b[i] << std::endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

struct UnionFind{
    vector<ll> d;
    UnionFind(ll n): d(n,-1) {}
    ll find(ll x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(d[x] < d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(ll x,ll y){
        return find(x)==find(y);
    }
    ll size(ll x){
        return -d[find(x)];
    }
};

//#define ll long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    vector<ll> b(m);
    for(ll i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }
    vector<ll> ans(m+1);
    ans[m]=n*(n-1)/2;
    UnionFind uf(n);
    for(ll i = 0; i < m; i++) {
        ll ta=a[m-1-i]-1;
        ll tb=b[m-1-i]-1;
        ll dec=abs(uf.size(ta)*uf.size(tb));
        if(uf.same(ta,tb)) dec=0;
        ans[m-i-1]=ans[m-i]-dec;
        uf.unite(ta,tb);
    }
    for(ll i = 0; i < m; i++) {
        cout << ans[i+1] << "\n";
    }

    return 0;
}


Measured memory_bytes: 6964
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  ll l,r;
  cin >> l >> r;
  ll ans=inf;
  for(ll i=l;i<=min(r,l+2018);i++){
    for(ll j=i+1;j<=min(r,l+2018);j++){
      ans=min(ans,(i*j)%2019);
    }
  }
  cout << ans << endl;
return 0;}

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

int main() {
  string S;
  cin >> S;
  long ans = 0;
  for (int i = 0, cnt = 0, b = 0; i < S.size(); i++) {
    if (S.at(i) == 'W') {
      if (b) ans += max(0, i - cnt);
      cnt++;
    } else b = 1;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
int t[5][5];
ll h,a,b,c,d,e;
int ans = 1;
ll mod = 1e9+7;
bool memo[15][15] = {0};
ll func(ll x){
  ll k = 1;
  while(x>1){
    k *= x;
    k %= mod;
    x--;
  }
  return k;
}
int main(){
  ll m,n;
  cin >> n >> m;
  ll ans = 0;
  if(n<m) swap(n,m);
  if(n-1<=m){
    if(m==n-1)  ans = func(n) * func(m) % mod;
    else ans = func(n) * 2 * func(m) % mod;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }
    int count = 0;
    for(int i = 1; i < n-1; i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]){
            count++;
        }
        else if(p[i+1] < p[i] && p[i] < p[i-1]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

using namespace std;

int main(){
   long long a,i,d,e,sisa,tampung,b,c;
   scanf("%lld %lld", &a, &b);
   getchar();
   if(a==0&&b==0){
      c=0;
   }
   else if(a==0 ||b==0){
      if(a==0){
         c=b;
      }
      else{
         c=a;
      }
   }
   else{
      if(a<b){
      tampung=a;
      a=b;
      b=tampung;
   }
   d=a;
   e=b;
   sisa=a%b;
   if(sisa==0){
      sisa=b;
   }
   else{
      while(e%sisa!=0){
     // printf("%d", e);
      tampung=sisa;
      sisa=e%tampung;
      e=tampung;
   }
   }
   c=a*b/sisa;
   }
   
  // printf("%d", sisa);
  // cout<<a<<"  "<<b<<"   "<<sisa<<"lala";
   printf("%lld\n", c);
}

Measured memory_bytes: 256
#include <cstdio>

char a[4][7][8] = 
{
	{
		"aabc",
		"ddbc",
		"efgg",
		"efhh"
	},
	{
		"aabbc",
		"hii.c",
		"h..jd",
		"g..jd",
		"gffee"
	},
	{
		"aabee.",
		"d.b..f",
		"dcc..f",
		"ee.aab",
		"..fd.b",
		"..fdcc"
	},
	{
		"eeffgg.",
		"aab...g",
		"d.b...g",
		"dcc...f",
		"...aabf",
		"...d.be",
		"...dcce"
	}
};

const int N = 1000;
int n;
char s[N][N + 1];

int main() 
{
	scanf("%d", &n);
	if (n == 2) {
		printf("-1\n");
		return 0;
	}
	if (n == 3) {
		printf("%s\n%s\n%s\n", 
				"aa.",
				"..b",
				"..b"
		      );
		return 0;
	}
	int m = 4 + (n & 3);
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < m; ++j) 
			s[i][j] = a[m - 4][i][j];
		for (int j = m; j < n; ++j) s[i][j] = '.';
	}
	for (int t = m; t < n; t += 4) {
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) s[t + i][t + j] = a[0][i][j];
			for (int j = 0; j < t; ++j) s[t + i][j] = '.';
			for (int j = t + 4; j < n; ++j) s[t + i][j] = '.';
		}
	}
	for (int i = 0; i < n; ++i) 
		printf("%s\n", s[i]);
	return 0;
}


Measured memory_bytes: 2632
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

long long power(long long x, long long n, long long mod = 1000000007) {
    if (n == 0) return 1;
    if (n % 2 == 0) return power(x * x % mod, n/2, mod);
    else return x * power(x, n-1, mod) % mod;
}

void solve() {
    int d, n;
    cin >> d >> n;
    if (n == 100) n ++; 
    cout << power(100,d) * n << endl;
}

int main() {
    solve();
    
    return 0;
}

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

int main() {
    ll N, M; cin >> N >> M;
    ll ans;
    if(N>1 && M>1) ans = N*M - 2*M - 2*N + 4;
    else if((N==1 && M>1) || (M==1 && N>1)) ans = N*M - 2;
    else ans = 1;
    cout << ans << endl;    
}

Measured memory_bytes: 256
n = int(input())
cnt = [0] * 4
for _ in range(n):
    tmp = input()
    if tmp == 'AC':
        cnt[0] += 1
    elif tmp == 'WA':
        cnt[1] += 1
    elif tmp == 'TLE':
        cnt[2] += 1
    else:
        cnt[3] += 1

j_txt = ['AC', 'WA', 'TLE', 'RE']

for i in range(4):
    print(j_txt[i] + ' x ' + str(cnt[i]))

Measured memory_bytes: 9148
import sys

def dfs(node, sink, f, used, Edge): #最大流量fを返す
    if node == sink: return f
    used[node] = True
    for i, e in enumerate(Edge[node]):
        nextnode, nextcap, edgeIndex = e
        if not used[nextnode] and nextcap > 0: #次の行先が未探索で容量がある場合
            d = dfs(nextnode, sink, min(f, nextcap), used, Edge) 
            if d > 0:
                Edge[node][i][1] -= d
                Edge[nextnode][edgeIndex][1] += d
                return d
    return 0

def MF(): #頂点数V、辺数Eのグラフの最大流を返す
    input = sys.stdin.readline
    V, E = map(int, input().split())
    Edge = [[] for _ in range(V)]
    edgeSize = [0] * V
    for _ in range(E): #frmからtへ容量capの辺の入力を受ける(0-index)
        frm, t, cap = map(int, input().split())
        Edge[frm].append([t, cap, edgeSize[t]])
        Edge[t].append([frm, 0, edgeSize[frm]])
        edgeSize[t] += 1
        edgeSize[frm] += 1

    maxFlow = 0
    while True:
        visited = [False for _ in range(V)]
        f = dfs(0, V - 1, 1000000000, visited, Edge)
        if f == 0: break
        maxFlow += f
    print(maxFlow)
    
    return 0

if __name__ == "__main__":
    MF()


Measured memory_bytes: 5788
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        while(true) {
            if(isPrime(x)) break;
            x++;
        }
        System.out.println(x);
    }
    
    static boolean isPrime(int num) {
        if(num < 2) return false;
        else if(num == 2) return true;
        else if(num % 2 == 0) return false;
        
        double sqrtNum = Math.sqrt(num);
        for(int i = 3; i <= sqrtNum; i+=2) {
            if(num % i == 0) {
                return false;
            }
        }
        
        return true;
    }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        char[] sarr = S.toCharArray();
        char[] tarr = T.toCharArray();
        String ans = "";
        for (int i = 0; i < N; i++) {
            ans += sarr[i];
            ans += tarr[i];
        }

        System.out.println(ans);

    }
}

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

typedef long double ld;
#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);         
#endif
}

const int mod = 1e9+7;
const int maxn = 1e6+5;

void solve(){  
	int n; cin>>n;
	int a[n], sum=0; mii mp;
	rep(i, 0, n){
		cin>>a[i]; sum+=a[i]; mp[a[i]]++;
	}
	int q; cin>>q;
	while(q--){
		int x, y; cin>>x>>y;
		sum -= x*mp[x]; sum += y*mp[x]; 
		mp[y] += mp[x]; mp[x] = 0;
		cout<<sum<<"\n";
	}
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// io();
    //cout<<setprecision(100);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }

    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif

    return 0;
}


Measured memory_bytes: 10348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcount(x);};
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n; cin >> n;
    vector<int> x(n),y(n),p(n);
    rep(i,n) cin >> x[i] >> y[i] >> p[i];
    vl ans(n+1,linf);
    vvl tate(1<<n,vl(n,linf)), yoko(1<<n,vl(n,linf));
    rep(bit,1<<n){
        rep(i,n){
            chmin(tate[bit][i], abs(x[i]));
            chmin(yoko[bit][i], abs(y[i]));
            rep(j,n){
                if(bit>>j & 1){
                    chmin(tate[bit][i], abs(x[i] - x[j]));
                    chmin(yoko[bit][i], abs(y[i] - y[j]));
                }
            }
        }
    }
    rep(bit,1<<n){
        int pcnt = pcount(bit);
        for(int sub=bit; sub>=0; sub--){
            sub &= bit;
            ll sum = 0;
            rep(i,n){
                sum += min(tate[sub][i], yoko[bit-sub][i]) * p[i];
            }
            chmin(ans[pcnt], sum);
        }
    }
    rep(i,n+1) cout << ans[i] << "\n";
}

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

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ret;
    int ret2;
    int ans = 0;
    for (int i=0; i*r<=n; i++){
        ret = n - i*r;
        for (int x=0; x*g<=ret; x++){
            ret2 = ret - x*g;
//            cout << i << " " << x << " " << (n - i*r - x*g)/b << " " << ret2%b << endl;
            if (ret2%b==0 || ret2==0){
                ans+=1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import *;L=int(input());S=bin(L);N=len(S)-2;print(N,N+N+S.count("1")-3)
for i,j in product(range(1,N),[0,1]):
 print(i,-~i,j*2**~-i)
 if int(S[-i])&j:L^=2**~-i;print(i,N,L)

Measured memory_bytes: 3064
H,W = map(int,input().split())
src = [list(map(int,input().split())) for i in range(H)]

odd = src[0][0]%2
prev = (0,0)
ans = []
for i in range(H):
    if i%2==0:
        for j in range(W):
            if (i,j) == (0,0):
                continue
            if odd:
                ans.append((prev[0]+1, prev[1]+1, i+1, j+1))
                if src[i][j]%2:
                    odd = False
            elif src[i][j]%2:
                odd = True
            prev = (i,j)
    else:
        for j in range(W-1,-1,-1):
            if odd:
                ans.append((prev[0]+1, prev[1]+1, i+1, j+1))
                if src[i][j]%2:
                    odd = False
            elif src[i][j]%2:
                odd = True
            prev = (i,j)

print(len(ans))
for row in ans:
    print(*row)

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

int main()
{
  int N, B[10000], res;

  cin >> N;
  for (int i = 0; i < N - 1; i++) cin >> B[i];

  res = B[0];
  for (int i = 0; i < N - 1; i++)
    res += min(B[i], B[i + 1]);
  res += B[N - 2];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3632
/*
 * Problem Description: Binary Search Tree Il
 * Category: Binary Search Trees
 * Author: Khan
 * Date: 23th October, 2017
 */

#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node
{
    int key;
    Node *r, *l, *p;
};

Node *root, *NIL;

void Insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

    while(x != NIL)
    {
        y = x;
        if(z->key < x->key)
            x = x->l;
        else
            x = x->r;
    }

    z->p = y;
    if(y == NIL)
        root = z;
    else
    {
        if(z->key < y->key)
            y->l = z;
        else
            y->r = z;
    }
}

void Inorder(Node *u)
{
    if(u == NIL)
        return;
    Inorder(u->l);
    printf(" %d", u->key);
    Inorder(u->r);
}

void Preorder(Node *u)
{
    if(u == NIL)
        return;
    printf(" %d", u->key);
    Preorder(u->l);
    Preorder(u->r);
}

Node *find(Node *u, int k)
{
    while(u != NIL && k != u->key)
    {
        if(k < u->key)
            u = u->l;
        else
            u = u->r;
    }
    return u;
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    int n, i, x;
    string cmd;

    scanf("%d", &n);

    for (int i = 0; i < n; ++i)
    {
        cin >> cmd;
        if(cmd[0] == 'f')
        {
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t != NIL)
                printf("yes\n");
            else
                printf("no\n");
        }
        else if(cmd[0] == 'i')
        {
            scanf("%d", &x);
            Insert(x);
        }
        else if(cmd[0] == 'p')
        {
            Inorder(root);
            printf("\n");
            Preorder(root);
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 22008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,ans=0;
	cin>>n;
	for(int i=n;i>=1;i--){
		ll now=i,cnt=0;
		while(now!=0){
			now/=10;
			cnt++;
		}
		if(cnt%2==1){
			ans++;
		}
	}
	cout <<ans;
	return 0;
}

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

const int N = 100010;
int sz;
int djs[N];

int find(int x) {
    return (x == djs[x] ? x : djs[x] = find(djs[x]));
}

void uni(int a, int b) {
    int ga = find(a), gb = find(b);
    if (ga == gb) return;
    djs[ga] = gb;
    sz--;
}

int main() {
    int n, m, a, b; cin >> n >> m;
    sz = n;
    for (int i=1; i<=n; i++) djs[i] = i;
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        uni(a, b);
    }
    cout << sz-1 << endl;
}

Measured memory_bytes: 4024
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N, K = readInts()
  hs = readInts()
  ans = 0
  for h in hs:
    if h >= K:
      ans += 1

  print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 11996
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int main() {
    abdelrahman010
    int n , a[N];
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    vector<int> v;
    int cnt[N] = {};
    for(int i = n;i >= 1;i--) {
        if (a[i]) {
            int c = 0;
            for (int j = i + i; j <= n; j += i)
                c += cnt[j];
            if (c % 2 == 0) {
                v.push_back(i);
                cnt[i]++;
            }
        } else {
            int c = 0;
            for (int j = i + i; j <= n; j += i)
                c += cnt[j];
            if (c % 2) {
                v.push_back(i);
                cnt[i]++;
            }
        }
    }
    cout << v.size() << '\n';
    for(auto &i : v)
        cout << i << " ";
    return 0;
}

Measured memory_bytes: 5320
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void no(){
  cout << -1 << endl;
  exit(0);
}

int main() {
  string s; cin >> s;
  int cnt[26] = {0};
  REP(i, s.size()){
    cnt[s[i]-'a']++;
  }
  REP(i, 26){
    if(cnt[i] == 0){
      char ch = 'a' + i;
      cout << s + ch << endl;
      return 0;
    }
  }
  //全種類出現
  char cur = 'a';
  //p_{k-1} < p_k > p_{k+1} > p_{k+2}...
  ll k = 0;
  IREP(i, s.size()){
    if(s[i]<cur){
      k = i+1;
      break;
    }
    cur = s[i];
  }
  if(k==0) no();
  IREP(i, s.size()){
    if(s[i] > s[k-1]){
      cout << s.substr(0,k-1) + s[i] << endl;
      return 0;
    }
  }
}

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

int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> h;
  for(int i = 0;i < N; i++){
    int tmph;
    cin >> tmph;
    h.push_back(tmph);
  }

  int cnt = 0;
  for (int x : h) {
    if(x >= K) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, r;
    cin >> n >> r;
    cout << r + 100* max(0, 10-n) << endl;
    return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split(" "))

ans = 0
for i in reversed(range(k + 1)):
    start = min(k, n - i)
    if n - i - start > k:
        continue
    for j in reversed(range(start + 1)):
        if(n - i - j <= k):
            # print(i, j, n - i - j)
            ans += 1

print(ans)


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

int main(){
  int n;
  cin>>n;
  int p;
  cin>>p;
  if(p!=0){
    cout<<"0"<<endl;
    return 0;
  }
  if(n==1){
    cout<<n<<endl;
    return 0;
  }
  
  vector<long long int> vec(n-1);
  for(int i=0;i<n-1;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  if(vec.at(n-2)>=n){
    cout<<"0"<<endl;
    return 0;
    }
  
  vector<long long int> kosuu(100000);
  for(int i=0;i<n-1;i++){
    kosuu.at(vec.at(i))++;
  }
  
  int g;
  for(int i=0;i<100000;i++){
    if(kosuu.at(99999-i)>0){
      g=99999-i;
      break;
    }
  }
  
  //cout<<g<<endl;
  
  long long int answer=1;
  if(kosuu.at(1)==0){
    answer*=0;
  }

  if(kosuu.at(0)!=0){
    answer*=0;
  }

  
  long long int mod=998244353;
  
  for(int i=2;i<g+1;i++){
    for(int j=0;j<kosuu.at(i);j++){
      answer*=kosuu.at(i-1);
      answer%=mod;
    }
  }
  cout<<answer%mod<<endl;
}


Measured memory_bytes: 1792
n = int(input())
# a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# a.sort()
# b.sort()

# 4 100
# 5 101
# 5 101
# 6 110
# max 2
# 20 = 2^2*4 2^1*1 + 1*2
# 2 010

# maxab = max(a) + max(b)
# print(maxab, flush=True)
# maxlen = len(format(maxab, 'b'))
# allsum = sum(a)*n + sum(b)*n
# print(allsum, flush=True)
# ans = ''
# while maxlen != 0:
#     q,mod = divmod(allsum, 2^(maxlen-1))
#     if q%2==0:
#         ans += '0'
#     else:
#         ans += '1'
#     allsum = mod
#     maxlen -=1
# print(format(ans, 'o'), flush=True)
# WA: Can't get exact num from here

### k k+1
### 1 0
### => bigger than 2^k, smaller than 2^k+1
### k k+1
### 1 1
### => bigger than 2^k + 2^k+1, smaller than 2^k+1 + 2^k+1
###
### minus a
### and binary search b
### then count
# def binary_search(sorted_list, item):
#     left = 0
#     right = len(sorted_list) - 1
#     while left <= right:
#         middle = (left + right) // 2
#         if left == right:
#             if sorted_list[middle] < item:
#                 left = middle + 1
#                 break;
#             else:
#                 break;
#         elif sorted_list[middle] < item:
#             left = middle + 1
#         else:
#             right = middle - 1
#     return left
# ans = 0
# for i in range(29):
#     # 2^k
#     t =1<<i
#     for ax in a:
#         b_num = 0
#         # bigger than 2^k, smaller than 2^(k+1)
#         #  (b < 2^(k+1) - a) - (b < 2^k - a)
#         b_num =  binary_search(b, 2*t - ax)
#         b_num -= binary_search(b, t - ax)
#         # bigger than 2^k + 2^k+1, smaller than 2^k+1 + 2^k+1
#         # (b < 2*2^(k+1) -a) - (b <  2^k + 2^(k+1))
#         b_num += binary_search(b, 4*t - ax)
#         b_num -= binary_search(b, 3*t - ax)
#         if b_num%2==1:
#             ans+=1<<i
# print(ans, flush=True)
# TLE

# should use np.searchsorted. They can convolute array to array.

import numpy as np
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
ans = 0
for i in range(29):
    # 2^k
    t = 1<<i
    ax = a%(2*t)
    bx = b%(2*t)
    ax.sort()
    bx.sort()
    b_num=0
    # bigger than 2^k, smaller than 2^(k+1)
    # (b < 2^(k+1) - a) - (b < 2^k - a)
    b_num =  np.searchsorted(bx, 2*t - ax)
    b_num -= np.searchsorted(bx, t - ax)
    # bigger than 2^k + 2^k+1, smaller than 2^k+1 + 2^k+1
    # (b < 2*2^(k+1) -a) - (b <  2^k + 2^(k+1))
    b_num += np.searchsorted(bx, 4*t - ax)
    b_num -= np.searchsorted(bx, 3*t - ax)
    if b_num.sum()%2==1:
        ans+=1<<i
print(ans, flush=True)



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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, x, y;
	cin>>n>>x>>y;
	vector<int> cnt(n, 0);
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			int mn = j - i;
			mn = min(mn, abs(j - x) + abs(i - y) + 1);
			mn = min(mn, abs(j - y) + abs(i - x) + 1);
			cnt[mn]++;
		}
	}
	for(int i = 1; i < n; i++){
		cout<<cnt[i]<<'\n';
	}

	return 0;
}

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

const ll inf = (1 << 30) - 1;
ll dp[1010][1003];
int N, M;

int main()
{
    cin >> N >> M;
    vector<ll> D(N + 10), C(M + 10);
    for (int i = 1; i <= N; i++)
    {
        cin >> D[i];
    }
    for (int i = 1; i <= M; i++)
    {
        cin >> C[i];
    }
    for (int i = 0; i <= M + 1; i++)
    {
        for (int j = 0; j <= N + 1; j++)
        {
            dp[i][j] = inf;
        }
    }
    dp[1][1] = 0;
    for (int i = 2; i <= M + 1; i++)
    {
        for (int j = 1; j <= N + 1; j++)
        {
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + C[i - 1] * D[j - 1]);
        }
    }
    cout << dp[M + 1][N + 1] << endl;
}


Measured memory_bytes: 10912
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,i;
	cin>>a>>b;
	if(a<=b){
		for(i=1;i<=b;i++){
			cout<<a;
		}
	}
	else{
		for(i=1;i<=a;i++){
			cout<<b;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
15 6
1 2 7 8 12 50

output:
2
"""

import sys


def solve():
    rec[0] = 0
    for coin in coins:
        for current_cost in range(coin, total_cost + 1):
            rec[current_cost] = min(rec[current_cost], rec[current_cost - coin * 1] + 1)

    return rec


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    total_cost, c_num = map(int, _input[0].split())
    coins = list(map(int, _input[1].split()))
    # assert len(coins) == c_num
    rec = [float('inf')] * (total_cost + 1)
    ans = solve()
    print(ans[-1])

Measured memory_bytes: 9560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	int N,M,Ans=0,tmp=0;
	cin>>N>>M;
	vector<pair<int,int>> X(M);
	for(int i=0;i<M;i++) cin>>X[i].first>>X[i].second;
	sort(X.begin(),X.end(),[](auto &left, auto &right){
		return left.second < right.second;
	});
	for(int i=0;i<M;i++){
		if(tmp<=X[i].first){
			Ans++;
			tmp=X[i].second;
		}
	}
	cout<<Ans<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<bool> mat(N+1,false);
  int pp;
  for (int i=0; i<N; i++) {
    cin >> pp;
    if (i+1 == pp) {
      mat[i] = true;
    }
  }
  int ans = 0;
  for(int i=0; i<N; i++) {
    if (mat[i]) {
      ans++;
      mat[i+1] = false;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int
main()
{
  string s, t;
  cin >> s >> t;
  int r = 0;
  for (int i = 0; i < 3; ++i) {
    if (s[i] == t[i]) {
      ++r;
    }
  }
  cout << r << endl;
  return 0;
}

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

#define int long long
#define max(a,b) max((signed)a,(signed)b)
#define mn(a,b) min((signed)a,(signed)b)

using namespace std;

signed main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=1;i<k;i++) a[0] += a[i];
	cout<<a[0];
}

Measured memory_bytes: 3552
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    }

    private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    }

    private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    }

}


Measured memory_bytes: 23124