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

int main() {

  int N;
  cin >> N;
  string ans = "No";
  
  for(int i = 0; i <= 25; i++){
    for(int j = 0; j <= 15; j++){
      if( 4 * i + 7 * j == N ) {
        ans = "Yes";
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    ll N;
    cin >> N;
    ll A, B;
    cin >> A >> B;
    if(A > B){
        cout << 0 << endl;
        return 0;
    }
    else if(N == 1){
        if(A == B){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
        return 0;
    }
    else{
            cout << (B - A) * (N - 2) + 1 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    *c, = map(lambda x: tuple(x), b.items())
    c.sort(key=lambda x: x[0], reverse=True)

    ans = 1
    count = 0
    for (k, v) in c:
        if v >= 4 and ans == 1:
            ans = k ** 2
            count += 2
            break
        if v >= 2:
            ans *= k
            count += 1
        if count == 2:
            break
    if count < 2:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl

const long long MOD = 1000000007;


int main(){
    ll a, b;
    cin >> a >> b;
    ll c = a+b;
    if(c%2 == 1){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << c/2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int[][] a=new int[3][3];
		int[] x=new int[3];
		int[] y=new int[3];
		Scanner sc=new Scanner(System.in);
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				a[i][j]=sc.nextInt();
			}
			
		}
		boolean flag=true;
		
			for(int k=0;k<100;k++) {
				x[0]=k;
				for(int i=0;i<3;i++) {
					y[i]=a[0][i]-x[0];
				}
				for(int i=0;i<3;i++) {
					x[i]=a[i][0]-y[0];
				}
				flag=true;
				for(int i=0;i<3;i++) {
					for(int j=0;j<3;j++) {
						if(x[i]+y[j]!=a[i][j]) {
							flag=false;
							break;
						}
					}
					
				}
				if(flag) {
					break;
				}
				
			}
			
			
		
		
		if(flag) {
			System.out.println("Yes");
		}
		else{
				System.out.println("No");
			}
		
	}

}


Measured memory_bytes: 23252
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
     a[i],b[i],c[i] = map(int,input().split())

dp = [[0] * 3 for i in range(n)]

dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

for i in range(1,n):
     dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i])
     dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i])
     dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i])

print(max(dp[n-1]))

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

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

  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int x = h1 * 60 + m1;
  int y = h2 * 60 + m2;

  cout << max(y - x - k, 0) << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    bool ans = false;
    for(int i = 1;i<=1000;i++) {
        if(a<=k*i && b>=k*i) {
            ans = true;
            break;
        }
    }
    if(ans)cout <<"OK" <<endl;
    else cout << "NG" <<endl;
}

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

int main(){
  string s;
  long long k;
  cin>>s>>k;
  if(s[0]!='1'){
    cout<<s[0]<<endl;
    return 0;
  }
  int f=0;
  int cnt;
  char num;
  for(int i=0;i<s.size();i++){
    if(s[i]=='1')continue;
    f=1;
    cnt=i;
    num=s[i];
    break;
  }
  if(f==0||k<=cnt)cout<<'1'<<endl;
  else cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;
LL ans=0,num1=0,pw2[100010],pw3[100010],dp[100010][2];

int main()
{
	cin>>s;
	pw2[0]=pw3[0]=1;
	repn(i,100005) pw2[i]=pw2[i-1]*2%MOD,pw3[i]=pw3[i-1]*3%MOD;
	if(s[0]=='0') dp[0][0]=1;
	else
	{
		dp[0][0]=2;
		dp[0][1]=1;
	}
	repn(i,s.size()-1)
	{
		if(s[i]=='1')
		{
			dp[i][1]=(dp[i-1][0]+dp[i-1][1]*3)%MOD;
			dp[i][0]=(dp[i-1][0]*2)%MOD;
		}
		else
		{
			dp[i][1]=(dp[i-1][1]*3)%MOD;
			dp[i][0]=dp[i-1][0];
		}
	}
	cout<<(dp[s.size()-1][0]+dp[s.size()-1][1])%MOD<<endl;
	rt0;
}

Measured memory_bytes: 3584
from collections import defaultdict

h, w, m = map(int, input().split())

cnt_h = [0] * h #各行の爆破対象マス
cnt_w = [0] * w #各列の爆破対象マス
dic = defaultdict(int) #

for _ in range(m): #爆破対象のマスそれぞれ
  h_m, w_m = map(int, input().split()) #位置を取得
  cnt_h[h_m -1] += 1 #行のカウント
  cnt_w[w_m -1] += 1 #列のカウント
  dic[(h_m - 1, w_m - 1)] += 1 #マス（交差地点）を保持

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
  if max_h == cnt_h[i]:
    mh.append(i)
    
for j in range(w):
  if max_w == cnt_w[j]:
    mw.append(j)

for i in mh:
  for j in mw:
    if dic[(i, j)] == 0:
      print(max_h + max_w)
      exit()

print(max_h + max_w - 1)

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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < (k); i++ )
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long L;
typedef unsigned long UL;
typedef long long LL;
typedef unsigned long long ULL;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void solve(__attribute__((unused)) int tc = 0) {
    LL n, ans = 0;
    cin >> n;

    for(LL i = 1; i * i <= n; i++) {
        if (n % i) continue;
        LL m = (n / i) - 1;
        if (m <= i) continue;
        ans += m;
    }

    cout << ans << endl;
    return;
}

int main() {
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    /*int TC;
      cin >> TC;
      REP(tc, TC) {
      solve(tc);
      }*/
    solve();
#ifdef TIME
    cout << "Execution time(second) : " << int(clock() * 1000.0 / CLOCKS_PER_SEC) << " ms" << endl;
#endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}
static const double pi = 3.141592653589793;
int main()
{
  long double A, B, H, M;
  cin >> A >> B >> H >> M;
  long double thetaA = (H * 30) + (M * 30 / 60);
  long double thetaB = 6 * M;
  thetaA = thetaA * pi / 180;
  thetaB = thetaB * pi / 180;

  pair<long double, long double> Apos, Bpos;
  Apos = make_pair(A * cosl(thetaA), A * sinl(thetaA));
  Bpos = make_pair(B * cosl(thetaB), B * sinl(thetaB));

  long double ans = pow(Apos.first - Bpos.first, 2) + pow(Apos.second - Bpos.second, 2);
  ans = sqrt(ans);
  cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 4172
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int[] a=new int[8];
    for(int i=0;i<3;i++)
    {
     int x=sc.nextInt();
      a[x]++;
    }
    if(a[5]==2 && a[7]==1)
    {
      System.out.println("YES");
    }
    else
    {
      System.out.println("NO");
    }
    
  }
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

signed main()
{
 //   int a,b,c;cin>>a>>b>>c;
//    int a;cin >> a;
vector<int> v(3,110);
cin >> v[0] >> v[1] >> v[2];
sort(v.begin(), v.end());
cout << v[0] + v[1];
	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{

    ll a;
    cin >> a;
    string b;
    cin >> b;

    if (a >= 3200)
    {
        cout << b << endl;
    }
    else
    {
        cout << "red" << endl;
    }
}

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

#define str(a) to_string(a)
#define int long long
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define N 1000001


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s, t;
    cin >> s >> t;
    bool flag = true;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            flag = false;
            break;
        }
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/07/07  Problem: ABC 133 A / Link: http://abc133.contest.atcoder.jp/tasks/abc133_a  ----- */


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

	LL N, A, B;
	cin >> N >> A >> B;
	LL ans = min(N*A, B);
	cout << (ans) << "\n";

	return 0;
}


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

n = int(input())

list_ = [0]*(10**4)
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            a = x**2+y**2+z**2+x*y+y*z+z*x
            if a <= 10**4:
                list_[a-1] += 1

for i in range(n):
    print(list_[i])


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    const int M = 26;
    vector<int> C(M);
    for(int i=0; i<M; i++) cin >> C[i];
    vector<vector<int>> S(D, vector<int>(M));
    for(int i=0; i<D; i++)
    {
        for(int j=0; j<M; j++)
        {
            cin >> S[i][j];
        }
    }
    vector<int> T(D);
    for(int i=0; i<D; i++)
    {
        cin >> T[i];
        T[i]--;
    }

    int ans = 0;
    vector<int> last(M, -1);
    for(int i=0; i<D; i++)
    {
        ans += S[i][T[i]];
        last[T[i]] = i;
        for(int j=0; j<M; j++)
        {
            ans -= C[j] * (i - last[j]);
        }
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	char s[3];
	map<string, int> m;
	while(~scanf("%*d,%2s",s))m[string(s)]++;
	printf("%d\n%d\n%d\n%d\n", m["A"], m["B"], m["AB"], m["O"]);
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

int main() {
  int R, G, B, N;
  scanf("%d %d %d %d", &R, &G, &B, &N);

  intmax_t res = 0;
  for (int r = 0; r <= N; ++r)
    for (int g = 0; g <= N; ++g) {
      int M = r*R + g*G;
      if (M > N) break;
      if ((N-M) % B) continue;
      ++res;
    }

  printf("%jd\n", res);
}



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

using namespace std;

using ll = long long;

int main(){
    ll n;
    cin >> n;
    vector<ll>v;
    double kanta = (double)n / 3.0;
    std::cout << std::fixed;
    cout << setprecision(6) << kanta * kanta * kanta;
    return 0;
}


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

from collections import deque

p = [(i+1)/2 for i in p]

d_front = deque(p[:k])
d_back = deque(p[k:])

sum_prev = sum(d_front)
ma = sum_prev

while d_back:
    ff = d_front.popleft()
    bf = d_back.popleft()
    sum_curr = sum_prev - ff + bf
    ma = max(ma, sum_curr)
    d_front.append(bf)
    sum_prev = sum_curr
    
print(ma)

Measured memory_bytes: 25060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
			FastScanner scanner = new FastScanner(System.in);
			String threeDigit = scanner.next();
			int sum = 0;
			for (int i = 0; i < 3; i++) {
				if (threeDigit.charAt(i)=='1') {
					sum++;
				}
			}
			PrintWriter printWriter = new PrintWriter(System.out);
			printWriter.printf("%d\n", sum);
			printWriter.close();
	}

	static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

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

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

			return tokenizer.nextToken("\n");
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public long nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = (int) nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(8);
    int wild = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a <= 399) v[0]++;
        else if(a <= 799) v[1]++;
        else if(a <= 1199) v[2]++;
        else if(a <= 1599) v[3]++;
        else if(a <= 1999) v[4]++;
        else if(a <= 2399) v[5]++;
        else if(a <= 2799) v[6]++;
        else if(a <= 3199) v[7]++;
        else wild++;
    }
    int mi = 0;
    for(int i=0; i<v.size(); i++) mi += (v[i] != 0);
    int mx = mi + wild;
    if(mi == 0) mi = 1;
    cout << mi << " " << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
N,M = map(int,(input().split()))
A = [list(map(int,input().split()[1:])) for i in range(N)]
numFav = [0]*M
for line in A:
    for a in line:
        numFav[a-1] = numFav[a-1] + 1
print(numFav.count(N))


Measured memory_bytes: 3060
#include <stdio.h>

// 4-14

//switch文を使ってみよう。
int main() {

	int D;

	scanf("%d", &D);

	switch (D) {
	case 25:
		printf("Christmas\n");
		break;
	case 24:
		printf("Christmas Eve\n");
		break;
	case 23:
		printf("Christmas Eve Eve\n");
		break;
	case 22:
		printf("Christmas Eve Eve Eve");
		break;
	}
	return 0;
	
}



Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)

ans = 10**20
for i in range(1,N):
    x = cums[i]
    y = cums[-1] - cums[i]
    ans = min(ans, abs(x-y))
print(ans)

Measured memory_bytes: 24832
/**
 *    author:  math2do
 *    created: 19.01.2020 00:29:06
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector <double> dp(n + 1);
  dp[0] = 1;
  for (int coin = 0; coin < n; coin++) {
    double head;
    cin >> head;
    for (int i = coin + 1; i >= 0; i--) {
      dp[i] = (i == 0 ? 0 : dp[i - 1] * head) + dp[i] * (1 - head);
    } 
  }
  
  double ans = 0;
  for (int heads = 0; heads <= n; heads++) {
    int tails = n - heads;
    if (heads > tails) {
      ans += dp[heads];
    } 
  }

  cout << fixed << setprecision(10) << ans << '\n';
  return 0;
}


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


def solve(Q: int, l: "List[int]", r: "List[int]"):
    # 10^5までの素数を予め計算しておく。
    INF = 100100
    is_prime = get_prime_numbers_array(INF)
    is_like = [0] * INF
    for i in range(INF + 1):
        if i % 2 == 0:
            continue
        if (is_prime[i] and is_prime[int((i+1)/2)]):
            is_like[i] = 1
    a = cumsum(is_like)
    for i in range(Q):
        print(a[r[i] + 1] - a[l[i]])
    return


def get_prime_numbers_array(n: int):
    """エラトステネスのふるいを用いてnまでの素数判定を行うための配列を返す

    Args:
        n ([int]): nまでの素数判定を行う
    """
    N = n + 1
    is_prime = [1] * N
    is_prime[0] = is_prime[1] = 0
    for i in range(2, N):
        if not is_prime[i]:
            continue
        for j in range(i * 2, N, i):
            is_prime[j] = 0
    return is_prime


def cumsum(data: "List[int]"):
    """dataの累積和の配列を求める。
 
    Args:
        data (List[int]): 累積和の配列を求めたい配列
    """
    a = [0] * (len(data) + 1)
    for i in range(len(data)):
        a[i + 1] = a[i] + data[i]
    return a


# Generated by 1.1.6 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()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]"
    r = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;
  for (int i = -1000; i <= 1000; ++i) {
    for (int j = -1000; j <= 1000; ++j) {
      if (1ll * i * i * i * i * i - 1ll * j * j * j * j * j == x) {
        cout << i << ' ' << j << "\n";
        return 0;
      }
    }
  }
  assert(false);
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

vector<int64> G[11234];
vector<int64> cnt, lab;
queue<int64> v;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int64 N;
  cin >> N;
  cnt.resize(N, 0);
  REP(i, N-1) {
    int64 a, b;
    cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
    cnt[a]++; cnt[b]++;
  }
  vector<int64> c(N);
  REP(i, N) cin >> c[i];
  int64 idx = 0;
  sort(all(c));
  lab.resize(N);
  vector<bool> visited(N, 0);
  REP(i, N) {
    if (cnt[i] == 1) {
      v.push(i);
      visited[i] = 1;
    }
  }
  int64 res = 0;
  while(v.size()) {
    int64 u = v.front(); v.pop();
    lab[u] = c[idx++];
    bool add = 0;
    REP(i, G[u].size()) {
      cnt[G[u][i]]--;
      if (!visited[G[u][i]]) {
        add = 1;
        if (cnt[G[u][i]] == 1) {
          v.push(G[u][i]);
          visited[G[u][i]] = 1;
        }
      }
    }
    if (cnt[u]) res += lab[u];
  }
  cout << res << endl;
  REP(i, N) cout << lab[i] << " ";
  cout << endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w; cin >> h >> w;
	int ans = INF;
	int sx, sy, sz;
	rep(i, w - 1) {
		sx = (i + 1)*h;
		sy = (h / 2)*(w - i - 1);
		sz = ((h + 1) / 2)*(w - i - 1);
		ans = min(ans, max(max(sx, sy), sz) - min(min(sx, sy), sz));
	}
	rep(i, h - 1) {
		sx = (i + 1) * w;
		sy = (w / 2)*(h - i - 1);
		sz = ((w + 1) / 2)*(h - i - 1);
		ans = min(ans, max(max(sx, sy), sz) - min(min(sx, sy), sz));
	}
	ans = min(ans, min(((w + 2) / 3)*h - (w / 3)*h, ((h + 2) / 3)*w - (h / 3)*w));
	cout << ans << endl;
	return 0;
}

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

#define 	ll				long long int
#define 	vi				vector<int>
#define		rep(i,n) 		for(i=0;i<n;i++)
#define		repe(i,I1,I2) 	for(i=I1;i<I2;i++)
#define		pb  			push_back
#define		mp  			make_pair
#define		endl			'\n'
#define 	mod				1000000007


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k,t,c=0,i;
	t=1;
	//cin>>t;
	string s;
	while(t--)
	{
		cin>>s;
		if(s.length()==2)
			cout<<s;
		else
		{
			reverse(s.begin(),s.end());
			cout<<s;
		}
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvpi vector<vpi>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,a,n) for(int i=a;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;
	
const int nax= 305;
double p[nax][nax][nax];
double ev[nax][nax][nax];
void solve(){
	fio;
	int n;
	cin>>n;
	vector<int> cnt(4);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		cnt[x]++;
	}
	p[cnt[1]][cnt[2]][cnt[3]]=1.0;
	for(int c=n;c>=0;c--){
		for(int b=n;b>=0;b--){
			for(int a=n;a>=0;a--){
				//cout<<c<<" "<<b<<" "<<a<<endl;
				if(a+b+c==0) continue;
				if(a+b+c>n)continue;
				double waste= (double)(n-a-b-c)/n;
				double e_waste= waste/(1-waste) +1;
				ev[a][b][c]+=e_waste*p[a][b][c];
				if(a){
					double pro= (double)a/(a+b+c);
					p[a-1][b][c]+= p[a][b][c]*pro;
					ev[a-1][b][c]+= ev[a][b][c]*pro;
				}
				if(b){
					double pro= (double)b/(a+b+c);
					p[a+1][b-1][c]+=p[a][b][c]*pro;
					ev[a+1][b-1][c]+= ev[a][b][c]*pro;
				} 
				if(c){
					double pro= (double)c/(a+b+c);
					p[a][b+1][c-1]+=p[a][b][c]*pro;
					ev[a][b+1][c-1]+= ev[a][b][c]*pro;
				}  
			}
		}
	}
	cout.precision(10);
	cout<<fixed<<ev[0][0][0]<<endl;
}

int32_t main(){
	#ifndef ONLINE_JUDGE
  		freopen("input.txt", "r", stdin);
  		freopen("output.txt", "w", stdout);
  	#endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){ 
		//cout<<"Case #"<<i<<":\n";
		solve();
	}
	return 0;
}


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

int ans[100005];

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




Measured memory_bytes: 1024
import copy
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())
p_list = [[int(j) for j in input().split()] for i in range(m)]

for p in p_list:
    tmp = copy.deepcopy(t)
    tmp[p[0]-1] = p[1]
    print(sum(tmp))

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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

bool dp[100100];

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

     cout << min(A+C,min(A+B,B+C)) << endl;

}



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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}
/****** define variable start ******/
ll a, b, n;
/******* define variable end *******/
int solve() {
	cin >> a >> b >> n;

	cout << (ll)(floor(a * (min(n, b-1))/b) - a * floor((min(n, b-1))/b)) << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3592
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace
import           Text.Printf


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int
getIntTuple = (\vec -> (vec VU.! 0, vec VU.! 1)) <$> getIntVector

main = do
  k <- getInt

  print $ genLunlun !! (k-1)

digit 0 = []
digit x = x `mod` 10 : (digit $ x `div` 10)

checkLunlun x = undefined

lengthInt x = length . show $ x

nextLunlun x
  | lastDigit == 0 = [10*x, 10*x+1]
  | lastDigit == 9 = [10*x+8, 10*x+9]
  | otherwise = [x*10+lastDigit-1 .. x*10+lastDigit+1]
  where
    lastDigit = x `mod` 10

genLunlun = [1..9] ++ concatMap nextLunlun genLunlun

modelAnswer = do
  k <- VUM.replicate 1 (0 :: Int)

  print ()


Measured memory_bytes: 10116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,l[200],sum;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>l[i];
    sort(l+1,l+1+n);
    for(int i=1;i<n;i++)sum+=l[i];
    if(l[n]<sum){cout<<"Yes\n";}
    else{cout<<"No\n";}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int ans = 0;
  int l = 0;
  for( int i = 0;i<s.size();i++){
    if( s.at(i) == 'A' || s.at(i)== 'G' || s.at(i) == 'T' || s.at(i) == 'C'){
      l +=1;
      ans = max(ans,l);
    }
    else{
      l = 0;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 1000000
int main() {
	int n, i, a, max, min;
	long int sum;
	max = -N; min = N; sum = 0;
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		if (max < a) max = a;
		if (min > a) min = a;
		sum += a;
	}

	printf("%d %d %ld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 2708
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;




int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); REP(i,n) cin >> a[i];
    int cnt = 0;
    REP(i,n) 
        if(a[i] != i+1) ++cnt;

    if(cnt == 2 || cnt == 0) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}


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

/* #define MULTI_INPUT 0 */

const ll MOD = 1000000007;

ll mod(ll b, int n) {
    if (n == 1) {
        return b;
    }
    ll m = mod(b, n / 2);
    m = (m * m) % MOD;
    if (n % 2 == 1) {
        m = (m * b) % MOD;
    }
    return m;
}

void solve()
{
    int n;
    cin >> n;
    ll ans = mod(10, n) - 2 * mod(9, n) + mod(8, n);
    ans %= MOD;
    if (ans < 0) {
        ans = MOD + ans;
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef MULTI_INPUT
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3648
H, W = map(int, input().split())
map = [["" for i in range(W)] for j in range(H)]
for i in range(H):
    tmp = input()
    for j in range(len(tmp)):
        map[i][j] = tmp[j]

def check_map(i, j):
    count = 0
    a1=j+1
    a2=j-1
    b1=i+1
    b2=i-1
    if(a2>=0):
        if(map[i][a2]=="#"):
            count+=1
    if(a1<W):
        if(map[i][a1]=="#"):
            count+=1
    if(b2>=0):
        if(map[b2][j]=="#"):
            count+=1
    if(b1<H):
        if(map[b1][j]=="#"):
            count+=1

    if(a2>=0 and b2>=0):
        if(map[b2][a2] == "#"):
            count+=1
    if(a1<W and b2>=0):
        if(map[b2][a1] == "#"):
            count+=1
    if(a1<W and b1<H):
        if(map[b1][a1] == "#"):
            count+=1
    if(a2>=0 and b1<H):
        if(map[b1][a2] == "#"):
            count+=1
    return str(count)

for i in range(H):
    for j in range(W):
        if(map[i][j] == "."):
            map[i][j] = check_map(i, j)

for i in range(H):
    for j in range(W):
        print(map[i][j],end="")
    print()


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,people,now[1001],poteto=1;;
    while(1){
        cin>>n>>people;
        if(n==0&&people==0)break;
        for(int i=1;i<=n;i++)now[i]=1;
        for(int i=0;i<n-1;i++){
            for(int j=0;j<people;j++){
            if(now[poteto]!=0){
                now[poteto]=1;
                for(int k=poteto;;k++){
                    if(k>n)k=1;
                    if(now[k]==1){
                            now[k]=2;
                            break;
                    }
                }
            }
            else j--;
            if(j==people-1){
                    now[poteto]=0;
                   // cout<<poteto<<endl;
            }
            poteto++;
            if(poteto>n)poteto=1;
        }
        }
        for(int i=1;i<=n;i++){
                if(now[i]==2||now[i]==1){
                    cout<<i<<endl;
                    break;
                }
        }
        poteto=1;
    }
}

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

template <class T, class Op> struct segtree {
  const Op op;
  const T e;
  const int n;
  vector<T> t;
  segtree(int _n, Op _op, T _e) : op(_op), e(_e), n(_n), t(2 * n, e) {}
  T& operator[](int i) { return t[n + i]; }
  void build() { for (int i = n; i-- > 1; ) t[i] = op(t[2 * i], t[2 * i + 1]); }
  T fold(int l, int r) const {
    T a = e, b = e;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) a = op(a, t[l++]);
      if (r & 1) b = op(t[--r], b);
    }
    return op(a, b);
  }
  void set(int i, T a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};
template <class T, class Op> auto make_segtree(int n, Op op, T e) {
  return segtree<T, Op>(n, op, e);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  auto st = make_segtree(n, [](int a, int b) { return a | b; }, 0);
  for (int i = 0; i < n; ++i) {
    st[i] = 1 << (s[i] - 'a');
  }
  st.build();
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      st.set(i, 1 << (c - 'a'));
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int res = __builtin_popcount(st.fold(l, r));
      cout << res << '\n';
    }
  }
}


Measured memory_bytes: 4892
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define L 20
#define Gard NULL

struct Tree{
  int nodekey;
  struct Tree *parent;
  struct Tree *leftch;
  struct Tree *rightch;
};

typedef struct Tree  *Search;
Search road;

void Insert(int );
void Pre(Search );
void In(Search );
Search Find(int ,Search);
void Delete(Search );
Search Suc(Search );
Search Min(Search );

int main(){
  int loop,numnode;
  char order[L];
  int i;
    
  scanf("%d",&loop);
  
  for(i=0;i<loop;i++){
    scanf("%s",order);
   
    if(order[0]=='i'){
      scanf("%d",&numnode);
      Insert(numnode);
    }
    
    else if(order[0]=='p'){
      In(road);
      printf("\n");
      Pre(road);
      printf("\n");
    }
    
    else if(order[0]=='f'){
      scanf("%d",&numnode);
    
      if(Find(numnode,road)!=Gard){
	printf("yes\n");
      }

      else{
	printf("no\n");
      }
    }

    else if(order[0]=='d'){
      scanf("%d",&numnode);
      Delete(Find(numnode,road));
    }
    
  }
  
  return 0;
}

void Insert(int numnode){
  Search xnode,ynode,znode;
  
  xnode=road;
  ynode=Gard;
  znode=malloc(sizeof(struct Tree));
  znode->nodekey=numnode;
  znode->leftch=Gard;
  znode->rightch=Gard;
  
  while(1){
    if(xnode==Gard)break;
    
    ynode=xnode;
    
    if(znode->nodekey<xnode->nodekey){
      xnode=xnode->leftch;
    }
    
    else{
      xnode=xnode->rightch;
    }
  }
  
  znode->parent=ynode;
  
  if(ynode==Gard){
    road=znode;
  }
  
  else if(znode->nodekey<ynode->nodekey){
    ynode->leftch=znode;
  }
  
  else{
    ynode->rightch=znode;
  }
  
}

void Pre(Search road){
  
  if(road==Gard){
    return;
  }
  
  printf(" %d",road->nodekey);
  
  Pre(road->leftch);
  Pre(road->rightch);
  
}

void In(Search road){
  
  if(road==Gard){
    return;
  }
  
  In(road->leftch);
  
  printf(" %d",road->nodekey);
  
  In(road->rightch);
}

Search Find(int numnode, Search road){
  
  if((road==Gard) || (numnode==road->nodekey)){
    return road;
  }
  
  else if(numnode<road->nodekey){
    return Find(numnode,road->leftch);
  }
  
  else{
    return Find(numnode,road->rightch);
  }
}

void Delete(Search znode){
  Search xnode,ynode;

  if((znode->leftch==Gard) || (znode->rightch==Gard)){
    ynode=znode;
  }

  else{
    ynode=Suc(znode);
  }

  if(ynode->leftch!=Gard){
    xnode=ynode->leftch;
  }

  else{
    xnode=ynode->rightch;
  }

  if(xnode!=Gard){
    xnode->parent=ynode->parent;
  }

  if(ynode->parent==Gard){
    road=xnode;
  }

  else if(ynode==ynode->parent->leftch){
    ynode->parent->leftch=xnode;
  }

  else{
    ynode->parent->rightch=xnode;
  }

  if(ynode!=znode){
    znode->nodekey=ynode->nodekey;
  }
}

Search Suc(Search znode){
  Search judge;

  if(znode->rightch!=Gard){
    return Min(znode->rightch);
  }

  judge=znode->parent;
  while((znode==judge->rightch) && (judge!=Gard)){
    znode=judge;
    judge=judge->parent;
  }

  return judge;
}

Search Min(Search zright){

  while(1){
    if(zright->leftch==Gard)break;

    else{
      zright=zright->leftch;
    }
  }

  return zright;
}



Measured memory_bytes: 20444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		String N = sc.next();
		
		char[] NcharArray = N.toCharArray();
		int sum = 0;
		for (int i = 0; i < NcharArray.length; i++) {
			sum +=Character.getNumericValue(NcharArray[i]);
		}
		
		// 結果の出力
		if (sum % 9 == 0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
		sc.close();
	}
}


Measured memory_bytes: 40668
#include <stdio.h>
int main(){
  int N,a,b;
  scanf("%d",&N);
  if (10<=N<100){
    a=N/10;
    N=N-10*a;
  }
  if (100<=N<1000){
    a=N/100;
    b=N/10;
    N=N-100*a-10*b;
  }
  if ((N==2)||(N==4)||(N==5)||(N==7)||(N==9)){
    printf("hon\n");
  }
  if ((N==0)||(N==1)||(N==6)||(N==8)){
    printf("pon\n");
  }
  if (N==3){
    printf("bon\n");
  }
  return 0;
}

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

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

  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, m;
vector<pair<ll, ll>> xy;

void solve() {
    unordered_map<ll, ll> mp;
    rep(i, n) mp[i]++;
    set<ll> idx_red;
    idx_red.insert(0);
    rep(i, m) {
        ll x = xy[i].first, y = xy[i].second;
        if (idx_red.count(x) != 0) {
            if (mp[x] == 1) idx_red.erase(x);
            idx_red.insert(y);
        }
        mp[x]--, mp[y]++;
    }
    cout << idx_red.size() << endl;
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        xy.emplace_back(make_pair(x, y));
    }
    solve();
    return 0;
}

Measured memory_bytes: 10608
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
  int n,m;
  int a,b;
  cin>>n>>m;
  int s=0,t=0;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    if(a<n){
      s+=(n-a);
      t=max(t,n-a);
    }
  }
  cout<<s-t<<endl;
  return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e2 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int N, next[maxn], f[maxn];
char s1[maxn], s2[maxn];
inline void getnext()
{
    next[1] = 0;
    for (ri i = 2, j = 0; i <= N; ++i) {
        while (j > 0 && s2[j + 1] != s2[i]) {
            j = next[j];
        }
        if (s2[j + 1] == s2[i]) {
            ++j;
        }
        next[i] = j;
    }
}
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    N = read();
    scanf("%s", s1 + 1), scanf("%s", s2 + 1);
    getnext();
    for (ri i = 1, j = 0; i <= N; ++i) {
        while (j > 0 && s1[i] != s2[j + 1]) {
            j = next[j];
        }
        if (s1[i] == s2[j + 1]) {
            j++;
        }
        f[i] = j;
    }
    writeln(N + N - f[N]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC137();
}

void ABC137(){
    int k,x,i;
    cin>>k>>x;
    vector<int> vec;
    vec.push_back(x);
    for(i=1;i<k;i++){
        vec.push_back(x+i);
        vec.push_back(x-i);
    }
    sort(vec.begin(),vec.end());
    for(i=0;i<vec.size();i++){
        if(i<vec.size()-1)cout<<vec[i]<<" ";
        else cout<<vec[i]<<endl;
    }
}

Measured memory_bytes: 256