akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
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 long long INF = 1LL << 60;

// 入力
int N;
long long W, weight[110], value[110];

// DP テーブル
long long dp[110][100010];

int main() {
  
  cin >> N >> W;
  for (int i = 0; i < N; ++i)  cin >> weight[i] >> value[i];
  
  //初期値
  FOR(i,0,110) {
    FOR(j,0,100010) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;  //初期状態では価値0しか実現できない

  // ループ
  for (int i = 0; i < N; ++i) {
    for (int sum_v = 0; sum_v <= 100010; ++sum_v) {
      if (sum_v - value[i] >= 0) { //i番目を追加する場合を考える
        chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]); //valueに着目、weightを最小化
      }
      chmin(dp[i+1][sum_v], dp[i][sum_v]); //i番目を追加しない場合を考える
    }
  }
  
  // 答え
  long long ans = 0;
  FOR(i,0,100010) {
    if (dp[N][i] <= W) ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 89548
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void solve() {
		int k=s.nextInt();
		int val = s.nextInt();
		k *= 500;
		if(k>=val) {
			out.println("Yes");
		}else {
			out.println("No");
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}


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

using namespace std;

int main (void) {
    int n;
    cin >> n;
    vector<int> a(n);
    int a_max = 0;
    for ( int i = 0; i < n; i++ ) {
        cin >> a.at(i);
        a_max = max(a_max, a.at(i));
    }

    int ans = 0;
    int diff;
    int diff_min = INT_MAX;
    for ( int i = 0; i < n; i++ ) {
        if ( a.at(i) == a_max )
            continue;
        diff = abs(a_max / 2 - a.at(i));
        if ( diff < diff_min ) {
            diff_min = diff;
            ans = a.at(i);
        }
    }

    cout << a_max << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int max10(int a[10])
{
    int max = a[0], i;

    for(i = 1; i < 10; i++)
        if(max < a[i])
            max = a[i];

    return max;
}

int main(void)
{

    int a[10], i, b[3], j;

    for(i = 0; i < 10; i++)
        scanf("%d", &a[i]);

    j = 0;
    while(j != 3){
       b[j] = max10(a);
       for(i = 0; i < 10; i++) {
           if(a[i] == b[j]) {
               a[i] = 0;
               break;
           }
       }
       j++;
    }
    for(i = 0; i < 3; i++)
        printf("%d\n", b[i]);

    return 0;
}

Measured memory_bytes: 600
// Last Change: 03/22/2019 19:19:23.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  if (A > X) {
    cout << "NO" << endl;
  } else {
    if (X <= A + B) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, p[15], ans;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) cin >> p[i];
    sort(p, p + n);
    for (int i = 0; i < n - 1; i++) ans += p[i];
    ans += p[n - 1] / 2;
    cout << ans << endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 == 0 || i%5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
/**
 *   
 *   Date: 30 March 2020
 *   Time: 12:30:34
**/
#pragma GCC optimize("O3")
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1000000007;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,k,n1,d,d1;
	cin>>n>>k;
	ll ar[n+2],dp[n+2];
	for(ll i=1;i<=n;i++)
	{
		cin>>ar[i];
	}
	dp[1]=0;
	for(ll i=2;i<=n;i++)
	{
		n1=i-k;
		n1=max(n1,1ll);
		dp[i]=INT_MAX;
		for(ll j=n1;j<i;j++)
		{
			d=abs(ar[i]-ar[j]);
			dp[i]=min(dp[i],dp[j]+d);
		}
	}
	cout<<dp[n]<<endl;

return 0;
}

Measured memory_bytes: 1792
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy
ans  = 'U'*y + 'R'*x
ans += 'D'*y + 'L'*x
ans += 'L' + 'U'*(y+1) + 'R'*(x+1) + 'D'
ans += 'R' + 'D'*(y+1) + 'L'*(x+1) + 'U'
print(ans)

Measured memory_bytes: 3060
from sys import stdin
mod=10**9+7
def expo(n):
    if n<=0:
        return 1
    if n%2==0:
        return expo(n//2)*expo(n//2)%mod
    else:
        return 2*expo(n//2)*expo(n//2)%mod

n=int(input())
differences=list(map(int,stdin.readline().split()))
repetition=0
nbDiff=[0]*n
places=[0]*n
possible=True
moitie=n//2
for i in range(n):
    difference=differences[i]
    moitieDiff=difference//2
    if nbDiff[difference]==1:
        repetition+=1
    nbDiff[difference]+=1    
    
    if n%2==1:
        places[moitie+moitieDiff]+=1
        places[moitie-moitieDiff]+=1
    else:
        places[moitie+moitieDiff]+=1
        places[moitie-moitieDiff-1]+=1

for i in range(n):
    if places[i]!=2:
        possible=False

if possible:
    print(expo(repetition))
else:
    print(0)

Measured memory_bytes: 13876
#include<stdio.h>

int main(void) {
    char str[21];
    fgets(str, 21, stdin);

    int i, len;
    for(i = 0; i < 21; i++) {
        if(str[i] == '\0') {
            len = i;
            break;
        }
    }

    for(i = 0; i < len; i++) {
        printf("%c", str[len - 1 - i]);
    }
    printf("\n");                                                                                                  

    return 0;
}

Measured memory_bytes: 524
#include<iostream>
using namespace std;
#define MAX 100010
#define KAZU -1

struct Node{int parent, left, right;};

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].parent == KAZU) cout << "root, ";
  else if(T[u].left == KAZU) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i=0,c = T[u].left;c != KAZU;i++,c=T[c].right){
    if(i) cout << ", ";
    cout << c;
  }
    cout << "]" << endl;
}

int getdepth(int u,int p){
  D[u] = p;
  if(T[u].right != KAZU) getdepth(T[u].right,p);
  if(T[u].left != KAZU) getdepth(T[u].left,p+1);
}

int main(){
  int i,j,d,v,c,l,r;
  cin >> n;
  for(i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = KAZU;

  for(i=0;i<n;i++){
    cin >> v >> d;
    for(j=0;j<d;j++){
      cin >> c;
      if(j==0) T[v].left = c;
      else T[l].right = c;
      l = c;
      T[c].parent = v;
    }
  }

  for(i=0;i<n;i++){
    if(T[i].parent == KAZU) r = i;
  }

  getdepth(r,0);
  for(i=0;i<n;i++) print(i);

  return 0;
}




Measured memory_bytes: 7756
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
#define endl "\n"
using namespace std;
vector<ll>v;
ll dp[100003];
ll a,n;
ll rec(int i){
    if(i==n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    if(i<n-2){
        return dp[i]=min(abs(v[i+1]-v[i])+rec(i+1),abs(v[i+2]-v[i])+rec(i+2));
    }
    return dp[i]=abs(v[i+1]-v[i])+rec(i+1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a;
        v.pb(a);
    }
    memset(dp,-1,sizeof(dp));
    ll ans=rec(0);
    cout<<ans<<endl;



    return 0;
}



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

int main() {
  int N,X; cin >>N >>X;
  vector<int> m(N);
  rep(i,0,N) cin >>m[i];
  sort(m.begin(),m.end());
  int temp=accumulate(m.begin(),m.end(),0);
  int ans=N+(X-temp)/m[0];
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

const int MOD = 1000000007;

long long
mod_mult(long long a, long long b)
{
	long long res = 0;
	long long mir = a%MOD;
	while (b) {
		if (b & 1) {
			res += mir;
			if (res > MOD) {
				res -= MOD;
			}
		}
		mir <<= 1;
		if (mir > MOD) {
			mir -= MOD;
		}
		b >>= 1;
	}
	return res;
}

int main() {
	int n;
	long long ans=1;
	vector<int> a, b,cmax,ed;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int c;
		cin >> c;
		a.push_back(c);
		cmax.push_back(0);
		ed.push_back(0);
	}
	for (int i = 0;i < n;i++) {
		int c;
		cin >> c;
		b.push_back(c);
		cmax[i] = min(a[i], b[i]);
	}
	if (a[n - 1] != b[0]) {
		cout << 0 << endl;
		return 0;
	}
	
	for (int i = 1;i < n;i++) {
		if (a[i] != a[i - 1]) {
			if (cmax[i] >= a[i]) {
				cmax[i] = a[i];
				ed[i] = 1;
			}else{
				cout << 0 << endl;
				return 0;

			}
		}
		
	}
	for (int i = n - 2;i >= 0;i--) {
		if (b[i] != b[i + 1]) {
			if (cmax[i] >= b[i]) {
				cmax[i] = b[i];
				ed[i] = 1;
			}
			else {
				cout << 0 << endl;
				return 0;
			}
		}
		
	}
	ed[0] = 1;
	ed[n - 1] = 1;
	for (int i = 0;i < n;i++) {
		if (ed[i]==0) {
			ans = mod_mult(ans, cmax[i])%MOD;
		}
	}
	cout << ans << endl;

	return 0;
	
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

struct UnionFind{
    vector<long long> par,r;

    //はじめに全てが根であるとしておく
    UnionFind(long long N):par(N),r(N,1){iota(par.begin(),par.end(),0);}

    long long root(long long x){//根に当たるまで再帰で探す
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    long long deep(long long x,long long A){
        if(par[x] == x) return A;
        else{A++;return deep(par[x],A);}
    }

    bool same(long long x,long long y){//つながっているかどうか判定
        return root(x) == root(y);
    }

    long long size(long long x){ //根の大きさを判定する
        return r[root(x)];
    }

    void unite(long long x, long long y){//根が同じでなかったらつなげる
        x = root(x), y = root(y);
        if(x == y) return;
        if(r[x] < r[y]) swap(x,y); //値を小さいほうを根にする
        r[x] += r[y];
        par[y] = x;
        return;
    }
};


signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long N,M;cin >> N >> M;
    UnionFind UF(2*N);
    long long A,B;
    REP(i,M){
        cin >> A >> B;A--;B--;
        UF.unite(A,B + N);
        UF.unite(A + N,B);
    }
    long long sum = 0,sq = 0;
    REP(i,N) sum += i;


    REP(i,N){
        if(UF.same(i,i + N)){
            cout << sum - M << endl;
            return 0;
        }
    }
    ll b = 0,w = 0;
    REP(i,N){
        if(UF.same(0,i)) b++;
    }
    w = N - b;
    sq = b*w;
    cout << sq - M << endl;
}


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

int main(){

  int N, K; cin >> N >> K;
  deque<int> V;
  for(int i=0; i<N; i++){
    int j; cin >> j;
    V.push_back(j);
  }

  int sol = 0;
  for(int i=0; i<=K; i++){
    for(int j=0; j+i<=K; j++){
      //左からi個、右からj個取る
      deque<int> V_sub = V;
      priority_queue<int> minus;
      int sum = 0;
      
      for(int k=0; k<max(i,j) && V_sub.size() > 0; k++){
        if(k<i){
          if(V_sub.front() < 0)
            minus.push(-V_sub.front());
          sum += V_sub.front();
          V_sub.pop_front();
        }
        if(V_sub.size()==0)
          break;
        if(k<j){
          if(V_sub.back() < 0)
            minus.push(-V_sub.back());
          sum += V_sub.back();
          V_sub.pop_back();    
        }
      }
      
      if(i+j<K && minus.size() > 0){
        //操作回数が余っている、かつマイナス価値がゼロでない
        for(int k=1; i+j+k<=K && minus.size() > 0; k++){
          sum += minus.top();
          minus.pop();
        }
      }
      
      sol = max(sol, sum);
      
    }  
  }
  
  cout << sol << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define pi  3.1415926535
int main()
{
	ll n,m,i,j;
	cin>>n>>m;
	char a[n][m];
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	ll dp[n][m];
	for(i=0;i<n;i++)
	for(j=0;j<m;j++)
	dp[i][j]=0;
	for(i=0;i<n;i++)
	{
		if(a[i][0]=='#')
		break;
	dp[i][0]=1;}
	for(i=0;i<m;i++)
	{
		if(a[0][i]=='#')
		break;
	dp[0][i]=1;}
	for(i=1;i<n;i++)
	{
		for(j=1;j<m;j++)
		{
			if(a[i][j]=='#')
			continue;
			dp[i][j]=((dp[i-1][j]%mod)+(dp[i][j-1]%mod))%mod;
			//cout<<dp[i][j]<<endl;
		}
	}
	cout<<dp[n-1][m-1]<<"\n";
}


Measured memory_bytes: 12324
#include<stdio.h>

int main(){
  int n, m, X, Y;
  int ans = 0;

  scanf("%d %d %d %d", &n, &m, &X, &Y);

  int x[n];
  int y[m];

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

  int z;
  int xflag = 0;
  int yflag = 0;
  for(z = X + 1; z <= Y; z++){
    xflag = 0;
    for(i = 0; i < n; i++){
      if(x[i] >= z){
		xflag = 1;
      }
    }

    yflag = 0;
    for(j = 0; j < m; j++){
      if(y[j] < z){
		yflag = 1;
      }
    }
 
    if(xflag == 0 && yflag == 0){
      ans = 1;
      break;
    }
  }

  if(ans){
    printf("No War\n");
  }
  else{
    printf("War\n");
  }

  return 0;
}

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

import sys
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

Q = INT()
_, a, b = MAP()
mid = a
asm = 0
bsm = b
ln = 1
que1, que2 = [-a], [INF]
for _ in range(Q-1):
    li = LIST()
    if li[0] == 1:
        a, b = li[1:]
        bsm += b
        l = -que1[0]
        r = que2[0]
        if ln % 2 == 1:
            asm += abs(a - l)
            if a < mid:
                heappush(que1, -a)
                heappush(que2, -que1[0])
                heappop(que1)
            else:
                heappush(que2, a)
        else:
            if a < l:
                asm += abs(a - l)
            elif a > r:
                asm += abs(a - r)
            if a > mid:
                heappush(que2, a)
                heappush(que1, -que2[0])
                heappop(que2)
            else:
                heappush(que1, -a)
        ln += 1
        mid = -que1[0]
    else:
        print(mid, asm + bsm)


Measured memory_bytes: 80600
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
def main():
    n,m = map(int,input().split())
    x = m//2
    y = m - x
    for i in range(x):
        print(i+1,2*x+1-i)
    for i in range(y):
        print(2*x+2+i,2*x+2*y+1-i)
    
if __name__ == "__main__":
    main()

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

if abs(n-m) >= 2:
    print(0)
    exit()

ans = 1
div = 10**9+7

for i in range(1, n+1):
    ans = (ans * i) % div
for i in range(1, m+1):
    ans = (ans * i) % div

if n != m:
    print(ans)
else:
    print((ans*2)%div)

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define md (ll)(1e9+7)
#define pb push_back
#define pi pair<ll,ll>
#define ff first
#define ss second

ll c[40],ar[200005],n,l,i,t,k,j,ans;

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

	cin >> n;
	l=1;
	for(i=1;i<=n;i++)
	{
		cin >> ar[i];
		t=ar[i];
		for(j=0;t>0;j++,t=t/2)
		{
			if(t%2==1)
				c[j]++;
			while(c[j]==2)
			{
				ans+=i-l;
				for(k=0;ar[l]>0;k++,ar[l]/=2)
				{
					if(ar[l]%2==1)
						c[k]--;
				}
				l++;
			}
		}
	}

	cout << ans+((i-l)*(i-l+1))/2 << endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int n;
	cin >> n;
	int a[101] = {};
	for (int i = 0; i < n; i++)
		cin >> a[i];
	reverse(a, a + n);
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1)
			cout << " ";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3072
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main(){
    int i,j,k;
    int ans;
    long double a,b,c;

    long double eps = 1.0E-14;

    cin >> a >> b >> c;

    if(sqrt(a)+sqrt(b)+eps<sqrt(c)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};

int main()
{
	f();
	int n,x;cin>>n>>x;
	int curr=0;
	int ans=1;
	while(n--)
	{
		int num;cin>>num;
		curr+=num;
		if(curr<=x)ans++;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AABC333 solver = new AABC333();
        solver.solve(1, in, out);
        out.close();
    }

    static class AABC333 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(in.nextInt() % 2 == 1 && in.nextInt() % 2 == 1 ? "Yes" : "No");
        }

    }
}



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

int main(){
  int h,w;
  cin >> h >> w;
  string s[h];
  for(int i = 0;i < h;i++){
    cin >> s[i];
  }
  int result = -1,c;
  int l[h][w],r[h][w],u[h][w],d[h][w];
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(s[i].at(j) == '#'){
        u[i][j] = 0;
      }
      else if(i == 0){
        u[i][j] = 1;
      }
      else{
        u[i][j] = u[i-1][j] + 1;
      }
      if(s[i].at(j) == '#'){
        l[i][j] = 0;
      }
      else if(j == 0){
        l[i][j] = 1;
      }
      else{
        l[i][j] = l[i][j-1] + 1;
      }
    }
  }
  for(int i = h-1;i >= 0;i--){
    for(int j = w-1;j >= 0;j--){
      if(s[i].at(j) == '#'){
        d[i][j] = 0;
      }
      else if(i == h-1){
        d[i][j] = 1;
      }
      else{
        d[i][j] = d[i+1][j] + 1;
      }
      if(s[i].at(j) == '#'){
        r[i][j] = 0;
      }
      else if(j == w-1){
        r[i][j] = 1;
      }
      else{
        r[i][j] = r[i][j+1] + 1;
      }
      c = u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3;
      result = max(result,c);
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 66816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int a[10010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    int tmp = 0;
    while (a[i] % 2 == 0) { 
      a[i] /= 2;
      tmp++;
    }
    ans += tmp;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        sum += x;
    }
    if (n < sum) cout << -1;
    else cout << n - sum;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int box[5]={0,};

int main(int argc, const char * argv[]) {
 
    int n;
    
    scanf("%d",&n);
    
    string h;
    
    for(int i=0;i<n;i++){
        cin >> h;
        if(h[0]=='M') box[0]++;
        else if(h[0]=='A') box[1]++;
        else if(h[0]=='R') box[2]++;
        else if(h[0]=='C') box[3]++;
        else if(h[0]=='H') box[4]++;
    }

    long long sum = 0;
    
    
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                sum += (long long)box[i] * box[j] * box[k];
            }
        }
    }
  
    printf("%lld\n",sum);
    return 0;
}


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

using namespace std;

int main() {
    int n;
    string s;

    cin >> n;
    cin >> s;

    int cnt = 0;

    for (int i=0; i<s.size()-2; i++) {
        if (s.substr(i, 3) == "ABC") {
            cnt++;
        }
    }

    cout << cnt << endl;
}


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

// for the bellman-ford (BF) method
using graphBF = std::vector<std::vector<long long>>;

#define INF (long long)(1e18 + 7) 
#define ALL(x) std::begin(x), std::end(x) 

void print(std::vector<long long> vec){
    int n = vec.size();
    for(int i = 0; i < n; ++i){
        std::cout << vec.at(i) << std::endl;
    }
}

int main(){
    int n, m;
    std::cin >> n >> m;

    graphBF g;
    std::vector<long long> s(m), e(m), w(m);
    for(int i = 0; i < m; ++i){
        std::cin >> s.at(i) >> e.at(i) >> w.at(i);
        --s.at(i); --e.at(i); w.at(i); // since from-1-indexes are given, s and t have to be adjusted by -1
    }

    std::vector<long long> score(n, -INF);
    score.at(0) = 0;
    
    for(int i = 0; i < n - 1; ++i){
        for(int j = 0; j < m; ++j){
            long long buf = std::max(score.at(e.at(j)), score.at(s.at(j)) + w.at(j));
            if(buf != score.at(e.at(j))){
                score.at(e.at(j)) = buf;
            }
        }
        
//        print(score);
//        std::cout << "------" << std::endl;
    }

    // updating a score at a certain vertex at the Nth search secures the existence of a (positive, in this case,) cycle
    // in the following sectcion, it is going to be examined whether the update, if exists, will affect the score at score.at(n - 1)
    std::vector<bool> isUpdated(n, false);
    for(int j = 0; j < m; ++j){
        // if s.at(j) has been updated, e.at(j) also to be
        if(isUpdated.at(s.at(j))){
            isUpdated.at(e.at(j)) = true;
        // verify whether score.at(e.at(j)) will be updated, which means there is a cycle
        }else{
            long long buf = std::max(score.at(e.at(j)), score.at(s.at(j)) + w.at(j));
            if(buf != score.at(e.at(j))){
                isUpdated.at(e.at(j)) = true;
            }
        }
    }

    if(isUpdated.at(n - 1)){
        std::cout << "inf" << std::endl; // the Nth vertex was affected by the cycle
    }else{
        std::cout << score.at(n - 1) << std::endl;
    }

    return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int A, B, C, temp;
	long long ans = 0;
	cin >> A >> B >> C;
	temp = min(A, C);
	ans = temp;
	C -= temp;
	temp = min(B, C);
	ans += 2 * temp;
	C -= temp;
	B -= temp;
	ans += B + min(C, 1);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp90 {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();
            ulong K = ulong.Parse(Console.ReadLine());

            int len = S.Length;

            //先頭から1が何回続くかをカウントする
            int cnt_1 = 0;
            for (int i = 0; i < len; i++) {
                if (S[i] == '1') {
                    cnt_1++;
                } else {
                    break;
                }
            }

            if (K <= (ulong)cnt_1) {
                Console.WriteLine('1');
                return;
            }

            for (int i = 0; i < len; i++) {
                if (S[i] != '1') {
                    Console.WriteLine(S[i]);
                    return;
                }
            }

            Console.WriteLine('1');
        }

    }
}

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

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int arr[n+1];
	int dp[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	dp[1]=0;
	for(int i=2;i<=n;i++)
	dp[i]=INT_MAX;
	
	for(int i=2;i<=n;i++)
	{
		for(int j=i-1;j>=(i-k) && j;j--)
		{
			dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));
		}
	}
	
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair

ll dp[100000][13];
string a;

ll gs(int ind,int n,int sum){
    if(ind==n){
        //cout << "in " << sum << endl;
        return (sum%13==5 ? 1:0);
    }
    if(dp[ind][sum%13]!=-1){
        return dp[ind][sum%13]%1000000007;
    }
    if(a[ind]!='?'){
        return dp[ind][sum%13]=gs(ind+1,n,((sum*10)+a[ind]-'0')%13)%1000000007;
    }
    ll res=0;
    for(int i=0 ; i<=9 ; i++){
        res+=gs(ind+1,n,((sum*10)+i)%13);
        //cout << i << " " << res << endl;
        res%=1000000007;
    }
    return dp[ind][sum%13]=res%1000000007;
}

int main(){
	fast;
	int test=1;
	//cin >> test;
	while(test--){
	    cin >> a;
	    memset(dp,-1,sizeof dp);
	    cout << gs(0,a.length(),0) << endl;
	}
	return 0;
}

Measured memory_bytes: 21704
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if(self.parents[x] > self.parents[y]):
            x,y = y,x        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def issame(self, x, y):
        return self.find(x) == self.find(y)

    def count(self,x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def __str__(self):
        return '\n'.join('{}: {}'.format(root, self.members(root)) for root in self.roots())

n,m,k = map(int, input().split(" "))

uf_friend = UnionFind(n+1)
uf_block = UnionFind(n+1)
count = [0]*(n+1)
for i in range(m):
    a,b = map(int, input().split(" "))
    uf_friend.union(a, b)
    count[a] += 1
    count[b] += 1

for i in range(k):
    a,b = map(int, input().split(" "))
    if(uf_friend.issame(a,b)):
        count[a] += 1
        count[b] += 1

result = [0]*n
for i in range(1,n+1):
    result[i-1] = uf_friend.count(i) - count[i] - 1

print(*result)

Measured memory_bytes: 14900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    bool ok=true;
    ll time=0;
    cin >> n;
    vector<pair<int,int>> task(n);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        task[i] = make_pair(b,a);
    }
    sort(task.begin(),task.end());
    
    rep(i,n){
        time += task[i].second;
        if(time > task[i].first) ok = false;
    }
    if(ok) cout << "Yes" <<endl;
    else cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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 RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	string s;
	cin >> s;
	int ns = 0;
	int we = 0;
	REP(i, s.length()) {
		if (s[i] == 'N')
			ns|=1;
		if (s[i] == 'W')
			we|=1;
		if (s[i] == 'S')
			ns |= 2;
		if (s[i] == 'E')
			we|=2;
	}
	if ((ns == 0 || ns == 3) && (we == 0 || we == 3))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

if a == "A":
    a = 10
elif a == "B":
    a = 11
elif a == "C":
    a = 12
elif a == "D":
    a = 13
elif a == "E":
    a = 14
else:
    a = 15

if b == "A":
    b = 10
elif b == "B":
    b = 11
elif b == "C":
    b = 12
elif b == "D":
    b = 13
elif b == "E":
    b = 14
else:
    b = 15

if a > b:
    print(">")
elif a < b:
    print("<")
else:
    print("=")

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


def comb(x):
    a = 1
    for i in range(1, x+1):
        a *= i
        a %= 1000000007
    return a

if abs(n-m) > 1:
    print(0)
elif n == m:
    print((2*comb(n)**2)%1000000007)
else:
    print((comb(n) * comb(m))%1000000007)

Measured memory_bytes: 38512
#include <stdio.h>
 
int main(void){
int n,count;
int i,p[51];
 
  scanf("%d\n",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
 
  for(i=0;i<n;i++){
    if(p[i]!=i+1){
      count++;
    }
  }
 
  if(count>2){
    printf("NO");
  }
  else{
    printf("YES");
  }
  return 0;
}

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

int main(void){
  int a, b, k;
  cin >> a >> b >> k;
  for(int i = 0; i < k; i++){
    if(i%2 == 0){
      b += a/2;
      a /= 2;
      }
    else{
      a += b/2;
      b /= 2;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
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=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll N; cin >> N;
    vector<ll> a, b, c;
    vector<vector<ll>> dp(N, vector<ll>(3, -1));
    REP(i, N){
        ll a_i, b_i, c_i;
        cin >> a_i >> b_i >> c_i;
        a.PB(a_i);
        b.PB(b_i);
        c.PB(c_i);
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    REP(i, N){
        if (i == 0){continue;}
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }
    ll ans = max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]);
    cout << ans << endl;
}


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

int n,wmax;
int w[101],v[101] ;
ll dp[101][100001] ;


ll bag(int ,int) ;
ll max(ll,ll);

int main()
{
	ll result;
	cin>>n>>wmax;
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i] ;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=wmax;j++)
		dp[i][j]=-1;
	}
	
	result=bag(n,wmax) ;
	cout<<result ;
	return 0;
}

ll bag(int i,int j)
{
	if(dp[i][j]!=-1)
	{
		return(dp[i][j]) ;
	}
	
	if(i==0 || j==0) dp[i][j]=0;
	
	else if(j<w[i]) 
	{
		dp[i][j]=bag(i-1,j) ;
	}
	
    else dp[i][j]=max(bag(i-1,j),v[i]+bag(i-1,j-w[i])) ;
	
	return(dp[i][j]) ;
	
}

ll max(ll a,ll b)
{
	if(a>=b) return a;
	return b ;
}


Measured memory_bytes: 79104
process.stdin.resume();
process.stdin.setEncoding('utf8');
var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});
function main(input){
  input = input[0].split(" ")
  console.log(input[0]*1+1-input[1]*1)
}

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

int N;
long A[1000000];

int main() {
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> A[i];
    }
    A[N] = 0;
    sort(A,A+N);
    int count = 1;
    int count2 = 0;
    for(int i=1;i<=N;i++){
        if(A[i-1]==A[i]){
            //cout << A[i] <<" " << A[i+1] <<"\n";
            count++;
            //cout << count <<"\n";
        } else {
            //cout << i <<" " << count <<"\n";
            if(count%2==1) count2++;
            count = 1;
            //cout << i << " " <<count2 <<"\n";
        }
    }

    cout << count2 <<"\n";
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(b < a){
        for(int i = 0;i < a;i++)
            cout << b;
        cout << endl;
        return 0;
    }
    for(int i = 0;i < b;i++)
        cout << a;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = [[int(a) for a in input().split()] for _ in range(N)]

from operator import itemgetter

L.sort(key=itemgetter(1))

t = 0
ans = "Yes"
for i in range(N):
    if L[i][0] > L[i][1]-t:
        ans = "No"
        break
    else:
        t += L[i][0]
        
print(ans)

Measured memory_bytes: 41308
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define pb push_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define bump cout<<"bleh\n"
#define all(v) (v).begin(),(v).end()

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;
const ll infll=1e15;


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int ara[n];
    for(int i=0;i<n;i++)cin>>ara[i];

    bool ok=1;

    for(int i=0;i<n;i++){
        if(ara[i]%2==0){
            if(ara[i]%3 and ara[i]%5){
                ok=0;
                break;
            }

        }

    }

    if(ok)cout<<"APPROVED\n";
    else cout<<"DENIED\n";


    return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = list(map(int, input().split()))

turn_p = 0
if N > 2:
    a_ = A[1]
    d_ = np.sign(A[1] - A[0])
    for a in A[2:]:
        d = np.sign(a - a_)
        #print(a, d, d_, turn_p)
        if d != 0:
            if d_ == 0:
                d_ = d
            elif d_ != d:
                turn_p += 1
                d_ = 0
        a_ = a 

print(turn_p+1)
    



Measured memory_bytes: 23144
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{int a1,a2,a3,cost[6],ans=100000,i;
    scanf("%d %d %d",&a1,&a2,&a3);
   
        cost[0]=abs(a1-a2)+abs(a2-a3);
        cost[1]=abs(a1-a3)+abs(a2-a3);
        cost[2]=abs(a2-a1)+abs(a1-a3);
        cost[3]=abs(a2-a3)+abs(a1-a3);
        cost[4]=abs(a3-a1)+abs(a1-a2);
        cost[5]=abs(a3-a2)+abs(a1-a2);
        for(i=0;i<6;i++){
            if(cost[i]<ans){
                ans=cost[i];
            }
        }
        printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <queue>

using namespace std;

int w,h;
bool** flags;
char** map;

class Point{
public:
	int X,Y;
};

template <class T> T** NewArray(int w,int h){
	T** r = new T*[w];
	for(int i=0;i<w;i++){
		r[i] = new T[h];
		for(int j=0;j<h;j++){
			r[i][j] = 0;
		}
	}
	return r;
}

template <class T> void RemoveArray(T** array,int w,int h){
	for(int i=0;i<h;i++){
		delete[] array[i];
	}
	delete[] array;
}

bool Check(int x,int y,int c){
	if(x<0){return false;}
	if(y<0){return false;}
	if(x>=w){return false;}
	if(y>=h){return false;}
	if(flags[x][y]){return false;}
	if(map[x][y] != c){return false;}
	return true;
}

bool Solve(int sx,int sy,int gx,int gy){
	//printf("(%2d,%2d)->(%2d,%2d)\n",sx,sy,gx,gy);
	char c = map[sx][sy];
	queue<Point> pts;
	flags = NewArray<bool>(w + 1,h + 1);
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
			flags[i][j] = false;
		}
	}
	Point p,pp;
	p.X = sx;
	p.Y = sy;
	pts.push(p);
	flags[sx][sy] = true;
	
	bool res = false;
	
	while(pts.size() > 0){
		p = pts.front();
		pts.pop();
		if(flags[gx][gy] == true){
			res = true;
			break;
		}
		pp = p;
		pp.X -= 1;
		if(Check(pp.X,pp.Y,c)){ pts.push(pp); flags[pp.X][pp.Y]=true; }
		pp = p;
		pp.X += 1;
		if(Check(pp.X,pp.Y,c)){ pts.push(pp); flags[pp.X][pp.Y]=true; }
		pp = p;
		pp.Y -= 1;
		if(Check(pp.X,pp.Y,c)){ pts.push(pp); flags[pp.X][pp.Y]=true; }
		pp = p;
		pp.Y += 1;
		if(Check(pp.X,pp.Y,c)){ pts.push(pp); flags[pp.X][pp.Y]=true; }
	}
	
	RemoveArray<bool>(flags,w + 1,h + 1);
	return res;
}

int main(){
	int xs,ys,xg,yg;
	
	while(scanf("%d %d",&w,&h) && w && h){
		w+=1;
		h+=1;
		map = NewArray<char>(w + 1,h + 1);
		scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
		xs -= 1;
		ys -= 1;
		xg -= 1;
		yg -= 1;
		int n;
		scanf("%d",&n);
		int c,d,x,y;
		int xx,yy;
		for(int j=0;j<h;j++){
			for(int i=0;i<w;i++){
				//printf("%d ",map[i][j]);
				map[i][j] = 0;
			}
			//printf("\n");
		}
		
		for(int i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			if(d == 0){
				xx = 4;
				yy = 2;
			}else{
				xx = 2;
				yy = 4;
			}
			x-=1;
			y-=1;
			for(int j=0;j<xx;j++){
				for(int k=0;k<yy;k++){
					//printf("(%2d+%2d,%2d+%2d) = %d\n",k,j,y,k,c);
					map[x+j][y+k] = c;
				}
			}
		}
		for(int j=0;j<h;j++){
			for(int i=0;i<w;i++){
				//printf("%d ",map[i][j]);
			}
			//printf("\n");
		}
		
		
		if(Solve(xs,ys,xg,yg)){
			printf("OK\n");
		}else{
			printf("NG\n");
		}
		RemoveArray<char>(map,w + 1,h + 1);
	}
}

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

int main(){
    int n, yen;
    cin >> n >> yen;

    for(int x = 0; x <= n; x++){
        for(int y = 0; y <= n - x; y++){
            int z = n - x - y;
            if(10000 * x + 5000 * y + 1000 * z == yen){
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
}


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

int main() {
    int n;
    cin>>n;
    int d=0,a;
    for (int i=0;i<n;i++) {
        cin>>a;
        d+=a!=i+1;
    }
    if (d<=2)
        puts("YES");
    else
        puts("NO");
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	bool f = true;
	rep(i, n) {
		if (a[i] % 2 == 0) {
			if (!(a[i] % 3 == 0 || a[i] % 5 == 0)) {
				f = false;
				break;
			}
		}
	}

	if (f) {
		out("APPROVED");
	}
	else {
		out("DENIED");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int count[26];
  rep(i,0,26) count[i]=0;
  rep(i,0,n) count[s[i]-'a']++;
  string t="Yes";
  rep(i,0,26){
    if(count[i]%2!=0){
      t="No";
    }
  }
  cout<<t<<endl;
}

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

#define N 100100

int n, a[N];
map <int, int> mp;
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
    bool fg = 1;
    for (int i = 0; i < n; i ++) if (a[i]) fg = 0;
    if (fg) return puts("Yes"), 0;
    if (n % 3) return puts("No"), 0;
    int k;
    for (k = 1; k < n; k ++) if (a[0] != a[k]) break;
    if (k == n) return puts("No"), 0;
    if (a[0] > a[k]) swap(a[0], a[k]);
    for (int i = 0; i < n; i ++) mp[a[i]] ++;
    int c = n / 3;
    if (mp[a[0]] != c) return puts("No"), 0;
    if (a[0]) {
        if (mp[a[k]] == c && mp[a[0]^a[k]] == c) puts("Yes");
        else puts("No");
    }
    else {
        if (mp[a[k]] == 2 * c) puts("Yes");
        else puts("No");
    }

    return 0;
}


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

#define imie(...) " [" <<#__VA_ARGS__<<':'<<(__VA_ARGS__)<<"] "
int arr[100000+5];
int dp[100000+5];
int n,k;


int main () {
	  #ifndef ONLINE_JUDGE
	    freopen("in.txt","r",stdin);
	    freopen("out.txt","w",stdout);
    #endif
	cin>>n>>k;
	for(int i=0;i<n; i++) cin>>arr[i];
	dp[0] = 0;
	for(int i=1;i<n;++i){
		int ans = INT_MAX;
		for(int j=i-1; j >=0 && j >= i-k; --j){
			ans = min(ans,dp[j] + abs(arr[j] - arr[i]));
		}
		dp[i] = ans;
	}
	cout<<dp[n-1];
	

}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e17 + 7;

map<int, V<pi>> m;

signed main()
{
	IO_OP;

	int n, x, d;
	cin >> n >> x >> d;
	if (d == 0) {
		if (x == 0) cout << 1 << endl;
		else cout << n + 1 << endl;
		return 0;
	}
	if (x == 0) {
		cout << 1 + n * (n - 1) / 2 << endl;
		return 0;
	}
	for(int take=0;take<=n;take++) {
		int mid = take * x;
		int l = take * (take - 1) / 2 + mid / d;
		int r = take * (2*n-take-1) / 2 + mid / d;
		m[mid % d].EB(l, r);
	}
	int ans = 0;
	for(auto& p:m) {
		V<pi> &v = p.S;
		sort(ALL(v));
		int mx = -INF;
		for(pi p:v) {
			int l = p.F, r = p.S;
			if(l > mx) ans += r - l + 1;
			else ans += max(0LL, r - mx);
			mx = max(mx, r);
		}
	}
	cout << ans << endl;
	
}





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

int digit(int num) {
  int dig;
  int sum=0;
  while(num){
    dig=num%10;
    sum+=dig;
    num/=10;
  }
  return sum;
}

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int sums=0;
  for(int i=1;i<=n;i++) {
    if(a<=digit(i)&&digit(i)<=b) {
      sums+=i;
    }
  }
  cout<<sums<<endl;
}

Measured memory_bytes: 256
size::Int->Int
size 0 = 1
size n = 2*(size (n-1))+3

pate::Int->Int
pate 0 = 1
pate n = 2*(pate (n-1))+1

solver::Int->Int->Int
solver 0 k = if k >= 1 then 1 else 0
solver n k = if ((size (n-1))+1) > k
                then solver (n-1) (k-1)
                else if ((size (n-1))+2) > k
                        then pate (n-1)
                        else (pate (n-1)) + 1 + (solver (n-1) (k- ((size (n-1)) + 2 )))

main::IO()
main=do
  nkc<-getLine
  let n:k:[]=map read (words nkc)
  print (solver n k)

Measured memory_bytes: 508