akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;

const int mod = 1'000'000'007;

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

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int ways[19];
int f[109][19];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  ways[0] = 1;
  ways[1] = 2;
  for (int i = 2; i <= w; ++i) {
    ways[i] = ways[i - 1];
    add(ways[i], ways[i - 2]);
  }
  memset(f, 0, sizeof f);
  f[h][0] = 1;
  for (int i = h - 1; i >= 0; --i) {
    for (int j = 0; j < w; ++j) {
      add(f[i][j], mul(f[i + 1][j], mul(ways[max(0, j - 1)], ways[max(0, w - 2 - j)])));
      if (j - 1 >= 0) {
        add(f[i][j], mul(f[i + 1][j - 1], mul(ways[max(0, j - 2)], ways[max(0, w - 2 - j)])));
      }
      if (j + 1 < w) {
        add(f[i][j], mul(f[i + 1][j + 1], mul(ways[max(0, j - 1)], ways[max(0, w - 3 - j)])));
      }
    }
  }
  cout << f[0][k - 1] << endl;
}


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

using namespace std;

int main()
{
  string s,t;
  int n;
  cin>>n>>s>>t;
  int beg=n;
  for(int i=0;i<n;i++)
    if(s.substr(i,n-i)==t.substr(0,n-i))
      beg=min(beg,i);
  cout<<beg+n<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

import javax.lang.model.util.ElementScanner6;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int r=Integer.parseInt(scan.next());
		double PI =Math.PI;
		System.out.print(r*2*PI);


	}
}
//end


Measured memory_bytes: 35816
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long cntr=0,sum=0;
        while(h!=1)
        {
            sum+=(long)Math.pow(2,cntr);
            h/=2;
            cntr++;
        }
        sum+=(long)Math.pow(2,cntr);
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,M = map(int,input().split())
X = [int(x) for x in input().split()]

counter = [0] * M
pair_counter = [0] * M
se = set()

for x in X:
    r = x%M
    counter[r] += 1
    if x in se:
        pair_counter[r] += 1
        se.remove(x)
    else:
        se.add(x)

answer = 0
for r in range(1,(M+1)//2):
    s = M - r
    cr,cs = counter[r], counter[s]
    pr,ps = pair_counter[r], pair_counter[s]
    if cr < cs:
        cr,cs = cs,cr
        pr,ps = ps,pr
    x = cs + min(pr,(cr-cs)//2)
    answer += x

# 0とM//2
rs = [0] if M&1 else [0,M//2]
answer += sum(counter[r]//2 for r in rs)

print(answer)

Measured memory_bytes: 17000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int N = in.nextInt(), W = in.nextInt();
			int[] v = new int[N], w = new int[N];
			for (int i = 0; i < N; i++) {
				v[i] = in.nextInt(); w[i] = in.nextInt();
			}

			int[][] dp = new int[N+1][W+1];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j <= W; j++) {
					if (j >= w[i]) {
						dp[i+1][j] = Math.max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
					} else {
						dp[i+1][j] = dp[i][j];
					}
				}
			}
			out.println(dp[N][W]);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

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

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 29244
#include<iostream>
using namespace std;
int main(){
	int a,b,c,i;
	int n=0;
	int s[300];
	while(cin>>a>>b){
		a+=b;
		c=10;
		for(i=1;i<10;i++){
			if(a<c){
				break;
			}
			c*=10;
		}
		s[n]=i;
		n++;
	}
	for(i=0;i<n;i++){
		cout<<s[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from math import ceil
from collections import deque

n, d, a = map(int, input().split())
m = sorted([list(map(int, input().split())) for _ in range(n)])
m = [[x, ceil(h / a)] for x, h in m]

acc_damage = 0
que = deque()
ans = 0
for x, h in m:
    while que and x > que[0][0]:
        limit, damage = que.popleft()
        acc_damage -= damage

    rest_h = max(0, h - acc_damage)
    ans += rest_h
    acc_damage += rest_h

    if rest_h:
        que.append([x + 2 * d, rest_h])

print(ans)

Measured memory_bytes: 137432
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll H, W;
  cin >> H >> W;
  vvl A(H, vl(W, 0));
  string row;
  queue<vl> que;
  rep(i, H){
    cin >> row;
    rep(j, W){
      if(row[j] == '#'){
        A[i][j] = 1;
        que.push({i, j});
      }
    }
  }

  ll cnt = 0;
  vl frt, bck;

  while(true){
    bck = que.back();

    while(true){
      frt = que.front();
      que.pop();

      if((frt[0] > 0) && (A[frt[0] - 1][frt[1]] == 0)){
        A[frt[0] - 1][frt[1]] = 1;
        que.push({frt[0] - 1, frt[1]});
      }
      if((frt[0] < H - 1) && (A[frt[0] + 1][frt[1]] == 0)){
        A[frt[0] + 1][frt[1]] = 1;
        que.push({frt[0] + 1, frt[1]});
      }
      if((frt[1] > 0) && (A[frt[0]][frt[1] - 1] == 0)){
        A[frt[0]][frt[1] - 1] = 1;
        que.push({frt[0], frt[1] - 1});
      }
      if((frt[1] < W - 1) && (A[frt[0]][frt[1] + 1] == 0)){
        A[frt[0]][frt[1] + 1] = 1;
        que.push({frt[0], frt[1] + 1});
      }
	
      if((bck[0] == frt[0]) && (bck[1] == frt[1])) break;
    }

    if(que.empty()) break;
    cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 63540
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  int x,y,z;
	cin >> x >> y >> z;
	cout << z << " " << x << " "<< y << "\n";
}


Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) cin >> arr[i];
	sort(all(arr));
	ll ans = INF;
	for(int i = 1; i <= 100; i++) {
		ll now = 0;
		for(int j = 0; j < n; j++) {
			now+=(arr[j]-i)*(arr[j]-i);
		}
		ans=min(ans, now);
	}
	cout <<ans;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

const double eps = 1e-7;
const int MOD = 1000000007;
const int MOD_MAX = 200000;

using ll = long long;
using vi = vector<int>; using vi2 = vector<vi>; using vi3 = vector<vi2>;
using vll = vector<ll>; using vll2 = vector<vll>; using vll3 = vector<vll2>;
using vd = vector<double>; using vd2 = vector<vd>; using vd3 = vector<vd2>;
using pi = pair<int, int>; using pll = pair<ll, ll>;
using vpi = vector<pi>; using vpll = vector<pll>;

#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)
#define looplleq(i, n) for (ll i = 0; i <= (ll)n; i++)
#define rloopi(i, a, b) for(int i = (int)a - 1; i >= (int)b; i--)
#define rloop(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define rloopeq(i, n) for (int i = (int)n - 1; i >= 1; i--)
#define rloopll(i, n) for (int i = (ll)n - 1; i >= 0; i--)
#define rlooplleq(i, n) for (int i = (ll)n - 1; i >= 1; i--)
#define all(a) (a).begin(), (a).end()

bool feq(float x, float y) { return abs(x-y) <= eps; }
bool deq(double x, double y) { return abs(x-y) <= eps; }
int ceillog2(ll x) { return int (ceil(log2(x))); }
int floorlog2(ll x) { return int (floor(log2(x))); }
template<class T> T reversed (T container) { reverse(container.begin(), container.end()); return container; }
template<class T> T sort (T container) { sort(container.begin(), container.end()); return container; }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

int main() {
	string s; cin >> s;
	int q; cin >> q;
	int rev = 0;
	int front = 1;
	loop(i, q) {
		int qi; cin >> qi;
		if (qi == 2) {
			int fi; cin >> fi;
			char ci; cin >> ci;
			//if ((fi == 1 && front == 1) || (fi == 2 && front == 0)) {
			if ((fi == 1 && front == 1) || (fi == 2 && front == 0)) {
				s.insert(s.begin(), ci);
			}
			else {
				s.push_back(ci);
			}
			//front = 1 ^ front;
		}
		else {
			rev = 1 ^ rev;
			front = 1 ^ front;
		}
	}
	if (rev) cout << reversed(s) << endl;
	else cout << s << endl;
}


Measured memory_bytes: 1156
class UF():
  def __init__(self, N):
    self.parents = [-1] * N

  def find(self, n):
    if self.parents[n] < 0:
      return n
    else:
      self.parents[n] = self.find(self.parents[n])
      return self.parents[n]

  def union(self, u,v):
    p1,p2 = self.find(u),self.find(v)
    if p1==p2: return
    if p1 > p2:
      p1,p2 = p2,p1
    self.parents[p1] += self.parents[p2]
    self.parents[p2] = p1

  def same(self, u,v):
    return self.find(u) == self.find(v)

  def weight(self, u):
    p = self.find(u)
    return -self.parents[p]

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

uf = UF(N+1)
for i in range(M):
  u,v,z = map(int,input().split())
  uf.union(u,v)

ans = 0
for i in range(1, N+1):
  if uf.parents[i] < 0:
    ans += 1

print(ans)

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for(int i = 0; i < m; i++){
        cin >> x.at(i);
    }
    sort(x.begin(), x.end());
    reverse(x.begin(), x.end());
    vector<int> sub(m-1);
    for(int i = 0; i < m-1; i++){
        sub.at(i) = x.at(i) - x.at(i+1);
    }
    sort(sub.begin(), sub.end());
    reverse(sub.begin(), sub.end());
    int sum = 0;
    for(int i = n-1; i < m-1; i++){
        sum = sum + sub.at(i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n ,k;
    cin >> n >> k;
    bool a[n];
    memset(a, 0,sizeof(a));
    int d;
    int b;
    for(int i=0;i<k;i++){
    	cin >> d;
    	for(int j=0;j<d;j++){
    		cin >>b;
    		b--;
    		a[b] = true;
    	}
    }
    int ans = 0;
    for(int i=0;i<n;i++) if(!a[i])ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
const int mod=998244353;
const int N=1e6+7;
typedef long long ll;
ll freq[N];
ll inv[N],A[N];
ll r[N];
inline ll add(ll x, ll y) {
    return (x+y)%mod;
}
inline ll sub(ll x, ll y) {
    return ((x-y)%mod + mod)%mod;
}
inline ll mult(ll x, ll y) {
    return ((x%mod )*( y%mod)) % mod;
}

inline ll binpow(ll a, ll b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t,n,x;
	inv[0]=1;
	inv[1]=1;
	for(int i=2;i<=(int)1e6;i++) inv[i]=binpow(i,mod-2);
	t=1;
	while(t--){
		ll respt=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d",&x);
            A[i]=x;
			freq[x]++;
		}
		for(int i=(int)1e6;i>0;i--){
			ll sum=0,res=0;
			for(int j=i;j<=(int)1e6;j+=i) sum=add(sum,mult(j,freq[j]));
			for(int j=i;j<=(int)1e6;j+=i) res=add(res,mult(inv[i],mult(j,mult(freq[j],sum))));
			for(int j=2*i;j<= (int)1e6;j+=i) res =sub(res,mult(r[j],mult(j,inv[i])));
			r[i] = res;
			respt=add(respt,res);
		}
        for(int i=0;i<n;i++){
            respt=sub(respt,A[i]);
        }
        x=binpow(2,mod-2);
        respt=mult(respt,x);
		cout << respt << endl;
		memset(freq,0,sizeof freq);
		memset(r,0,sizeof r);
	}
}


Measured memory_bytes: 27392
import sys
input = sys.stdin.readline
num = []
iti = []

for temp in range(5):
    temp2 = input()
    temp3 = int(temp2)
    if temp3 >= 10 and temp2[-2] != "0":
        num.append((int(temp2[0:-2])+1)*10)
    elif temp2[-2] == "0":
        num.append(int(temp2[0:-2])*10)
    else:
        num.append(10)
    if int(temp2[-2]) != 0:
        iti.append(int(temp2[-2]))

if iti == []:
    last = 10
else:
    last = min(iti)
print(sum(num)-10+last)

Measured memory_bytes: 3316
#include <stdio.h>
#define MAX 100005
#define OUT -1
struct Node{
  int p;
  int l;
  int r;
};

void depth(int,int);
void print(int);
//using namespace std;

struct Node T[MAX];
int n, A[MAX];

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].r = OUT;
    T[i].l = T[i].r;
    T[i].p = T[i].l;
  }
  for(i = 0; i < n; i++){
    scanf("%d",&v);
    scanf("%d",&d);
    for(j = 0; j < d; j++){
      scanf("%d",&c);
    if(j == 0){
      T[v].l = c;
    }
    else{
      T[l].r = c;
    }
    l = c;
    T[c].p = v;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == OUT){
      r = i;
    }
  }
  depth(r,0);
  for(i = 0; i < n; i++){
    print(i);
  }
  return 0;
}// end of main func

void depth(int u, int p){
  A[u] = p;
  if(T[u].r != OUT){
    depth(T[u].r,p);
  }
  if(T[u].l != OUT){
    depth(T[u].l , p+1);
  }
}//end of depth func

void print(int u){
int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",A[u]);
  if(T[u].p == OUT){
    printf("root, ");
  }
  else if(T[u].l == OUT){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }
  printf("[");
  for(i = 0, c = T[u].l; c != OUT; i++, c = T[c].r){
    if(0 < i){
      printf(", ");
    }
    printf("%d",c);
  }
  printf("]\n");
}//end of print func

Measured memory_bytes: 5296
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, a, b, c, d;
	cin >> a >> b >> c >> d;
	while (a > 0) {
		c -= b;
		if (c <= 0) {
			printf("Yes\n");
			return 0;
		}
		a -= d;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const int mod = 2019;
int main() {
    string s;
    cin >> s;
    int n = s.size();
    int fac = 1;
    map<int,int>mp;
    int ans = 0;
    mp[0] = 1;
    ll cur = 0;
    for(int i = 0;i<n;i++) {
        cur += (s[n-1-i]-'0')*fac;
        cur %= mod;
        ans += mp[cur];
        mp[cur]++;
        fac = fac*10%mod;
    }
    cout << ans << endl;
}
    




Measured memory_bytes: 3740
#include <iostream>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main(void){
int N;
cin>>N;
int ans=0;

for(int i=1;i<=N;i++){
    int cout=0;
    double n=sqrt(i);
    for(int j=1;2*j+1<n;j++){
        if(i%(2*j+1)==0) cout++;
    }
    if(cout==3&&(i%2==1)) {ans++;}
    
}
cout<<ans;
return 0;
}


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

int main() {
	ll Ans=0;
	ll N; cin >> N;
	for(int i=1; i<N; i++){
		for(int j=1; i*j<N; j++){
			Ans++;
		}
	}
	cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 3628
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
cnt = 0

for i in range(n):
    sum = c
    for j in range(m):
        sum += a[i][j] * b[j]
    if sum > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in1 = s.nextInt();
        while(true){
            int in2 = s.nextInt();
            int count = 0;
            for(int i = in1; i <= in2 ; i++){
                if((i%4 == 0 && i%100 != 0) || (i%4 == 0 && i%400 == 0)){
                    System.out.println(i);
                    count++;
                }
            }
            if(count==0)
                System.out.println("NA");
            in1 = s.nextInt();
            if(in1==0)
                break;
            System.out.println();
         }

     }
}

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

int main () {
  int a, b;
  cin >> a >> b;
  
  int ans;
  if (a <= 9 && b <= 9) {
    ans = a*b;
  }
  else {
    ans = -1;
  }
  cout << ans << endl;
}

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

const int MN = 1010;

int N, K;
int psum[4*MN][4*MN];

void add(int x1, int y1, int x2, int y2) {
    x1 %= (2*K);
    x2 %= (2*K);
    y1 %= (2*K);
    y2 %= (2*K);

    if(x1 > x2) x2 += (2*K);
    if(y1 > y2) y2 += (2*K);

    psum[x1][y1]++;
    psum[x1][y2 + 1]--;
    psum[x2 + 1][y1]--;
    psum[x2 + 1][y2 + 1]++;
}

int main() {
    scanf("%d %d", &N, &K);

    memset(psum, 0, sizeof(psum));

    for(int i = 0; i < N; i++) {
        int x, y; char c; scanf("%d %d %c", &x, &y, &c);

        if(c == 'B') add(x + 1, y + 1, x + K, y + K);
        else add(x + 1 + K, y + 1, x + 2*K, y + K);
    }

    for(int i = 0; i < 4*K; i++) {
        for(int j = 0; j < 4*K; j++) {
            if(i) psum[i][j] += psum[i - 1][j];
            if(j) psum[i][j] += psum[i][j - 1];
            if(i && j) psum[i][j] -= psum[i - 1][j - 1];
        }
    }

    /*
    for(int i = 0; i < 4*K; i++) {
        for(int j = 0; j < 4*K; j++) {
            cout << psum[i][j] << ' ';
        }
        cout << endl;
    }
    //*/

    for(int i = 0; i < 4*K; i++) {
        for(int j = 0; j < 4*K; j++) {
            if(i >= 2*K || j >= 2*K) {
                psum[i % (2*K)][j % (2*K)] += psum[i][j];
            }
        }
    }

    /*
    for(int i = 0; i < 2*K; i++) {
        for(int j = 0; j < 2*K; j++) {
            cout << psum[i][j] << ' ';
        }
        cout << endl;
    }
    //*/

    for(int i = K; i < 2*K; i++) {
        for(int j = 0; j < 2*K; j++) {
            if(j < K) {
                psum[i - K][j + K] += psum[i][j];
            }
            else psum[i - K][j - K] += psum[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < 2*K; i++) {
        for(int j = 0; j < 2*K; j++) {
            ans = max(ans, psum[i][j]);
        }
    }

    cout << ans;
}


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

using namespace std;
using ll = long long;

bool reversed = false;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    deque<char> s;
    string input;
    cin>>input;
    for(char c: input){
        s.push_back(c);
    }

    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int t;
        cin>>t;
        if(t==1){
            reversed = !reversed;
        }else{
            int f;
            char c;
            cin>>f>>c;

            f--;
            if((bool)f^reversed){
                s.push_back(c);
            }else{
                s.push_front(c);
            }
        }
    }
    if(reversed){
        for(auto i=s.rbegin();i!=s.rend();i++){
            cout<<*i;
        }
    }else{
        for(char c: s)
            cout<<c;
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];

    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < N; i++) {
        int back1 = abs(h[i] - h[i - 1]);
        int back2 = abs(h[i] - h[i - 2]);
        dp[i]     = min(dp[i - 1] + back1, dp[i - 2] + back2);
    }
    cout << dp[N-1] << endl;
}

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

int main(){
  int A, B, C;
  cin>>A>>B>>C;
  if(A == B && B == C) cout << "No" << endl;
  else if(A != B && B != C && A != C) cout << "No" << endl;
  else cout << "Yes" << endl;
  
}


Measured memory_bytes: 256
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
              #if (d[i][k] != float("INF")) and (d[k][j] != float("INF")):
                d[i][j] = min(d[i][k] + d[k][j], d[i][j])
                
        #print(d)
    return d

##############################
n,m = map(int,input().split()) #n:頂点数　m:辺の数

d = [[float("INF")] * n for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)

hen = [0] * m
for i in range(m):
    x,y,z = map(int,input().split())
    d[x - 1][y - 1] = z
    d[y - 1][x - 1] = z
    hen[i] = [x - 1, y - 1, z]
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０

ans = warshall_floyd(d)
#それぞれの出発地点ごとにmaxをとり、そのmaxが最小の地点に引っ越し
#そのときの所要時間がp
#print(used)
answer = 0
for i in range(m):
  now = hen[i]
  if d[now[0]][now[1]] != now[2]:
    answer += 1
  
print(answer)  



Measured memory_bytes: 9336
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <string>
using namespace std;

const int qq = 1e5 + 10;
int num[qq];
int n, m, k;
int main(){
	scanf("%d%d", &n, &m);
	if(n == m){
		puts("Draw");
		return 0;
	}
	if(n == 1){
		puts("Alice");
	}else if(m == 1){
		puts("Bob");
	}else if(n > m){
		puts("Alice");
	}else{
		puts("Bob");
	}
	return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
#include<math.h>
int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(abs(a-c)<=d) printf("Yes\n");
    else if(abs(a-b)<=d&&abs(b-c)<=d) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

using namespace std;

template <typename T> class FenwickTree {
  private:
    std::vector<T> ft;

  public:
    FenwickTree(int sz) : ft(sz + 1, 0) {}

    void add(int idx, T x) {
        for (int i = idx + 1; i < static_cast<int>(ft.size()); i += i & -i) {
            ft[i] += x;
        }
    }

    T operator()(int idx) const {
        T res = 0;
        for (int i = idx + 1; i > 0; i -= i & -i) {
            res += ft[i];
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        C[i]--;
    }
    vector<vector<pair<int, int>>> L(N);
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        L[r].emplace_back(make_pair(l, i));
    }
    vector<int> res(Q);
    unordered_map<int, int> mp;
    FenwickTree<int> ft(N + 1);
    for (int i = 0; i < N; i++) {
        if (mp.count(C[i]) > 0)
            ft.add(mp[C[i]], -1);
        ft.add(i + 1, 1);
        mp[C[i]] = i + 1;
        for (auto &x : L[i]) {
            res[x.second] = ft(i + 1) - ft(x.first);
        }
    }
    for (auto r : res) {
        cout << r << '\n';
    }
    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9;
const llong LINF = 2e18;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// ATCODER RATING!!!

// Code below

llong N;

void inp() {
    cin >> N;
}

void solve() {
    for (llong n = 1; n <= 3500; ++n) {
        for (llong h = 1; h <= 3500; ++h) {
            if ((4 * h * n - N * (h + n)) > 0 && (n * h * N) % (4 * h * n - N * (h + n)) == 0) {
                cout << n << ' ' << h << ' ' << (n * h * N) / (4 * h * n - N * (h + n));
                cout << endl;
                return;
            }
        }
    }
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    cerr << endl << "Time: " << clock() / 1000.0 << " ms";
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>

using namespace std;

inline int read()
{
  int x=0,f=1;char ch=getchar();
  while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
  while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
  return x*f;
}

const int maxn = 3e5+1e2;

struct Node{
	int e,w;
}; 

Node a[maxn],b[maxn];
char s[maxn];
int n;

int main()
{
  cin>>n;
  scanf("%s",s+1);
  for (int i=1;i<=n;i++)
  {
  	a[i]=a[i-1];
  	if (s[i]=='E') a[i].e++;
  	else a[i].w++;
  }
  for (int i=n;i>=1;i--)
  {
  	 b[i]=b[i+1];
  	 if (s[i]=='E') b[i].e++;
  	 else b[i].w++;
  }
  int ans=1e9;
  for (int i=1;i<=n;i++)
  {
  	ans=min(ans,a[i-1].w+b[i+1].e);
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 5248
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val An = readLine()!!.split(" ").map(String::toInt)
    val employees: MutableList<MutableList<Int>> = (1..N).map { mutableListOf<Int>() }.toMutableList()
    // [i][j] = j belongs to i

    An.indices.forEach {
        employees[An[it] - 1].add(it + 2 - 1)
    }
    employees.forEach { row -> 
        row.size.run(::println)
    }
}

Measured memory_bytes: 90680
import math
x = int(input())
ans = 0
memo = {}
for i in range(1, x+1):
    for j in range(1, x+1):
        a,b = min(i,j), max(i,j)
        if (a,b) in memo.keys():
            l = memo[(a,b)]
        else:
            l = math.gcd(a,b)
            memo[(a,b)] = l
        for k in range(1, x+1):
            ans += math.gcd(l,k)
print(ans)

Measured memory_bytes: 71924
#coding:utf-8
import fractions
a, b, c, d = map(int, input().split())

# cで割り切れる個数を求める
c_div = (b // c) - ((a-1) // c)
#print(c_div)

# dで割り切れる個数を求める
d_div = (b // d) - ((a-1) // d)
#print(d_div)

# cとd両方で割り切れる数を求める
cd = (c * d) // fractions.gcd(c, d)
cd_div = (b // cd) - ((a-1) // cd)
#print(cd_div)

div =  c_div  + d_div - cd_div

print((b-a+1)-div)

Measured memory_bytes: 5048
#include <stdio.h>
#include <stdlib.h>
int c(const void *v1,const void *v2){
    int *x=(int *)v1;
    int *y=(int *)v2;
    return y[0]-x[0];
}
int main(void){
    int n,m,line[1000][2],i,sum=0,t,f,o=0,res=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d %d",&t,&f);
        t>=n?sum++:(line[o][0]=t,line[o++][1]=f);
    }
    if(sum >= m-1)
        puts("0");
    else{
        qsort(line,o,sizeof(int)*2,c);
        for(i=0;i<m-1-sum;i++)
            res+=n-line[i][0];
        printf("%d\n",res);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll a, b, fact[100100];

int main() {
    cin >> a >> b;
    fact[0] = 1;
    for(ll i = 1; i <= 100100 - 1; ++i)
        fact[i] = (fact[i-1]*i)%MOD;
    if (a == b) {
        cout << (fact[a]*fact[b]%MOD*2)%MOD;
    } else if (abs(a - b) <= 1) {
        cout << (fact[a]*fact[b])%MOD;
    } else cout << 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
    if(s.size() % 2 == 1){cout << "No" <<endl;
                         return 0;}
  for(int i=0; i<n/2 ;i++){
    if(s.at(i) == s.at(i+(n/2))){continue;}
    else{cout << "No" << endl;
         return 0;
        }
  }
cout << "Yes" << endl;
}
    
    


Measured memory_bytes: 256
import collections

n=int(input())
s=[]

for i in range(n):
    s.append(input())

d=collections.Counter(s).most_common()

ans=[]
past=d[0][1]

for i,m in d:
    if past==m:
        ans.append(i)
        past=m
    else:
        break

ans.sort()
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 45040
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    sa = [0]
    for a in A:
        sa.append(sa[-1] + a)

    b = []
    for i in range(N-1):
        if 2*sa[i+1] >= A[i+1]:
            b.append(True)
        else:
            b.append(False)
    b.append(True)

    ans = 0
    for c in b[::-1]:
        if c:
            ans += 1
        else:
            break
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16640
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
ans = 0
for i in ac.items():
    if i[0] != i[1]:
        if i[1] > i[0]:
            ans += i[1] - i[0]
        else:
            ans += i[1]
print(ans)

Measured memory_bytes: 18672
from math import *
s=int(input())
x1=ceil(sqrt(s))
if x1>10**9:
    x1-=1
y2=ceil(s/x1)
if y2>10**9:
    y2-=1
x2=x1*y2-s
print(0,0,x1,1,x2,y2)

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

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

  bool isFour = false;
  rep(i, N){
    string S;
    cin >> S;
    if(S=="Y") isFour=true;
  }

  if(isFour) 
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
  
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 200000
#define SHIRO 0
#define HAI 1
#define KURO 2

void keisan();

int A[MAX][MAX],n;

int main(){
  int i,j,u,v,k,c;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = INFTY;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      A[u][v] = c;
    }
  }
  keisan();


  return 0;
}


void keisan(){

  int d[MAX],color[MAX];
  int i,v,smav;


  for(i=0;i<n;i++){
    d[i] = INFTY;
    color[i] = SHIRO;
  }
  color[0] = HAI;  
  d[0] = 0;

  while(1){

    smav = INFTY;
    int u = -1;

    for(i =0;i<n;i++){
      if(smav > d[i] && color[i] != KURO){
	u =i;
	smav = d[i];
      }
    }
    if(u == -1)break;
    color[u] = KURO;

    for(v = 0;v<n;v++){
      if(color[v] != KURO && A[u][v] != INFTY){
	if(d[v] > d[u] + A[u][v]) {
	  d[v] = d[u] + A[u][v];
	  color[v] = HAI;
	}
      }
    }
  }

  for(i =0;i<n;i++){
    
    printf("%d ",i);
    if( d[i] == INFTY )d[i] = -1;
    printf("%d\n", d[i]);

  }
}

Measured memory_bytes: 636
#include<stdio.h>
int main(){
  int p[55556]={0},i,j,n;
  for(i=2;i<55556;i++)if(!p[i])for(j=i*2;j<55556;j+=i)p[j]=1;
  scanf("%d",&n);
  for(i=11,j=0;j<n;i+=10)if(!p[i]){printf("%d ",i);j++;}
}


Measured memory_bytes: 1912
#!/usr/bin/env python3
# 整数の入力
n = int(input())

#素因数分解
def PrimeFactorization(n):
    ret = []
    for i in range(2, int(n ** 0.5)+1):
        if n % i != 0:
            continue
        
        exp = 0
        while n % i == 0:
            exp += 1
            n //= i
        
        ret.append([i, exp])

    if n != 1:
        ret.append([n, 1])

    return ret

a = [0]*(n+1)
for i in range(2, n+1):
    tmp = PrimeFactorization(i)
    for j in range(len(tmp)):
        a[tmp[j][0]] += tmp[j][1]


ret = 1
#print(a)
for i in a:
    ret *= (i+1)
    ret %= 1000000007

print(ret)


Measured memory_bytes: 9444
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int x, y; cin >> x >> y;
  cout << x + y / 2 << endl;
}


Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
a,b = map(str,input().split())
a = int(a)
bint,bdec = b.split('.')
bint = int(bint)
bdec = int(bdec)
ans = a*bint+(a*bdec//100)
print(ans)


Measured memory_bytes: 9192
def resolve():
    N, D, A = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort()

    # imos
    imos = [0] * (N+1)
    ans = 0
    R = 0
    for l in range(N):
        if l:
            imos[l] += imos[l - 1]
        x = AB[l][0]
        h = AB[l][1]
        if imos[l] < h:
            R = max(R, l + 1)
            while R < N and AB[R][0] <= 2 * D + x:
                R += 1
            d = h - imos[l]
            cnt = -(-d//A) # 切り上げ
            imos[l] += cnt * A
            imos[R] -= cnt * A
            ans += cnt
    print(ans)

if __name__ == "__main__":
    resolve()

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

using namespace std;

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n, b, aa = 0;
  cin >> n;

  int a[8] = {};

  rep(i, 0, n) {
    cin >> b;
    b < 400 ? a[0] = true : b < 800 ? a[1] = true : b < 1200 ? a[2] = true : b < 1600 ? a[3] = true : b < 2000 ? a[4] = true : b < 2400 ? a[5] = true : b < 2800 ? a[6] = true : b < 3200 ? a[7] = true : aa++;
  }

  int ans = 0;
  rep(i, 0, 8) {
    if(a[i]) ans++;
  }

  cout << (ans == 0 ? 1 : ans) << ' ' << ans + aa << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a[3];
	int t=90000;
	for(int i=t;i;i--){
		for(int j=i;j;j--){
			if(i+j==2)cin>>n;
		}
	}
	while(n--){
		for(int i=0;i<3;i++)cin>>a[i];
		sort(a,a+3);
		cout<<(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]?"YES":"NO")<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long
struct Fast
{
  Fast()
  {
    std::cin.tie(0);
    std::cout.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int num;
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> l[i];
  }
  vector<int> d(n + 1);
  d[0] = 0;
  num = 0;
  for (int i = 0; i < n + 1; ++i)
  {
    if (i > 0)
      d[i] = d[i - 1] + l[i - 1];
    if (d[i] <= x)
    {
      ++num;
    }
  }
  cout << num << endl;
}


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

int main() {

	string x;
	int sum;
	while (cin >> x, x.compare("0")) {
		sum = 0;
		for (int i = 0; i < (int) x.size(); ++i) {
			sum += x.at(i) - '0';
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str,s;
  int cnt=0;
  cin >> s;
  for(int i=0,l=s.size();i<l;i++)
    if(s[i]>='A'&&s[i]<='Z')s[i]+=('a'-'A');
  while(cin >> str){
    if(str=="END_OF_TEXT")break;
    for(int i=0,l=str.size();i<l;i++)
      if(str[i]>='A'&&str[i]<='Z') str[i]+=('a'-'A');
    if(s==str) cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}

vector<P> segmi,segma;
ll n=1;

P mi(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return P(inf,-1);
    if(a<=l&&r<=b)return segmi[k];
    P c1=mi(a,b,k*2+1,l,(l+r)/2);
    P c2=mi(a,b,k*2+2,(l+r)/2,r);
    return min(c1,c2);
}
P ma(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return P(-1,-1);
    if(a<=l&&r<=b)return segma[k];
    P c1=ma(a,b,k*2+1,l,(l+r)/2);
    P c2=ma(a,b,k*2+2,(l+r)/2,r);
    return max(c1,c2);
}
int main(){
    int N,k;cin>>N>>k;
    while(n<N)n*=2;
    vi v(N),b(N);
    rep(i,N)cin>>v[i];
    rep(i,N-1){
        if(v[i]<v[i+1])b[i+1]=b[i]+1;
    }
  	ll ans=N-k+1;
  int t=0;
    rep(i,N){
        if(b[i]==k-1)t++;
    }
  ans-=max(0,t-1);
    segmi=vector<P>(n*2-1,P(inf,-1));
    segma=vector<P>(n*2-1,P(-1,-1));
    rep(i,n){
        if(i<N)segmi[i+n-1]=P(v[i],i);
        else segmi[i+n-1]=P(inf,i);
    }
    for(int i=n-2;i>=0;i--)segmi[i]=min(segmi[i*2+1],segmi[i*2+2]);
    rep(i,n){
        if(i<N)segma[i+n-1]=P(v[i],i);
        else segma[i+n-1]=P(-1,i);
    }
    for(int i=n-2;i>=0;i--)segma[i]=max(segma[i*2+1],segma[i*2+2]);
    REP(i,1,N-k+1){
        if(mi(i,i+k-1,0,0,n).first>v[i-1]&&ma(i,i+k-1,0,0,n).first<v[i+k-1])ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 19712
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, S := ReadInt(), ReadString()

	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		c := 0
		if S[i] == 'E' {
			c = 1
		}
		s[i+1] = s[i] + c
	}

	ans := N
	for i := 0; i < N; i++ {
		cnt := i - s[i] + s[N] - s[i+1]
		ans = Min(ans, cnt)
	}
	fmt.Println(ans)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

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

    int n;
    cin >> n;
    int ps[4], ts[4];
    for (int i = 0; i < 4; i++) cin >> ps[i];
    for (int i = 0; i < 4; i++) cin >> ts[i];

    int nin = 1e9;
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            for (int k = 0; k <= 100; k++) {
                for (int l = 0; l <= 100; l++) {
                    int cost = ps[0] * i + ps[1] * j + ps[2] * k + ps[3] * l;
                    int cnt = ts[0] * i + ts[1] * j + ts[2] * k + ts[3] * l;
                    if (cnt >= n) {
                        nin = min(nin, cost);
                    }
                }
            }
        }
    }

    cout << nin << endl;
}


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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    char op;
    cin >>a >> op >>b ;
    if(op == '+')
        cout << a + b <<endl;
    else
       cout << a - b <<endl;
}

Measured memory_bytes: 256
void main()
{
    long[] tmp = rdRow;
    long h = tmp[0], n = tmp[1];
    long[] a = new long[n], b = new long[n];
    foreach (i; 0 .. n)
    {
        tmp = rdRow;
        a[i] = tmp[0], b[i] = tmp[1];
    }

    long inf = 1L << 60;
    long[] dp = new long[](h+1);
    dp[] = inf;
    dp[0] = 0;
    foreach (i; 0 .. n)
    {
        long cnt = h / a[i];
        foreach (j; 0 .. cnt)
        {
            dp[j+1] = min(dp[j+1], b[i]*(j+1));
        }
        foreach (j; 0 .. h)
        {
            if (dp[j] != inf)
            {
                long k = j + a[i];
                if (k <= h)
                {
                    dp[k] = min(dp[k], dp[j]+b[i]);
                }
            }
            long rem = h - j;
            long num = (rem + a[i] - 1) / a[i];
            dp[h] = min(dp[h], b[i]*num+dp[j]);
        }
    }

    dp[h].writeln;
}

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 2556