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

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int now = 0;
    while(1){
        if(s[now].empty()){
            if(now == 0){
                cout << "A" << endl;
            }else if(now == 1){
                cout << "B" << endl;
            }else if(now == 2){
                cout << "C" << endl;
            }
            return 0;
        }
        char cur = s[now][0];
        s[now].erase(s[now].begin());
        now = cur - 'a';
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	d := abs(x - a[0])
	for i := 1; i < n; i++ {
		d = gcd(d, abs(x-a[i]))
	}
	fmt.Println(d)
}


Measured memory_bytes: 5504
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            int i, j;
            for (i = 0; i < H; i++) {
                for (j = 0; j < W; j++) {
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}



Measured memory_bytes: 64364
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,h[128],ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h[i];
    if(i)ans+=max(0ll,h[i]-h[i-1]);
    else ans+=h[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

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

	string ret = "             ";

	for (int i = 0; i < 4; i++)
	{
		ret.at(i) = str.at(i);
	}
	ret.at(4) = ' ';

	for (int i = 5; i < 13; i++)
	{
		ret.at(i) = str.at(i - 1);
	}

	cout << ret << endl;

//		sort(c, c + n, greater<int>()); //降順ソート

	return 0;
}

Measured memory_bytes: 256
a,b,k = map(int,input().split())

def yakusuu(n):
  lis=[]
  for i in range(1,n+1):
    if n%i==0: lis.append(int(i))
  return lis

yakusuu_a = set(yakusuu(a))
yakusuu_b = set(yakusuu(b))

joint = yakusuu_a & yakusuu_b

# print(joint)
joint_lis = list(joint)
joint_lis.sort(reverse=True)
# print(joint_lis)
print(joint_lis[k-1])

Measured memory_bytes: 38256
row = input()
lenght = len(row)
max_moji = 0
for i in range(lenght):
    if row[i] in 'ACGT':
        moji = 1
        for j in range(i + 1, lenght):
            if row[j] in 'ACGT':
                moji += 1
            else:
                break
        max_moji = moji if moji > max_moji else max_moji
    if max_moji == lenght - i:
        break
print(max_moji)

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

int main () {
 int K,A,B;
  cin >> K >> A >> B;
  string t;
  for (int x = B;A<=x;x--) {
   if (x%K == 0) {
    t = "OK" ;
     break;
   }
   if (x%K != 0) {
    t = "NG" ;
   }
  }
  cout << t << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;

void add(int &a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

int dp[4017][2017][2];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m,kk; cin>>n>>m>>kk;
	dp[0][0][0] = 1;
	for(int i = 0; i < (n+m-1)/(kk-1); i++)
	{
		for(int j = 0; j <= n; j++)
		{
			for(int k = 0; k < 2; k++)
			{
				int v = dp[i][j][k];
				if(v==0) continue;
				for(int z=0;z<kk;z++)
				{
					int newk=(z!=0);
					int newi=i+1;
					int newj=j+z;
					if(newj>n) continue;
					add(dp[newi][newj][newk],v);
				}
			}
		}
	}
	int ans=0;
	for(int i=1;i<=(n+m-1)/(kk-1);i++)
	{
		for(int j = n; j >= 0; j-=(kk-1))
		{
			int sj = (kk-1)*i - j;
			if(sj>=0&&sj<=m-1&&(m-1-sj)%(kk-1)==0)
			{
				//cerr<<i<<' '<<j<<' '<<sj<<' '<<dp[i][j][1]<<'\n';
				add(ans,dp[i][j][1]);
			}
		}
	}
	cout<<ans<<'\n';
}


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

const int MOD = 1e9 + 7;

void solve_test() {
	int d, t, s;
	cin >> d >> t >> s;

	int need_t = (d + s - 1) / s;

	cout << (need_t <= t ? "Yes" : "No") << '\n';
}

int32_t main() {
	int T; 
	// cin >> T;
	T = 1;
	while (T--)
		solve_test();

	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
   int n,k;
   Int(n,k);

   set<int>s;
   for(int i=1;i<=k;++i){
    int d;
    Int(d);

    while(d--){
      int x;
      Int(x);
      s.insert(x);
    }
   }
   printf("%d\n", n-sz(s));

   
    return 0;
}



Measured memory_bytes: 3684
n,m=map(int,input().split())

edges=[]
for i in range(m):
    a,b=map(int,input().split())
    edges.append((a,b))
    edges.append((b,a))

def conn(v1,v2):
    return (v1,v2) in edges

import itertools
ret=0
for x in itertools.permutations(list(range(1,n+1))):
    for i in range(n-1):
        if not conn(x[i],x[i+1]) or x[0]!=1:
            break
        if i==n-2:
            ret+=1

print(ret)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
#define Fail return puts("NO"),0
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
int H,W;
const int N=2e5+10;
char S[N],T[N];
int x,y;

int main()
{
	int n;
	init(H),init(W);init(n);init(x),init(y);
	scanf("%s",S+1);scanf("%s",T+1);
	int LY=y,RY=y,UX=x,DX=x;
	for(int i=1;i<=n;++i) {
		if(S[i]=='L') --LY;
		else if(S[i]=='R') ++RY;
		else if(S[i]=='U') --UX;
		else if(S[i]=='D') ++DX;
		if(LY<=0) Fail;
		if(RY>W) Fail;
		if(UX<=0) Fail;
		if(DX>H) Fail;
		
		if(T[i]=='L'&&RY>1) --RY;
		else if(T[i]=='R'&&LY<W) ++LY;
		else if(T[i]=='U'&&DX>1) --DX;
		else if(T[i]=='D'&&UX<H) ++UX;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
dp=[0]*(10**6+1)
for i in a:
  dp[i]+=1
for i in range(1,10**6+1):
  if dp[i]:
    for  j in range(2*i,10**6+1,i):
      dp[j]=0
print(dp.count(1))

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

int main(void)
{
    int L,R,d;
    if(scanf("%d %d %d", &L, &R, &d) == EOF) exit(1);

    int i, count =0 ;
    for (i=L; i<=R; i++){
        if (i%d == 0) count++;
    }
    printf("%d", count);

    return 0;
}

Measured memory_bytes: 1708
#include <stdio.h>

void dfs(int* data,int* label,int index) {

  int new[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

  int x,y;
  int nx,ny;

  int i;

  label[index]=1;

  x=index%12;
  y=index/12;

  for(i=0;i<4;i++) {

    nx=x+new[i][0];
    ny=y+new[i][1];

    if(nx<0 || nx>11 || ny<0 || ny>11) continue;

    if(label[nx+ny*12]==0 && data[nx+ny*12]==1) dfs(data,label,nx+ny*12);

  }

}
 
int main(void) {

  int data[200];

  int count;
  int idx;
  int label[200];

  char buf[50];
  int i,j;


  while(1) {

    idx=0;

    for(i=0;i<12;i++) {

      if(fgets(buf,sizeof(buf),stdin)==NULL) return 0;

      for(j=0;j<12;j++) {

	data[idx]=buf[j]-'0';

	idx++;

      }

    }

    /*
    for(i=0;i<12;i++) {

      for(j=0;j<12;j++) {

	printf("%d ",data[12*i+j]);

      }

      puts("");

    }
    */

    for(i=0;i<144;i++) label[i]=0;

    count=0;

    for(i=0;i<144;i++) {

      if(data[i]==1 && label[i]==0) {

	dfs(data,label,i);
	count++;

	
      }

    }

    /*
    for(i=0;i<144;i++) {

      if(i%12==0) puts("");
      printf("%d",label[i]);

    }
    */

    fgets(buf,sizeof(buf),stdin);

    printf("%d\n",count);

  }

  return 0;

}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

typedef struct
{
    int a;
    int b;
} task;

int cmp(const void *p, const void *q)
{
    return ((task *)p)->b - ((task *)q)->b;
}

int main(void)
{
    int n;
    task tasks[200001];

    scanf("%d", &n);
    rep(i, n)
        scanf("%d%d", &tasks[i].a, &tasks[i].b);

    qsort(tasks, n, sizeof(task), cmp);

    /*
    rep(i, n)
        printf("a:%d b:%d\n", tasks[i].a, tasks[i].b);
    */

    ll time = 0;
    rep(i, n)
    {
        time += tasks[i].a;
        if (time > tasks[i].b)
        {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    return 0;
}

Measured memory_bytes: 3324
N = int(input())
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,max(A)+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,10**6+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)


Measured memory_bytes: 105944
#include <bits/stdc++.h>
// #define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fi first
#define se second
#define MK make_pair
#define PB push_back
using namespace std;

typedef long long LL;
typedef pair<int ,int> PII;
const int N= 1e5 +10;
PII p[N];
char s[N];
LL n, k, rep;
int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%s%lld", s, &rep);
	n=strlen(s);
	for (int i=0,j;i<n; i=j){
		for (j=i; j<n && s[i]==s[j] ; ++j);
		p[k++]=MK(i,j);
	}
	if ( k==1) printf("%lld\n", (n*rep)>>1);
		else{
			LL res=0;
			if ( s[0]==s[n-1]){
				for (int i=1; i+1<k; ++i) res += rep*((p[i].se-p[i].fi)>>1);
				res += (p[0].se-p[0].fi)>>1;
				res += (p[k-1].se-p[k-1].fi)>>1;
				res += (rep-1)*((p[0].se-p[0].fi+p[k-1].se-p[k-1].fi)>>1);
			}	else
				for (int i=0; i<k; ++i) res += rep*((p[i].se-p[i].fi)>>1);
			
			printf("%lld\n", res);
		}
	return 0;
}

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

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

    for (int i = 0; i < B.size() - 1;i++){
        C += B.at(i);
    }
        if (A == C)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;


int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector< int> v;
    for (int i = 0; i < k and i + a <= b; i++) {
        v.emplace_back(i + a);
        v.emplace_back(b - i);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int x: v) cout << x << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,m,i,j;
	
	
	scanf("%d",&n);
	scanf("%d",&m);
	
	int A[n][m],b[m],ans[n];
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&A[i][j]);

		}

	}
	
	for(i=0;i<m;i++){		
			scanf("%d",&b[i]);
		
	}

	
	for(i=0;i<n;i++){
		ans[i] = 0;
		for(j=0;j<m;j++){

			ans[i] += b[j] * A[i][j];
		}
	}
	
	for(i=0;i<n;i++){	
	
			printf("%d\n",ans[i]);
	}
	return 0;
}

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

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

  int ans = 0;
  rep(i, N) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }

  cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  vector<int> d(4, 0);
  REP (i, 3) {
    int a, b;
    cin >> a >> b;
    d[a - 1]++;
    d[b - 1]++;
  }

  sort(d.begin(), d.end());

  if (d[0] == 1 && d[1] == 1 && d[2] == 2 && d[3] == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000
int n,a;
vector<int> G[MAX];
int match[MAX];
int used[MAX];
int C=10;
  
bool dfs(int v,int x){
  used[v]=C;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i],w=match[u];
    if( w<0 || (used[w]!=C && dfs(w,x)) ){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(int x=-1){
  int res=0;
  if(x==-1)memset(match,-1,sizeof(match));  
  int A=0,B=n;
  if(x!=-1){
    A=x;
    B=x+1;
    match[ match[x] ]=-1;
    match[x]=-1;    
  }  
  for(int v=A;v<B;v++){
    C++;    
    if(match[v]<0){
      if(dfs(v,x))res++;
      else return 0;
    }
  }
  return res;
}
 
int main(){  
  cin>>n;
  n--;  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",&a);
      if(a==1)G[j].push_back(n+i);
    }
  }
  for(int i=0;i<n;i++)sort(G[i].begin(),G[i].end());
   
  int F = bipartite_matching();  
  if( F == n ){
    cout<<"yes"<<endl;
    for(int i=0;i<n;i++){
      bipartite_matching(i);
      G[i].clear();
      G[i].push_back( match[i] );
    }
    for(int i=0;i<n;i++)cout<<match[i]+1-n<<endl;     
  }else{
    cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3324
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int imos[30][100010];
main(){
    int N,C;
    cin >> N >> C;
    vector<int> S(N),T(N),R(N);
    rep(i,0,N)cin >> S[i] >> T[i] >> R[i];
    rep(i,0,N){
        imos[R[i]-1][S[i]]++;
        imos[R[i]-1][T[i]+1]--;
    }
    rep(i,0,C)rep(j,0,100001)imos[i][j+1] += imos[i][j];
    int maxi = 0;
    //rep(i,0,C)rep(j,0,20)cout << imos[i][j] << " \n"[j==19];
    rep(i,0,100002){
        int cnt = 0;
        rep(j,0,C)if(imos[j][i])cnt++;
        maxi = max(maxi, cnt);
    }
    cout << maxi << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int a, b;

int main() {
  cin >> a >> b;
  if (abs(a - b) % 2 == 1) cout << "IMPOSSIBLE";
  else
    cout << (a + b) / 2;
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left,bisect_right
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(A[0]-1,A[-1]+1):
    value = bisect_right(A,i+1)-bisect_left(A,i-1)
    if value > ans:
        ans = value
print(ans)

Measured memory_bytes: 14008
def segfunc(x,y):
    return x+y

class SegmentTree():
    def __init__(self,A,n,ide_ele):
        self.ide_ele=ide_ele
        self.num =2**(n-1).bit_length()
        self.seg = [self.ide_ele]*2*self.num
        #set_val
        for i in range(n):
            self.seg[i+self.num-1]=A[i]
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=segfunc(self.seg[2*i+1],self.seg[2*i+2])

    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = segfunc(res,self.seg[p])
            if q&1 == 1:
                res = segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = segfunc(res,self.seg[p])
        else:
            res = segfunc(segfunc(res,self.seg[p]),self.seg[q])
        return res
N,Q = list(map(int,input().split()))
A = list(map(int,input().split()))
ST = SegmentTree(A,N,0)
for i in range(Q):
    n,p,x = list(map(int,input().split()))
    if n==1:
        print(ST.query(p,x))
    else:
        A[p] += x
        ST.update(p,A[p])


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

using namespace std;

int main()
{
    int a,b,temp;
    cin>>a>>b;
    ostringstream oss;
    oss << a << b;
    istringstream iss(oss.str());
    int c;
    iss >> c;
    temp = sqrt(c);

    if(temp*temp == c)
        printf("Yes");
    else
    printf("No");
    return 0;
}


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

constexpr int lim = 1e5;

int main() {
    int q;
    cin >> q;
    vector<pair<int, int>> lr(q);
    for (auto& e : lr) cin >> e.first >> e.second;

    vector<int> p(lim + 10, 1), f(lim + 10);
    p[0] = p[1] = 0;
    for (int i = 2; i <= lim; i++) {
        if (!p[i]) continue;
        for (int j = i+i; j <= lim; j += i) p[j] = 0;
    }

    for (int i = 1; i <= lim; i += 2) f[i+1] = f[i] = f[i-1] + (p[i] && p[(i+1)/2]);
    for (auto& e : lr) cout << f[e.second] - f[e.first-1] << endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
using namespace std;

const int INF=1e9;

int n,m=1;
int a[800005];
int g[2][800005];
int ans[200005];


void update(int k){
	int odd,pos=k;
	odd=k%2;
	k+=m-1;
	g[odd][k]=pos;
	g[(odd+1)%2][k]=INF;
	while(k>1){
		k/=2;
		for(int i=0;i<2;i++){
			if(g[i][k*2]==INF&&g[i][k*2+1]!=INF) g[i][k]=g[i][k*2+1];
			else if(g[i][k*2+1]==INF&&g[i][k*2]!=INF) g[i][k]=g[i][k*2];
			else if(g[i][k*2]!=INF&&g[i][k*2+1]!=INF){
				if(a[g[i][k*2]]<a[g[i][k*2+1]]) g[i][k]=g[i][k*2];
				else g[i][k]=g[i][k*2+1];
			}
		}
	}
}

int rmq(int l,int r,int k,int l1,int r1){
	int odd=l%2;
	if(l<=l1&&r>=r1) return g[odd][k];
	if(r<l1||l>r1) return INF;
	else{
		int x=rmq(l,r,k*2,l1,(l1+r1)/2),y=rmq(l,r,k*2+1,(l1+r1+1)/2,r1);
		if(x==INF&&y!=INF) return y;
		else if(x!=INF&&y==INF) return x;
		else if(x==INF&&y==INF) return INF;
		else{
			if(a[x]<a[y]) return x;
			else return y;
		}
	}
}

struct range{
	int a,b;
	int mint;
};

bool operator>(const range &x,const range &y){
	if(x.mint!=INF&&y.mint!=INF)return a[x.mint]>a[y.mint];
	else if(x.mint==INF&&y.mint!=INF) return true;
	else if(x.mint!=INF&&y.mint==INF) return false;
	else return true;
}


int main(){
	scanf("%d",&n);
	fill(a,a+800005,INF);
	fill(g[0],g[0]+800005,INF);
	fill(g[1],g[1]+800005,INF);
	while(m<n) m*=2;
	for(int i=1;i<=n;i++) {
		scanf("%d",a+i);
	}
	for(int i=1;i<=m;i++){
		update(i);
	}
	priority_queue<range,vector<range>,greater<range> > pq;
	range init={1,n,rmq(1,n,1,1,m)};
	pq.push(init);
	int id=1;
	while(id<=n&&!pq.empty()){
		range f=pq.top();
		pq.pop();
		ans[id++]=f.mint;
		range forw,bacw={f.mint+1,f.b,rmq(f.mint+1,f.b,1,1,m)};
		if(f.a<f.mint-1){
			forw={f.a,f.mint-1,rmq(f.a,f.mint-1,1,1,m)};
			pq.push(forw);
		}
		ans[id++]=bacw.mint;
		range sec,thir;
		if(bacw.a<bacw.mint-1){
			sec={bacw.a,bacw.mint-1,rmq(bacw.a,bacw.mint-1,1,1,m)};
			pq.push(sec);
		}
		if(bacw.mint+1<bacw.b){
			thir={bacw.mint+1,bacw.b,rmq(bacw.mint+1,bacw.b,1,1,m)};
			pq.push(thir);
		}
	}
	for(int i=1;i<=n;i++){
		if(i>1) printf(" ");
		printf("%d",a[ans[i]]);
	}
	printf("\n");
return 0;
}

Measured memory_bytes: 12280
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
const int maxn = 1e6 + 10;
 
int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	if (s[0] == '0' or s[n - 1] == '1')
		return cout << -1 << endl, 0;
	for (int i = 0; i < n - 1; i++)
		if (s[i] != s[n - i - 2])
			return cout << -1 << endl, 0;
	int root = 1, cnt = 2;
	for (int i = 2; i <= n; i++){
		if (s[i - 1] == '1'){
			cout << cnt << " " << root << endl;
			root = cnt ++;
			while (cnt <= i)
				cout << root << " " << cnt ++ << endl;
		}
	}
	while (cnt <= n)
		cout << root << " " << cnt ++ << endl;
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
using namespace std;
int main(){
int H, N;
cin >> H >> N;
int A[N] ={0};
for(int i = 0; i < N; i++){
  cin >> A[i];
}
int sum = 0;
for(int i = 0; i < N; i ++){
  sum += A[i];
}
if(sum >= H)cout <<"Yes" <<endl;
else cout << "No" <<endl;
}

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



int main() {
    int N, X, Y;
    int index = 0;
    cin >> N >> X >> Y;
    int k[N];
    for(int i = 0; i < N; i++)
        k[i] = 0;
    for(int i = 1; i < N; i++){
        for(int j = i + 1; j <= N; j++){
            index = min(abs(X-i) + abs(Y-j) + 1, j - i);
            k[index]++;
        }
    }

    for(int i = 1; i < N; i++)
        cout << k[i] << endl;
}


Measured memory_bytes: 256
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll unsigned long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define fi first
#define se second
#define mkp make_pair    
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vll vector< pair<ll,ll> > 
#define mpl map<ll, ll>
#define pr pair<ll,ll>
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x*x);if(p%2==0) return x;else return (x*n);}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}  
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
//	   cin>>t;
	      while(t--)
{
ll n;
cin>>n;
if(n==1)
cout<<0;
else
cout<<1;
ee;
}
return 0;
}



Measured memory_bytes: 3632
import numpy as np

n = int(input())
H = np.array(list(map(int, input().split())))
H = np.diff(H)
H = H <= 0

ans = 0
cnt = 0
for h in H:
        
    if h:
        cnt +=1
        ans = max(ans, cnt)
    else:
        cnt = 0
print(ans)

Measured memory_bytes: 23368
import sys
sys.setrecursionlimit(10**8)
T = int(input())
for _ in range(T):
    N,A,B,C,D = map(int,input().split())
    INF = float('inf')
    mem = {}
    def solve(n):
        if n==0: return 0
        if n==1: return D
        if n in mem: return mem[n]
        tmp = n*D
        if n%2==0:
            tmp = min(tmp, solve(n//2) + A)
        else:
            tmp = min(tmp, solve(n//2) + A+D, solve(n//2+1) + A+D)
        if n%3==0:
            tmp = min(tmp, solve(n//3) + B)
        else:
            d = n%3
            u = 3-d
            tmp = min(tmp, solve(n//3) + B+d*D, solve(n//3+1) + B+u*D)
        if n%5==0:
            tmp = min(tmp, solve(n//5) + C)
        else:
            d = n%5
            u = 5-d
            tmp = min(tmp, solve(n//5) + C+d*D, solve(n//5+1) + C+u*D)
        mem[n] = tmp
        return tmp
    print(solve(N))


Measured memory_bytes: 10968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int a,b,c,x,count=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=b;j++)
        {
            int rem  = x -( 500*i + 100*j);
            if(rem>=0 && ((rem/50)*50 == rem) && rem/50 <=c )
            {
                count++;
            }
        }
    }
    cout<<count<<endl;
   return 0;
}


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

int main() {
  int sum = 0;
  string s;

  cin >> s;
  for(int i = 0;i<4;i++){
    if(s.at(i) == '+'){
      sum++;
    }else{
      sum--;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


Int combination(Int n, Int r) {
    if(n == 1){return 0;}
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

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

    vector<Int> A = vi(N);
    map<int,int> answers;

    REP(i,1,N+1){
        int rank;
        cin >> rank;
        answers[rank] = i;
    }

    REP(i,1,N+1){
        cout << answers[i] << " ";
    }
    cout << endl;



    return 0;
}

Measured memory_bytes: 6272
/**
 *   author: sahushivam
 *   created: 22 December 2019 (Sunday)  17:30:50
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

void solve(){
	int a,b;
	cin>>a>>b;
	if(a>b) swap(a,b);
	if(a==1 && b==2)
		cout<<3;
	if(a==1 && b==3)
		cout<<2;
	if(a==2 && b==3)
		cout<<1;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> v1(N);
  for (int i=0;i<N;i++){
    cin >> v1[i];
  }
  vector<int> v2=v1;
  sort(v1.begin(),v1.end());
  int count=0;
  for (int i=0;i<N;i++){
    if (v1[i]!=v2[i]){
      count++;
    }
  }
  if (count==0||count==2){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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


def solve(N: int):
    res = N*(0+(N-1)) // 2
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
int main()
{
    int n;
    cin>>n;
    ll arr[n+5];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    ll m=1e18;
    if(arr[0]==0)
        cout<<"0"<<endl;
    else
    {
        ll ans=1;
        for(int i=0;i<n;i++){
            if(arr[i]<=m/ans)
                ans*=arr[i];
            else{
                cout<<"-1"<<endl;
                return 0;
            }

        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4404
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

int main(){
  string S;
  cin >> S;
  char prev;
  bool easy = true;
  for(int i=0;i<S.length();i++){
    if(i>0 && prev == S[i]){
      easy = false;
      break;
    }
    prev = S[i];
  }
  if(easy) cout << "Good" << endl;
  else     cout << "Bad"  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,cnt=0,cnt2=0;
    cin >> a;
    for(int i=1;i<=a;i+=2){
        cnt=0;
        for(int j=1;j<=i;j++){
            if(i%j==0){cnt++;}
        }
        if(cnt==8){cnt2++;}
    }
    cout << cnt2 << endl;

    return 0;
}

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

says = []

for _ in range(N):
    A = int(input())
    say = [list(map(int, input().split())) for _ in range(A)]
    says.append(say)


# print(says)
max_upright_count = 0
for i in range(1 << N):
    integrate = True
    upright_count = 0
    declares = [-1 for _ in range(N)]
    for j in range(N):
        if not integrate:
            continue
        # もし真偽不明の場合は正しいことを言う場合もあるから無視する
        if (i >> j & 1) == 1:
            upright_count += 1
            for x, y in says[j]:
                # print(i, j, x, y, declares)
                if declares[x - 1] == -1:
                    declares[x - 1] = y
                else:
                    if declares[x - 1] == y:
                        continue
                    else:
                        integrate = False
                        break
    # print(bin(i), integrate, declares, upright_count)
    for j in range(N):
        # print((i >> j) & 1, declares[j])
        if ((i >> j) & 1) != declares[j] and declares[j] != -1:
            # print(False)
            integrate = False
    # print(integrate)
    if integrate:
        max_upright_count = max(max_upright_count, upright_count)
print(max_upright_count)


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

int main() {
    int x,a,b; cin >> x >> a >> b;
    if (abs(x-a) > abs(x-b)) {
        cout << "B\n";
    } else {
        cout << "A\n";
    }
    return 0;
}

Measured memory_bytes: 256
/*input
10 2
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

ll m;
vector<vector<int>> adj;
vector<vector<ll>> pre;
vector<vector<ll>> suf;
vector<ll> dp;

void dfs1(int v, int p)
{
	if(adj[v].empty()) return; // special case: only one node in the graph
	for(int i = 0; i < adj[v].size(); i++) if(adj[v][i] != p)
	{
		dfs1(adj[v][i], v);
		dp[v] = (dp[v] * ((1 + dp[adj[v][i]]) % m)) % m;
	}
	pre[v].resize(adj[v].size());
	suf[v].resize(adj[v].size());
	pre[v][0] = ((adj[v][0] == p) ? 1 : (1 + dp[adj[v][0]]) % m);
	suf[v][adj[v].size() - 1] = ((adj[v][adj[v].size() - 1] == p) ? 1 : (1 + dp[adj[v][adj[v].size() - 1]]) % m);
	for(int i = 1; i < adj[v].size(); i++)
	{
		if(adj[v][i] == p) pre[v][i] = pre[v][i - 1];
		else pre[v][i] = (pre[v][i - 1] * ((1 + dp[adj[v][i]]) % m)) % m;
	}
	for(int i = adj[v].size() - 2; i > -1; i--)
	{
		if(adj[v][i] == p) suf[v][i] = suf[v][i + 1];
		else suf[v][i] = (suf[v][i + 1] * ((1 + dp[adj[v][i]]) % m)) % m;
	}
}

void dfs2(int v, int p, int i)
{
	if(v) // dp[v] *= (1 + dp[p]/(1 + dp[v]));
	{
		int j = 0;
		ll temp;
		if(adj[p].size() == 1) temp = 1;
		else if(i - 1 == -1) temp = suf[p][i + 1];
		else if(i + 1 == adj[p].size()) temp = pre[p][i - 1];
		else temp = (pre[p][i - 1] * suf[p][i + 1]) % m;
		dp[v] = (dp[v] * ((1 + temp) % m)) % m;
		// from here we update pre and suf
		while(adj[v][j] != p) j++;
		pre[v][j] = (!j ? (1 + temp) % m : (pre[v][j - 1] * ((1 + temp) % m)) % m);
		suf[v][j] = (j == adj[v].size() - 1 ? (1 + temp) % m : (suf[v][j + 1] * ((1 + temp) % m)) % m);
		int jj = j + 1;
		while(jj < adj[v].size())
		{
			pre[v][jj] = (pre[v][jj - 1] * ((1 + dp[adj[v][jj]]) % m)) % m;
			jj++;
		}
		jj = j - 1;
		while(jj > -1)
		{
			suf[v][jj] = (suf[v][jj + 1] * ((1 + dp[adj[v][jj]]) % m)) % m;
			jj--;
		}
	}
	for(int i = 0; i < adj[v].size(); i++) if(adj[v][i] != p) dfs2(adj[v][i], v, i);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n >> m;
    adj.resize(n);
    dp.resize(n);
    pre.resize(n);
    suf.resize(n);
    for(int i = 0; i < n; i++) dp[i] = 1;
    for(int i = 0; i < n - 1; i++)
    {
    	int u, v; cin >> u >> v;
    	u--; v--;
    	adj[u].push_back(v);
    	adj[v].push_back(u);
    }
    dfs1(0, -1);
    dfs2(0, -1, -1);
    for(int i = 0; i < n; i++) cout << dp[i] << endl;

    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x;
    cin >> n;
    int arr[n];
    unordered_map<int, int> mp;
    for(int i=1; i<n; ++i){
        cin >> arr[i];
        ++mp[ arr[i] ];
    }
    for(int i=1; i<=n; ++i){
        cout << mp[i] << "\n";
    }
}


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

int main(){
    string S;
    cin >> S;
    if(S[S.length()-1]=='s'){
        cout << S << "es" << endl;
    }else{
        cout << S << "s" << endl;
    }
    system("pause");
    return 0;
}

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

int main() {
  double N; cin >> N;
  double sum = 0;
  for(int i = 0; i < N; i++) {
    double x; cin >> x;
    string u; cin >> u;
    if(u == "JPY") {
      sum += x;
    }
    else {
      sum += x * 380000.0;
    }
  }
  cout << fixed << setprecision(8);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void deleteFirst() {
	if (nil->next == nil) return;
	Node *delNode = nil->next;
	nil->next = delNode->next;
	delNode->next->prev = nil;
	free(delNode);
}

void deleteLast() {
	if (nil->prev == nil) return;
	Node *delNode = nil->prev;
	nil->prev = delNode->prev;
	delNode->prev->next = nil;
	free(delNode);
}

Node *searchNode(int key) {
	Node *n;
	for (n = nil->next; n != nil; n = n->next) {
		if (n->key == key) {
			break;
		}
	}
	return n;
}

void deleteKey(int key) {
	Node *delNode = searchNode(key);
	if (delNode == nil) return;
	delNode->prev->next = delNode->next;
	delNode->next->prev = delNode->prev;
	free(delNode);
}

void insert(int key) {
	Node *newNode = (Node *)malloc(sizeof(Node));

	newNode->key = key;

	if (nil->prev == nil) {
		nil->prev = newNode;
	}
	else {
		nil->next->prev = newNode;
	}
		
	newNode->next = nil->next;
	nil->next = newNode;
	newNode->prev = nil;
}

void printList() {
	bool isf = true;
	for (Node *n = nil->next;n != nil; n = n->next) {
		if (isf) {
			isf = false;
		}
		else {
			printf(" ");
		}
		printf("%d", n->key);
	}
	printf("\n");
}

int main() {
	int key, n, i;
	int size = 0;
	char com[30];
	scanf("%d", &n);
	init();

	for (i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		}
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				scanf("%d", &key);
				deleteKey(key);
			}
		}
	}
	printList();
	return 0;
}


Measured memory_bytes: 33824
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int m,f,r;
  while(true){
    cin>>m>>f>>r;
    if(m==-1 && f==-1 && r==-1)
      break;
    if(m==-1 || f==-1)
      cout<<'F'<<'\n';
    else if(m+f>=80)
      cout<<'A'<<'\n';
    else if(m+f>=65)
      cout<<'B'<<'\n';
    else if(m+f>=50)
      cout<<'C'<<'\n';
    else if(m+f>=30){
      if(r>=50)
	cout<<'C'<<'\n';
      else
	cout<<'D'<<'\n';
    }
    else
      cout<<'F'<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;

int main(){
    int a, b,c;
    cin >> a >> b >> c;
    
    const int first = a % b;
    if(first == c) { cout << "YES" << endl; return 0; }
    
    int i = 2;
    while(1){
        const int r = i * a % b;
        if(r == first) break;
        if(r == c) { cout << "YES" << endl; return 0; }
        i++;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 888
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
string S = "";

int main() {
	scanf("%lld", &N);
	cin >> S;
	ll cnt = 0;
	for(int i = 0; i < S.size() - 2; i++) {
		if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
			cnt++;
		}
	}
	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int m=1001,M=0;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		if(a<m) m=a;
		if(a>M) M=a;
	}
	cout << M-m << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int flag=1;
    char a[105];
    scanf("%s",a+1);
    for(int i=1; a[i]!='\0'; i++)
    {
        if(i%2)
        {
            if(a[i]!='R'&&a[i]!='U'&&a[i]!='D')
            {
                flag=0;
                break;
            }
        }
        else
        {
            if(a[i]!='L'&&a[i]!='U'&&a[i]!='D')
            {
                flag=0;
                break;
            }
            }
    }
    if(flag)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

string inp;
int ans;
int next_num;

int main()
{
	cin >> inp;
	sscanf(inp.c_str(), "%d", &ans);
	//cout << ans << endl;

	while (cin >> inp)
	{
		if (inp == "=")
		{
			cout << ans << endl;
			break;
		}
		if (inp == "+")
		{
			cin >> inp;
			sscanf(inp.c_str(), "%d", &next_num);
			ans += next_num;
		}
		if (inp == "-")
		{
			cin >> inp;
			sscanf(inp.c_str(), "%d", &next_num);
			ans -= next_num;
		}
		if (inp == "*")
		{
			cin >> inp;
			sscanf(inp.c_str(), "%d", &next_num);
			ans *= next_num;
		}
		if (inp == "/")
		{
			cin >> inp;
			sscanf(inp.c_str(), "%d", &next_num);
			ans /= next_num;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1240
package main

/*
#include <stdio.h>
#include <stdlib.h>
void helloworld() {
    printf("Hello, World!\n");
}
int nextInt(){
	long long int a;
	if (scanf("%lld", &a) == 1){
		// printf("%d in C",a);
		// printf("成功");
	}else{
		// printf("失敗");
		// printf("failed to read integer.\n");
	}
	return a;
}
*/
import "C"
import "fmt"

func cNextInt() int {
	return int(C.nextInt())
}

func mini(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var ans, i int
	var a [100000]int

	N := cNextInt()
	x := cNextInt()
	for i = 0; i < N; i++ {
		a[i] = cNextInt()
	}

	for i = 1; i < N; i++ {
		diff := a[i-1] + a[i] - x
		if diff > 0 {
			ans += diff
			min := mini(diff, a[i])
			a[i] -= min
			diff -= min
			if diff > 0 {
				a[i-1] -= diff
			}
		}
	}
	fmt.Println(ans)
}


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

int n, m;
int k[10];
int s[10][10];
int p[10];

int main(void){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> k[i];
		for(int j = 0; j < k[i]; j++){
			cin >> s[i][j];
			s[i][j]--;
		} 
	}
	for(int i = 0; i < m; i++) cin >> p[i];

	int res = 0;
	for(int i = 0; i < 1<<n; i++){
		bool flag = true;
		for(int j = 0; j < m; j++){
			int num = 0;
			for(int l = 0; l < k[j]; l++){
				if(i>>s[j][l] & 1) num++;
			}
			if(num % 2 != p[j]) flag = false;
		}

		if(flag) res++;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

// int cnt[26];
// int cc[26];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string t = s;
    reverse(all(t));
    int l = 0,r = 0;
    int ad = 0;
    while(1){
        if(l+r>=len(s)-1){
            break;
        }
        if(s[l] != t[r]){
            if(s[l] == 'x'){
                l++;
                ad++;
            }else if(t[r] == 'x'){
                r++;
                ad++;
            }else{
                cout << "-1\n";
                return 0;
            }
        }else{
            l++,r++;
        }
    }
    cout << ad << "\n";
    // rep(i,len(s)){
    //     cnt[s[i]-'a']++;
    // }
    // int od = 0;
    // int id;
    // rep(i,26){
    //     if(i != 23){
    //         if(cnt[i] % 2 == 1){
    //             od++;
    //             id = i;
    //         }
    //     }
    // }
    // if(od >= 2){
    //     cout << "-1\n";
    // }else if(od == 1){
    //     rep(i,id){
    //         cc[s[i]-'a']++;
    //     }
    //     rep(i,id){
    //         cc[]
    //     }
    // }else{
    //
    // }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}

ll sosuu(ll x){
    for(int i = 2; i < x; i++){
        if(x % i == 0) return false;
    }

    return true;
}

//入力

int main(){

    int x;
    cin >> x;

    while(1){
        if(sosuu(x)){
            cout << x << endl;
            break;
        }
        x++;
    }

    return 0;
}

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

int dp[100][4][4];
int p[100], n, k;

int solve(int day, int bday, int bbday){
  int &tmp = dp[day][bday][bbday];
  if(day == n) return 1;
  if(tmp != -1) return tmp;
  if(p[day] != 0){
    return (bday == bbday && bday == p[day] ? 0 : solve(day+1,p[day],bday)%10000);
  }
  int ret = 0;
  for(int i = 1; i <= 3; i++){
    if(bbday == bday && bday == i) continue;
      ret += solve(day+1,i,bday) % 10000;
  }
  return tmp = ret % 10000;
}



int main(){

  cin >> n >> k;

  for(int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    p[a-1] = b;
  }

  memset(dp,-1,sizeof(dp));
  int ans = solve(0,0,0);

  cout << ans << endl;
}

Measured memory_bytes: 1172