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

using namespace std;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> dist(n, vector<int>(m, -1));
  vector<string> board(n);
  queue<pair<int, int>> q;
  for (int i = 0; i < n; ++i) {
    cin >> board[i];
    for (int j = 0; j < m; ++j) {
      if (board[i][j] == '#') {
        dist[i][j] = 0;
        q.emplace(i, j);
      }
    }
  }
  int ans = 0;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    ans = max(ans, dist[x][y]);
    q.pop();
    for (int d = 0; d < 4; ++d) {
      int xx = x + dx[d], yy = y + dy[d];
      if (xx >= 0 && xx < n && yy >= 0 && yy < m && dist[xx][yy] == -1) {
        dist[xx][yy] = dist[x][y] + 1;
        q.emplace(xx, yy);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 13456
import java.util.*;
import java.io.*;

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

        int[] a = new int[3];
        a[0] = s.nextInt();
        a[1] = s.nextInt();
        a[2] = s.nextInt();
        Arrays.sort(a);
        if (a[0] == 5 && a[1]== 5 && a[2] == 7) System.out.println("YES");
        else System.out.println("NO");
  }
}
  


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <cstring>

#define MAX_V 102
#define INF (int)1e9

using namespace std;


struct edge{int to,cap,rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v, int t,int f){
	if(v == t) return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); ++i)
	{
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		memset(used,0,sizeof(used));
		int f = dfs(s,t,INF);
		if(f == 0) return flow;
		flow += f;
	}
}
int main(){
	int V,E,c[3][E];
	cin >> V >> E;
	for (int i = 0; i < E; ++i)
	{
		int from,to,cap;
		cin >> from >> to >> cap;
		add_edge(from,to,cap);
	}
	int ans = max_flow(0,V-1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3164
N, M = map(int, input().split())

div = []
for m in range(1, int(M ** (0.5) + 1)):
    if M % m == 0:
        div.append(m)
        if m != M // m:
            div.append(M // m)
            
div.sort()
for i in range(len(div)):
    if div[-i-1] * N <= M:
        print(div[-i-1])
        break

Measured memory_bytes: 3060
S = [int(i) for i in input()]

N = len(S)

tens = [10**i for i in range(N)]

tens.reverse()

twos = [1]
twos.extend(2**i for i in range(N-1))

sums = 0
all_comb = sum(twos)
for i in range(N):
    tmp = [x*y for x, y in zip(tens[i:], twos)]
    exp = S[i] * sum(tmp) / sum(twos)
    sums = sums + exp
    del twos[-1]
print(int(sums * all_comb))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
    int h,w,n,i,j,count=1,color=1;
    scanf ("%d %d %d",&h,&w,&n);
    int a[n+1],c[h][w];
    //printf("h=%d,w=%d,n=%d\n",h,w,n);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        //printf("color=%dが%d\n",i,a[i]);
    };
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            c[i][i%2==0?j:w-j-1]=color;
            //printf("上から%d,左から%dが%d\n",i,i%2==0?j:w-j-1,color);
            //牛耕法
            count++;
            if(a[color]<count){
                count=1;
                color++;
            };
        };
    };
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            printf("%d ",c[i][j]);
        };
        printf("\n");
    };
    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> to(n);
	vector<vector<int>> cost(n);
	vector<int> ans(n, -1);
	queue<int>q;

	for (int i = 1; i < n; i++) {
		int a, b, we;
		cin >> a >> b >> we;
		a--;
		b--;
		to[a].emplace_back(b);
		to[b].emplace_back(a);
		cost[a].emplace_back(we);
		cost[b].emplace_back(we);
	}

	q.push(0);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int i=0; i < to[v].size(); i++) {
			int u = to[v][i];
			int w = cost[v][i];
			if (ans[u] != -1)continue;
			ans[u] = (ans[v] + w) % 2;
			q.push(u);
		}
	}

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

Measured memory_bytes: 11904
from collections import Counter

n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
c = Counter(a)
cc = c.most_common()
cv = []
ans = 0

for i in range(0,len(list(c.keys()))):
    cv.append(cc[i][1])

while len(cv) > k:
    ans += cv.pop()

print(ans)


Measured memory_bytes: 40976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const ll INF = 1LL<<60;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n);
    sum[0] = a[0];
    rep(i,n-1){
        sum[i+1] = sum[i] + a[i+1];
    }
    ll ans = INF;
    for(int i = 0; i < n-1; i++){
        ll x = sum[i];
        ll y = sum[n-1] - sum[i];
        ans = min(ans, abs(x-y));
    }
    cout << ans << endl;    
    return 0;
}

Measured memory_bytes: 6324
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


K,N = nm()
A  = nl()

maxL = 0
for i in range(N-1):
    if A[i+1]-A[i] > maxL: 
        maxL = A[i+1]-A[i]

if A[0]+K - A[N-1] > maxL:
    maxL = A[0]+K - A[N-1]

print(K - maxL )



Measured memory_bytes: 25944
#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
*/
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
/**/ 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
const long long inf = 1e18;
 
using namespace std;

int t=0;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    vi vv(n);
    rep(i,n)
    {
        cin>>vv[i];
    }
    if(n==1)
    {
        cout<<1<<endl;
        return;
    }
    sort(all(vv));
    vi v;
    vi vvv(n,1);
    repu(i,0,n-2)
    {
        if(vv[i]==vv[i+1])
        {
            vvv[i]=0;
            vvv[i+1]=0;
        }
    }
    vi v1;
    repu(i,0,n-1)
    {
        {
            v.pb(vv[i]);
        }
    }
    vi vis(1000001,0);
    n=v.size();
    int ans=0;
    repu(i,0,n-1)
    {
        if(vis[v[i]]==1)
        {
            continue;
        }
        else
        {
            if(vvv[i])
                ans++;
            for(int j=v[i];j<=1000000;j+=v[i])
            {
                vis[j]=1;
            }
        }
    }
    cout<<ans<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("hh.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 9540
import Control.Monad
import Data.List (sortBy) 

solve::Int->[Int]->Int
solve k hn = minimum $ zipWith (-) (drop (k-1) sortTree) sortTree
              where sortTree = sortBy compare hn

main = do
  [n, k] <- map read . words <$> getLine
  hn <- replicateM n $ read <$> getLine::IO[Int]
  print $ solve k hn

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  vector<int> ans(N + 1);
  for (i64 x = 1; x <= N; ++x) {
    i64 x2 = x * x;
    for (i64 y = 1; y <= N; ++y) {
      i64 y2 = y * y;
      i64 xy = x * y;
      for (i64 z = 1;; ++z) {
        i64 a = x2 + y2 + z * z + xy + y * z + x * z;
        if (a > N) break;
        ans[a]++;
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    cout << ans[i] << '\n';
  }
}

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

using namespace std;

const int N = 1e5 + 5;

int a[N];

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

    for(int i = 0 ; i < n ; i ++){
        scanf("%d" , &a[i]);
    }

    for(int i = n-1 ; i >= 1 ; i --){
        if(a[i] < a[i-1]){
            if(a[i-1] - a[i] > 1){
                printf("No\n");
                return 0;
            }
            a[i-1] --;
        }
    }

    printf("Yes\n");
}


Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::vector<long long> a, std::vector<long long> b,
           std::vector<long long> c) {
  vector<array<ll, 3>> max_happiness(N, {{0, 0, 0}});
  max_happiness[0][0] = a[0];
  max_happiness[0][1] = b[0];
  max_happiness[0][2] = c[0];
  for (int i = 1; i < N; ++i) {
    max_happiness[i][0] =
        max(max_happiness[i - 1][1], max_happiness[i - 1][2]) + a[i];
    max_happiness[i][1] =
        max(max_happiness[i - 1][2], max_happiness[i - 1][0]) + b[i];
    max_happiness[i][2] =
        max(max_happiness[i - 1][0], max_happiness[i - 1][1]) + c[i];
  }
  std::cout << max(max_happiness[N - 1][0],
                   max(max_happiness[N - 1][1], max_happiness[N - 1][2]))
            << std::endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  std::vector<long long> b(N);
  std::vector<long long> c(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, std::move(a), std::move(b), std::move(c));
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
using namespace std;
int main(void){
    int n,m,x;
    cin>>n>>m>>x;
    int c[12],a[12][12];
    for(int i(0);i<n;i++){
        cin>>c[i];
        for(int j(0);j<m;j++){
            cin>>a[i][j];
        }
    }
    int min(INT_MAX);
    for(int i(0);i<pow(2,n);i++){
        bool digit[12]={0};
        int num = i;
        int tc(0),ta[12]={0};
        for(int j(0);j<n;j++){
            if(num%2 != 0)digit[j] = true;
            num /= 2;
        }
        for(int j(0);j<n;j++){
            if(digit[j]){
                tc += c[j];
                for(int k(0);k<m;k++)ta[k] += a[j][k];
            }
        }
        bool ok(true);
        for(int j(0);j<m;j++){
            if(ta[j] < x)ok = false;
        }
        if(ok && min > tc)min = tc;
    }
    if(min == INT_MAX)cout<<"-1"<<endl;
    else cout<<min<<endl;
    return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;

typedef long long ll;

const int MOD = 1000000007;
const int MAX_N = 1e5 + 1;

struct Edge {
  Edge(int _to, int _cost)
    : to(_to), cost(_cost){}
  int to;
  int cost;
};


int N, M;

vector< Edge > e[MAX_N];
vector< int > path;
int d[MAX_N];
bool state[MAX_N];


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

  cin >> N >> M;

  vector< int > l(M);
  vector< int > r(M);
  vector< int > D(M);
  REP(i, M) {
    cin >> l[i] >> r[i] >> D[i];
    l[i]--; r[i]--;
    e[l[i]].emplace_back(Edge(r[i], D[i]));
  }

  
  vector< int > indeg(N, 0);
  stack< int > S;

  EACH(i, e) {
    EACH(si, i) {
      indeg[si.to]++;
    }
  }

  
  REP(i, N) {
    if (indeg[i] == 0)
      S.push(i);
  }

  
  while(!S.empty()) {
    int from = S.top(); S.pop();
    path.emplace_back(from);
    EACH(to_e, e[from]) {
      indeg[to_e.to]--;
      if (indeg[to_e.to] == 0)
    	S.push(to_e.to);
    }
  }
  
  
  bool ok = (path.size() == N);

  
  if (!ok) {
    OK(ok);
    return 0;
  }


  REP(i, N) {
    if (state[path[i]]) continue;

    int start = path[i];

    stack< int > s;
    
    d[start] = 0;
    state[start] = true;

    s.push(start);
    
    while(!s.empty()) {
      int from = s.top(); s.pop();
      
      EACH(to_e, e[from]) {
	/*
	debug(from);
	debug(d[from]);
	debug(to_e.to);
	debug(to_e.cost);
	debug(d[to_e.to]);
	OK(state[to_e.to]);
	*/
	if (!state[to_e.to]) {
	  d[to_e.to] = d[from] + to_e.cost;
	  state[to_e.to] = true;
	  s.push(to_e.to);
	} else {
	  if (d[to_e.to] != d[from] + to_e.cost) {
	    ok = false;
	  }
	}
	
      }
      if (!ok) break;
    }
  }

  OK(ok);
  

  return 0;
}



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

using namespace std;

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

    int n;
    long long k;
    cin >> n >> k;
    k *= n;
    
    deque<int> as(n);
    vector<vector<int>> idxs(202020);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        as[i] = a;
        idxs[a].push_back(i);
        idxs[a].push_back(i + n);
    }
    for (int i = 0; i < 202020; i++) {
        sort(idxs[i].begin(), idxs[i].end());
    }
    vector<int> nxt(n);
    for (int i = 0; i < n; i++) {
        int a = as[i];
        auto it = upper_bound(idxs[a].begin(), idxs[a].end(), i);
        nxt[i] = *it;
    }
    
    int idx = 0;
    long long period = 0;
    long long now = 0;
    vector<long long> time(n, -1);
    while (1) {
        if (time[idx] != -1 && period == 0) {
            period = now - time[idx];
        }
        time[idx] = now;
        if (period != 0 && k > period) {
            k %= period;
        }

        int step = nxt[idx] - idx + 1;
        if (k >= step) {
            k -= step;
            idx = (nxt[idx] + 1) % n;
            now += step;
        } else {
            vector<int> ans;
            set<int> es;
            for (int i = 0; i < k; i++) {
                int a = as[(idx + i) % n];
                if (es.count(a)) {
                    while (ans.back() != a) {
                        es.erase(ans.back());
                        ans.pop_back();
                    }
                    es.erase(a);
                    ans.pop_back();
                } else {
                    es.insert(a);
                    ans.push_back(a);
                }
            }
            for (int a : ans) {
                cout << a << ' ';
            }
            return 0;
        }
    }
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (P[i] == i) {
      if (i == N - 1) {
        swap(P[i - 1], P[i]);
      } else {
        swap(P[i], P[i + 1]);
      }
      count++;
    }
  }
  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<math.h>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); 
//    cin.tie(NULL); 
    cout.tie(NULL);
  	lli n,a,b,ans=0;
  	cin>>n>>a>>b;
  	if(n<a)
  		cout<<n;
	else if(n<=(a+b))
		cout<<a;
	else 
	{
		lli ans=0;
		ans=ans+(n/(a+b))*a;
//		cout<<ans<<endl;
		if(n%(a+b)<a)
  			ans=ans+(n%(a+b));
		else if(n%(a+b)<=(a+b))
			ans+=a;
		cout<<ans;
	}
	return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back
#define ii pair<int,int>
#define fre freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//fre
	string s;
	int k;
	cin>>k>>s;
	k%=26;
	//cout<<k;
	for(int i=0;i<s.length();i++){
		cout<<(char)((s[i]+k-65)%26+65);
	}
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(){
	int a, b;
	double fa, fb;

	scanf("%d %d", &a, &b);
	fa = (double)a;
	fb = (double)b;
	
	printf("%d %d %lf\n", a/b, a%b, fa/fb);

	return 0;

}


Measured memory_bytes: 2100
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){
  long A[100000],amin,sum;
  int k,i,j,x,y,z,K,N;
  amin=1000000000;
  if(scanf("%d",&N)>1){
    exit(1);
  }
  
  for(i=0;i<N;i++){
  if(scanf("%ld",&A[i])>1){
    exit(1);
  }
  }
  sum = 0;
  k=0;
  for(i=0;i<N;i++){
   if(A[i]<0){
     k=k+1;
   A[i]=labs(A[i]);
   }
   if(amin>A[i]){
   amin = A[i];
   }
   sum = sum + A[i];
  }
  if(k%2!=0){
   sum = sum - 2 * amin;
  }
  printf("%ld",sum);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    string str;
    cin >> str;
    int w[n],e[n];
    w[0] = 0;
    e[0] = 0;
    int ans = n;
    for(int i = 0;i < n;i++){
        if(str[i] == 'W'){
            if(i == 0){
                w[0] = 1;
                e[0] = 0;
            }else{
                w[i] = w[i - 1] + 1;
                e[i] = e[i - 1];
            }
        }else{
            if(i == 0){
                w[0] = 0;
                e[0] = 1;
            }else{
                w[i] = w[i - 1];
                e[i] = e[i - 1] + 1;
            }
        }
    }
    for(int i = 0;i < n;i++){
        int t = 0;
        if(i == 0){
            t = e[n - 1] - e[0] ;
        }else{
            t = w[i - 1] + e[n - 1] - e[i];
        }
        ans = min(ans,t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
typedef long long ll;
const int N=20000005;
int n,k,x,t,a,b;
string s;
vector<int>v;
int main(){

	cin >> n;
	while(n){
		if(n%10 == 7){
			cout << "Yes";
			return 0;
		}
		n/=10;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3612
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn = inputs[0][0]

# body
if $debugFlag
  p nn
end

arr = []

arr << nn
cnt = 2
while true
  if arr[-1] % 2 == 0
    x = arr[-1]/2
  else
    x = 3*arr[-1] + 1
  end
  flag = false
  arr.each do |a_i|
    if x == a_i
      flag = true
      break
    end
  end
  if flag == true
    puts cnt
    exit
  end
  arr << x
  cnt += 1
end


Measured memory_bytes: 1788
W, H, x, y, r = map(int, input().split(" "))


check_h1 = (x - r) >= 0
check_h2 = (x + r) <= W
check_v1 = (y - r) >= 0
check_v2 = (y + r) <= H

check_h = check_h1 & check_h2
check_v = check_v1 & check_v2

check_all = check_h & check_v

if check_all:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
main :: IO ()
main = do
  w <- getLine :: IO String
  putStr $ test w

test :: String -> String
test [] = "Yes"
test [_] = "No"
test (x:xs) 
  | length fil `mod` 2 == 1 = "No"
  | otherwise = test filnot
    where fil = filter (==x) (x:xs)
          filnot = filter (/=x) xs


Measured memory_bytes: 508
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	long long aa[n];
	long long bb[n];
	long long ans = 0;

	for(int i = 0; i < n; i++){
		cin >> aa[i] >> bb[i];
	}

	for(int i = n-1; i >= 0; i--){
		long long a = aa[i] + ans;
		long long b = bb[i];
		long long tmp = b*(a/b + 1) - a;
		if((a % b) == 0){
			tmp = 0;
		}

		//cout << tmp << endl;
		ans += tmp;
	}



	cout << ans << endl;

	return 0;
}

/*




*/

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct UF {
    vector<int> data;

    UF(int n) {
        data.resize(n, -1);
    }
    
    int root(int i) {
        return data[i] < 0 ? i : data[i] = root(data[i]);
    }

    int sz(int i) {
        return -data[root(i)];
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);

        if (x == y) return;
        if (sz(x) < sz(y)) swap(x, y);

        data[x] += data[y];
        data[y] = x;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int n, k;
bool c[100010];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> n >> k, n) {
        fill_n(c, 100010, false);
        bool f = false;

        for (int i = 0; i < k; ++i) {
            int a; cin >> a; --a;
            if (a == -1) f = true;
            c[a] = true;
        }

        int ans = 0;
        int cur = 0;

        for (int i = 0; i < n; ++i) {
            if (c[i]) cur++;
            else cur = 0;

            ans = max(ans, cur);
        }

        if (f) {
            if (ans < n) ans++;

            UF uf(n+1);

            for (int i = 0; i < n - 1; ++i) {
                if (c[i] && c[i + 1]) uf.unite(i, i + 1);
            }

            for (int i = 1; i < n; ++i) {
                if (c[i]) continue;
                int l = 0, r = 0;

                if (c[i - 1]) l = uf.sz(i - 1);
                if (c[i + 1]) r = uf.sz(i + 1);

                ans = max(ans, l + r + 1);
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
                
set<int> s;
int n;
void calc(int x, int y) {
	if(x == 0) {
		return;
	}
	for(int i = 3; i <= 7; i += 2) {
		int t = y * 10 + i;
		int l = t;
		set<int> m;
		while(l > 0) {
			m.insert(l % 10);
			l /= 10;
		}
		if(t <= n && m.size() == 3) {
			s.insert(t);
		}
		calc(x - 1, t);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	cin >> n;
	calc(9, 0);
	cout << s.size() << endl;
	return 0;	
}


Measured memory_bytes: 1536
minlist=[]
maxlist=[]
 
n,m=map(int,input().split())
for i in range(m):
  l,r=list(map(int,input().split()))
  minlist.append(l)
  if r>0:
    maxlist.append(r)
ans=0
dif=min(maxlist)-max(minlist)
if(dif>=0):
  ans=dif+1
else:
  ans=0
print(ans)

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

typedef long long ll;
const ll M = 1e9+7;
vector<list<ll> > tree(100001);
ll bd2[100001], bd1[100001];

void dp(int v) {
	bd1[v] = 1;
	bd2[v] = 1;
	for (auto it: tree[v]) {
		tree[it].remove(v);
		dp(it);
		bd1[v] *= bd2[it];
		bd1[v] %= M;
		bd2[v] *= (bd1[it]+bd2[it])%M;
		bd2[v] %= M;
	}
}

int main() {
	int n, x, y;
	cin >> n;
	for (int i=1; i<n; i++) {
		cin >> x >> y;
		tree[x].push_back(y);
		tree[y].push_back(x); 	
	}
	dp(1);
	cout << (bd1[1]+bd2[1])%M << "\n";
}

Measured memory_bytes: 17920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	public static final int SIZE = 2000005;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			PQ Q = new PQ(SIZE);

			String input_str = "";
			String tmp_str[] = new String[2];

			StringBuilder ans = new StringBuilder();

			while(!(input_str = br.readLine()).equals("end")){

				tmp_str = input_str.split("\\s+");

				//空の場合と満杯の場合の出力は設問で未定義なのでチェックしない
				if(tmp_str[0].equals("insert")){

					Q.push(Integer.parseInt(tmp_str[1]));

				}else{

					ans.append(Integer.toString(Q.pop())).append("\n");
				}
			}

			System.out.print(ans.toString());

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
    }
}

class PQ{

	public int table[];
	public int num_nodes;
	public final int root = 0;
	public final int NONE = -1;

	PQ(int arg_size){

		table = new int[arg_size];

		for(int i = 0; i < table.length; i++){

			table[i] = NONE;
		}

		num_nodes = 0;
	}

	public void push(int value){

		table[num_nodes] = value;
		int loc = num_nodes++;
		int parent = -1,tmp = 0;

		//親が今回挿入するデータより小さい場合、親と子を入れ替える
		while(loc != root){
			parent = (loc-1)/2;
			if(table[parent] >= table[loc]){

				break;
			}else{

				tmp = table[parent];
				table[parent] = table[loc];
				table[loc] = tmp;
				loc = parent;
			}
		}
	}

	public boolean isEmpty(){

		return num_nodes == 0;
	}

	public boolean isFull(){

		return num_nodes == table.length;
	}

	public int pop(){

		int ret = table[root];

		//とりあえず末尾のデータをtopに持ってくる
		num_nodes--;
		table[root] = table[num_nodes];
		table[num_nodes] = NONE;

		int loc = root;
		int left = 0,right = 0;
		int tmp = 0;

		//親子の大小関係が正しくなるようにする
		while(true){

			left = 2*loc+1;
			if(left >= table.length)break; //一番下の層

			right = 2*loc+2;

			if(table[loc] >= table[left] && table[loc] >= table[right]){ //親 >= 左右の子

				break;
			}else{ //少なくとも一方の子が親よりも大きい→左と右で大きい方の子と交換する

				if(table[left] >= table[right]){

					tmp = table[loc];
					table[loc] = table[left];
					table[left] = tmp;
					loc = left;

				}else{// table[left] < table[right]

					tmp = table[loc];
					table[loc] = table[right];
					table[right] = tmp;
					loc = right;
				}
			}
		}

		return ret;
	}
}

class UTIL{

    //String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 554372
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] ham = new int[1000001];
		for ( int i = 1; i < 1000001; i++ ) {
			int tmp = i;
			while(tmp%5==0)tmp/=5;
			while(tmp%3==0)tmp/=3;
			while(tmp%2==0)tmp/=2;
			ham[i]=tmp;
		}
		while ( !sc.hasNext("0") ) {
			int m = sc.nextInt() , n = sc.nextInt() , count=0;
			for ( ; m <= n; m++ )
				if( ham[m] == 1) count++;
			System.out.println(count);
		}
	}
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N, X, Y;
	cin >>N >>X >>Y;
	vector<vector<int>> S(N+1, vector<int> (N+1, INF));
	for (int i=1; i<=N; i++) // Self
		S.at(i).at(i)=0;
	for (int i=1; i<=N; i++) // Initial
		for (int j=1; j<=N; j++)
			S.at(i).at(j)=S.at(j).at(i)=abs(i-j);
	S.at(X).at(Y)=S.at(Y).at(X)=1; // New
	for (int i=1; i<=N; i++)
		for (int j=1; j<=N; j++) {
			S.at(i).at(j) =min(S.at(i).at(j), S.at(i).at(X)+S.at(Y).at(j)+1);
			S.at(i).at(j) =min(S.at(i).at(j), S.at(i).at(Y)+S.at(X).at(j)+1);
		}
	vector<int> ss(N, 0);
	for (int i=1; i<=N; i++)
		for (int j=1; j<=N; j++)
			ss.at(S.at(i).at(j))++;
	for (int i=1; i<N; i++)
		cout <<ss.at(i)/2 <<endl;
	return 0;
}



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

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

    ll r, d, x;
    cin >> r >> d >> x;
    for(int i=1;i<=10;i++)
    {
        x = r*x-d;
        cout << x << '\n';
    }
}   

Measured memory_bytes: 256
#include <unistd.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define istream ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define uint unsigned int
#define mod 1000000007
#define vec vector<int>
#define twod vector<vector<int>>
#define mp make_pair
#define pbc push_back
#define all(a) a.begin(),a.end()
#define debug1(x)                cout<<#x<<"="<<x<<endl;
#define debug2(x,y)              cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define debug3(x,y,z)            cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define debug4(x,y,z,w)          cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<" "<<#w <<"="<<w<<endl;
#define debugarray(arr,j,n)      for(int i=j;i<n;i++) {cout<<"i="<<i<<" arr[i]="<<arr[i]<<"\n";};

int32_t main()
{
     int n,k;
     cin>>n>>k;
     vec arr;
     for(int i=0;i<n;i++){
          int temp;
          cin>>temp;
          arr.push_back(temp);
     }
     vec dp(n,INT_MAX);
     dp[0]=0;
     for(int i=0;i<n-1;i++){
          for(int j=1;j<=k;j++){
               if(i+j <n)
                    dp[i+j] = min(dp[i+j],dp[i] + abs(arr[i+j] - arr[i]));
          }
     }
     cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4988
#include<cstdio>
const int maxn=510;
int h,v;
int a[maxn][maxn];
int nm;
struct Move {
	int a,b,c,d;
}mv[maxn*maxn];
int main() {
	scanf("%d%d",&h,&v);
	for(register int i=1;i<=h;++i)for(register int j=1;j<=v;++j)scanf("%d",&a[i][j]);
	for(register int i=1;i<=h;++i) {
		if(i&1) {
			for(register int j=1;j<v;++j)if(a[i][j]&1) --a[i][j],++a[i][j+1],mv[++nm]=(Move){i,j,i,j+1};
			if(i<h&&(a[i][v]&1)) --a[i][v],++a[i+1][v],mv[++nm]=(Move){i,v,i+1,v};
		}
		else {
			for(register int j=v;j>1;--j)if(a[i][j]&1) --a[i][j],++a[i][j-1],mv[++nm]=(Move){i,j,i,j-1};
			if(i<h&&(a[i][1]&1)) --a[i][1],++a[i+1][1],mv[++nm]=(Move){i,1,i+1,1};
		}
	}
	printf("%d\n",nm);
	for(register int i=1;i<=nm;++i)printf("%d %d %d %d\n",mv[i].a,mv[i].b,mv[i].c,mv[i].d);
	return 0;
}

Measured memory_bytes: 7040
N=int(input())
if N<=1000:
    print(1000-N)
if 2000>=N>1000:
    print(2000-N)
if 3000>=N>2000:
    print(3000-N)
if 4000>=N>3000:
    print(4000-N)
if 5000>=N>4000:
    print(5000-N)
if 6000>=N>5000:
    print(6000-N)
if 7000>=N>6000:
    print(7000-N)
if 8000>=N>7000:
    print(8000-N)
if 9000>=N>8000:
    print(9000-N)
if 10000>=N>=9000:
    print(10000-N)

Measured memory_bytes: 9040
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>

int loot[10];
int can[10][10];
int counter;

int n;

int memo[10][10];

int dp(int now, int old){
	int ans = 0;
	loot[now] = 1;
	if (counter == 0){
		loot[now] = 0;
		return memo[now][old] = 1; }
	for (int a = 0; a <= n; a++){
		if (can[now][a] != 0 && loot[a] == 0){
			counter--;
			ans += dp(a, now);
			counter++;
		}
	}
	loot[now] = 0;
	return memo[now][old] = ans;
}

int main(){
	memset(memo, 255, sizeof(memo));
	int m;
	int buf, buffer;

	scanf("%d%d", &n, &m);
	counter = n - 1;
	for (int a = 0; a < m; ++a){
		scanf("%d%d", &buf, &buffer);
		can[buf][buffer]++;
		can[buffer][buf]++;
	}

	printf("%d\n", dp(1, 1));

	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        string answer = "";

        while (true)
        {
            long mod = n % 26;
            char c = mod == 0 ? 'z' : (char)('a' + mod - 1);
            answer = c.ToString() + answer;
            n -= mod == 0 ? 26 : mod;
            n /= 26;
            if (n == 0)
            {
                break;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27500
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		long ans = 0;
		while(x <= y) {
			x *= 2;
			ans++;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c;
    cin >> a >> b >> c;

    if (a > b) {
        swap(a, b);
    }
    if (a > c) {
        swap(a, c);
    }
    if (b > c) {
        swap(b, c);
    }

    cout << a * b / 2 << '\n';

    return 0;
}

Measured memory_bytes: 256
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
int n, dp[2005];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    dp[0] = 1;
    for (int i = 3; i <= n; ++i)
    {
        for (int j = 3; j <= i; ++j)
        {
            (dp[i] += dp[i - j]) %= 1000000007;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N, X;
    cin >> N >> X;

    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int d = 0;
    int ans = 1;
    for (int i = 0; i < N; i++) {
        d += L[i];
        if (d <= X) {
            ans++;
        }
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[300000];
int b[300000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d",&a[i+1]);
	}
	vector<int>ans;
	for(int i=n;i>=1;i--){
		int cnt=0;
		for(int j=i*2;j<=n;j+=i){
			cnt+=b[j];
		}
		cnt%=2;
		b[i]=cnt^a[i];
		if(b[i]){
			ans.push_back(i);
		}
	}
	cout<<ans.size()<<endl;
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<endl;
}

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

int main() {
  long long n,c,k;
  cin>>n>>c>>k;
  vector<long long> t(n);
  for(long long &x: t) cin>>x;
  sort(t.begin(),t.end());
  long long count=0,memo=0;
  bool flag=false;
  for(long long i=0;i<n;){
    if(flag==false){
    if(i==n-1) {count++; break;}
    }
    long long m;
    m=min(n-1,i+c-1);
    if(flag){
      if(t[i]-t[memo]>k) {count++; flag=false; continue;}
      if(i==n-1) {count++; break;}
      if(t[i]-t[memo]<=k&&t[i+1]-t[memo]>k) {count++; flag=false;}
      i++;
      continue;
    }   
    if(t[m]-t[i]<=k) {count++; i+=m-i+1;}
    else  {flag=true; memo=i; i++;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

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

    REP(i, a+b+1){
        if(i != a){
            if(s[i] < '0' || '9' < s[i]){
                nOUT;
                return 0;
            }
        }
        if(s[a] != '-'){
            nOUT;
            return 0;
        }
    }

    yOUT;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
int main()
{
  int n;
  cin >> n;
  vi v(n), c(n);
  re(i, n) cin >> v[i];
  re(i, n) cin >> c[i];

  int cost = 0;
  re(i, n) {
    if (v[i] > c[i]) cost += v[i] - c[i];
  }

  cout << cost << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int x = 1, y = 1, z,i = 0;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	scanf("%d%d", &x, &y);
	while (x != 0 || y != 0) {
		
		if (x < y) {
			printf("%d %d\n",x,y);
		}
		else {
			printf("%d %d\n", y, x);
		}
		scanf("%d%d", &x, &y);
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}


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

int min(int a, int b){
    return (a < b) ? a : b;
}

int asc(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A < *B) return 1;
  if (*A > *B) return -1;
  return 0;
}

int main(void){
    int x, y, z, k;
    scanf("%d%d%d%d", &x, &y, &z, &k);
    long int a[x];
    long int b[y];
    long int c[z];
    for(int i = 0; i < x; i++){
        scanf("%ld", &a[i]);    
    }
    for(int i = 0; i < y; i++){
        scanf("%ld", &b[i]);    
    }
    for(int i = 0; i < z; i++){
        scanf("%ld", &c[i]);    
    }
    qsort((void *)a, x, sizeof(a[0]), asc);
    qsort((void *)b, y, sizeof(b[0]), asc);
    qsort((void *)c, z, sizeof(c[0]), asc);
    
    long int ab[x][y];
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            ab[i][j] = a[i] + b[j];
        }       
    }

    qsort((void *)ab, x * y, sizeof(ab[0][0]), asc);

    int n = min(3000, x * y);
    long int abc[n][z];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < z; j++){
            abc[i][j] = ab[i/x][i%x] + c[j];
        }      
    }
    qsort((void *)abc, n * z, sizeof(abc[0][0]), asc);
    n = min(k, x * y * z);
    for(int i = 0; i < n; i++){
        printf("%ld\n", *(&abc[0][0]+i));
    }
    return 0; 
}

Measured memory_bytes: 54916
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
int digitSum(int a){
    int sum = 0;
    for(;a;a /= 10)sum += a % 10;
    return sum;
}
main(){
    int N,A,B;
    cin >> N >> A >> B;
    int ans = 0;
    for(int i = 1;i <= N;i++){
        int n = digitSum(i);
        if(n >= A && n <= B)ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<String> stlist = new ArrayList<String>(N);
        int[] time = new int[N];
        for(int i=0;i<N;i++){
            String str = sc.next();
            int ms = sc.nextInt();
            stlist.add(str);
            time[i]=ms;
        }
        String target = sc.next();
        int ind = stlist.indexOf(target);
        long ans = 0;
        for(int i=ind+1;i<N;i++){
            ans+=time[i];
        }   
        System.out.println(ans);
    }
}

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

const ll INF = 1LL << 60;

const int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N, M, K;
int main() {
    cin >> N >> M >> K;
    combination comb(N * M + 10);

    mint ans = 0;

    // 2点を固定する
    // x 方向
    for (int i = 0; i <= M - 1; i++) {
        ans += i * (M - i) * N * N; 
    }

    // y 方向
    for (int i = 0; i <= N - 1; i++) {
        ans += i * (N - i) * M * M;
    }

    // 2点以外の残りを選ぶ
    ans *= comb(N * M - 2, K - 2);
    cout << ans << endl;
}

Measured memory_bytes: 6352