akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int N, M;
int a[100];

void sit_from_left(int id) {
  for (int i = 0; i < N; ++i) {
    if (a[i] == -1) {
      a[i] = id;
      break;
    }
  }
}

void sit_a() {
  sit_from_left(0);
}

void sit_b() {
  bool sat = false;;
  for (int i = N - 1; i >= 0; --i) {
    if (a[i] != -1) {
      continue;
    }
    if (i > 0 && a[i - 1] == 0) {
      continue;
    }
    if (i < N - 1 && a[i + 1] == 0) {
      continue;
    }
    a[i] = 1;
    sat = true;
    break;
  }

  if (sat) {
    return;
  }

  sit_from_left(1);
}

void sit_c() {
  bool sat = false;
  for (int i = 0; i < N; ++i) {
    if (a[i] == -1) {
      continue;
    }
    if (i < N - 1 && a[i + 1] == -1) {
      a[i + 1] = 2;
      sat = true;
      break;
    }
    if (i > 0 && a[i - 1] == -1) {
      a[i - 1] = 2;
      sat = true;
      break;
    }
  }

  if (sat) {
    return;
  }

  a[N / 2] = 2;
}

void sit_d() {
  int m = 0;
  int mi = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i] != -1) {
      continue;
    }
    int l = N;
    int r = N;
    for (int j = i; j >= 0; --j) {
      if (a[j] != -1) {
        l = i - j;
        break;
      }
    }
    for (int j = i; j < N; ++j) {
      if (a[j] != -1) {
        r = j - i;
        break;
      }
    }
    if (m < min(l, r)) {
      m = min(l, r);
      mi = i;
    }
  }
  a[mi] = 3;
}

int main() {
  while (1) {
    cin >> N >> M;
    if (!N && !M) {
      break;
    }
    fill(a, a + N, -1);
    for (int i = 0; i < M; ++i) {
      string s;
      cin >> s;
      if (s == "A") {
        sit_a();
      } else if (s == "B") {
        sit_b();
      } else if (s == "C") {
        sit_c();
      } else if (s == "D") {
        sit_d();
      }
    }
    for (int i = 0; i < N; ++i) {
      if (a[i] < 0) {
        cout << (char)'#';
      } else {
        cout << (char)('A' + a[i]);
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3108
N,K,Q =map(int,input().split())
A = [int(input()) for i in range(Q)]
point = [K-Q]*N
for i in range(Q):
    point[A[i]-1] +=1
for i in range(N):
    if(point[i]>0):
        print("Yes")
    else:
        print("No")

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/04/25  Problem: AOJ 2157 / Link: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2157  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */
struct InitMap {
	int val;
	InitMap(long long i=100000):val(i) {}
};

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


	while (cin >> N, N) {
		string s, t; cin >> s >> t;
		VI usenum;
		LL ans = 0;
		FOR(i, 0, N) {
			s[i] -= '0';
			t[i] -= '0';
		}

		queue<string>Q;
		map<string, InitMap>d;
		d[s].val = 0;
		Q.push(s);

		while (!Q.empty()) {
			string a = Q.front(); Q.pop();
			int dist = d[a].val;
			if (a == t) {
				ans = dist;
				break;
			}
			int id = 0;
			while (a[id] == t[id])id++;
			int diff = (t[id] - a[id] + 10) % 10;
			FOR(j, id, N) {
				a[j] += diff;
				a[j] %= 10;
				if (d[a].val > dist + 1) {
					d[a].val = dist + 1;
					Q.push(a);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}


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

int main()
{
    int n,k;
    std::cin>>n>>k;
    std::vector<int> h(n);
    for(int i=0;i<n;i++)std::cin>>h[i];

    std::vector<int> dp(n,2000000000); //dp[i] : i番目の足場に行くための最小コスト
    dp[0] = 0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j >= 0) dp[i] = std::min(dp[i],dp[i-j] + std::abs(h[i] - h[i-j]));
        }
    }
    std::cout<<dp[n-1]<<std::endl;
}

Measured memory_bytes: 1024
//AtCoder ABC062 B - Picture Frame
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    int H,W;
    cin>>H>>W;
    vector<string> atbl(H);
    for(auto&& a:atbl){
        cin>>a;
    }
    cout<<string(atbl[0].size()+2,'#')<<endl;
    for(const auto & a:atbl){
        cout<<"#"<<a<<"#"<<endl;
    }
    cout<<string(atbl[0].size()+2,'#')<<endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CFolia {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n+1);
      rep(i, n+1) {
        cin >> a[i];
      }
      if (n==0) {
        if (a[0] == 1) {
          cout << 1 << endl;
        } else {
          cout << -1 << endl;
        }
        return;
      }


      vector<ll> c(n+1);
      c[n] = a[n];
      for(int i=n-1; i>=0; i--) {
        c[i] = c[i+1] + a[i];
      }

      vector<ll> b(n+1);
      b[0] = 1;
      for(int i=1; i<=n; i++) {
        b[i] = min((b[i-1]-a[i-1])*2, c[i]);
      }

      for(int i=0; i<=n; i++) {
        if (a[i] > b[i]) {
          cout << -1 << endl;
          return;
        }
      }

      ll ans = 0;
      rep(i, n+1) {
        ans += b[i];
      }
      cout << ans << endl;
    }
};

signed main() {
  CFolia solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 5612
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            int[] nums = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int X = nums[0], Y = nums[1];
            if ((4 * X < Y) || (X >= Y) || (Y % 2 == 1) || (Y / 4) > X || X > (Y / 2))
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 28232
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long p[210];
long long v[210];
char in[210];
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int a;scanf("%d",&a);
		for(int i=0;i<a;i++){
			scanf("%lld",p+i);
		}
		scanf("%s",in);
		bool ok=true;
		for(int i=a-1;i>=0;i--){
			if(in[i]=='1'&&p[i])ok=false;
			for(int j=i-1;j>=0;j--){
				p[j]=min(p[j],p[j]^p[i]);
			}
		}
		if(ok){
			printf("0\n");
		}else printf("1\n");
	}
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl a(n);
  vector<bool> z(1000007, true);
  vector<bool> z1(1000007, false);
  rep(i, n){
    cin >> a[i];
    if(z[a[i]]){
      for (ll j = 2; a[i] * j < 1000007; j++){
        z[a[i] * j] = false;
      }
      if(z1[a[i]])z[a[i]] = false;
      z1[a[i]] = true;
    }
  }
  ll ans = 0;
  rep(i, n){
    if(z[a[i]])
      ans++;
  }
  print(ans);
}


Measured memory_bytes: 5068
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>

using namespace std;

using ll = long long int;
#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    vector<pair<int, int>> Ssum(S.size() + 1);
    Ssum[0] = make_pair(0, 0);
    loop(i, S.size()){
        Ssum[i + 1] = Ssum[i];
        if (S[i] == 'A'){
            ++Ssum[i + 1].first;
        }else{ // S[i] == 'B'
            ++Ssum[i + 1].second;
        }
    }
    string T;
    cin >> T;
    vector<pair<int, int>> Tsum(T.size() + 1);
    Tsum[0] = make_pair(0, 0);
    loop(i, T.size()){
        Tsum[i + 1] = Tsum[i];
        if (T[i] == 'A'){
            ++Tsum[i + 1].first;
        }else{ // T[i] == 'B'
            ++Tsum[i + 1].second;
        }
    }
    scanInt(q);
    loop(i, q){
        scanInt(ai); --ai;
        scanInt(bi); bi;
        scanInt(ci); --ci;
        scanInt(di); di;
        // printf("%d %d ", Ssum[bi].first, Ssum[bi].second);
        // printf("%d %d ", Ssum[ai].first, Ssum[ai].second);
        // printf("%d %d ", Tsum[di].first, Tsum[di].second);
        // printf("%d %d ", Tsum[ci].first, Tsum[ci].second);
        // printf("%d %d ", (Ssum[bi].first - Ssum[ai].first), (Ssum[bi].second - Ssum[ai].second));
        // printf("%d %d ", (Tsum[di].first - Tsum[ci].first), (Tsum[di].second - Tsum[ci].second));
        const int Srem = (((Ssum[bi].first - Ssum[ai].first) - (Ssum[bi].second - Ssum[ai].second)) % 3 + 3) % 3;
        const int Trem = (((Tsum[di].first - Tsum[ci].first) - (Tsum[di].second - Tsum[ci].second)) % 3 + 3) % 3;
        // printf("%d %d ", Srem, Trem);
        if (Srem == Trem){
            puts("YES");
        }else{
            puts("NO");
        }
    }
}


Measured memory_bytes: 2432
program sample
implicit none
integer K,A,B,C,count1,count2
read(*,*)K
read(*,*)A,B
C=A/K
count1=(C+1)*K
count2=C*K
If (count1>=A.and.count1<=B) then
   write(*,*) "OK"
else if (count2==A) then
   write(*,*) "OK"
else
   write(*,*) "NG"
end if
stop
end program sample

Measured memory_bytes: 2796
#include <iostream>
using namespace std;
int main(){
	char c;
	cin>>c;
	if(c=='a')cout<<'b';
	if(c=='b')cout<<'c';
	if(c=='c')cout<<'d';
	if(c=='d')cout<<'e';
	if(c=='e')cout<<'f';
	if(c=='f')cout<<'g';
	if(c=='g')cout<<'h';
	if(c=='h')cout<<'i';
	if(c=='i')cout<<'j';
	if(c=='j')cout<<'k';
	if(c=='k')cout<<'l';
	if(c=='l')cout<<'m';
	if(c=='m')cout<<'n';
	if(c=='n')cout<<'o';
	if(c=='o')cout<<'p';
	if(c=='p')cout<<'q';
	if(c=='q')cout<<'r';
	if(c=='r')cout<<'s';
	if(c=='s')cout<<'t';
	if(c=='t')cout<<'u';
	if(c=='u')cout<<'v';
	if(c=='v')cout<<'w';
	if(c=='w')cout<<'x';
	if(c=='x')cout<<'y';
	if(c=='y')cout<<'z';
	return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
sum = 0
if x == 1 and y == 1:
    print(1000000)
else:
    if x == 1:
        sum += 300000
    elif x == 2:
        sum += 200000
    elif x == 3:
        sum += 100000
    if y == 1:
        sum += 300000
    elif y == 2:
        sum += 200000
    elif y == 3:
        sum += 100000
    print(sum)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 100005
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}
int n,key[N],fa[N],sum[N],flag;
char s[N];
int findfa(int x) {return fa[x]==x?x:fa[x]=findfa(fa[x]);}
int main()
{
    scanf("%s",s+1); n=strlen(s+1);
    if(n&1) flag=1,n--;
    for(int i=1;i<=n/2;++i) 
	key[i]=s[flag?(n+2-i):(n+1-i)]-s[i],fa[i]=i;
    fa[n/2+1]=n/2+1,key[n/2+1]=0;
    for(int i=n/2;i;--i) key[i]-=key[i-1];
    for(int T=gi(),le,ri;T;--T) {
	le=gi(),ri=gi();
	if(flag) {
	    if(le>n/2+1) le--;
	    if(ri>n/2) ri--;
	}
	if(le>ri) continue;
	if(le<=n/2 && ri>n/2) {
	    if(n/2+1-le >= ri-n/2) ri=n-ri;
	    else le=n+2-le;
	}
	if(le>ri) continue;
	if(le>n/2)
	    le=n+1-le,ri=n+1-ri,swap(le,ri);
	ri++;
	if(findfa(le)!=findfa(ri)) fa[fa[le]]=fa[ri];
    }
    findfa(n/2+1);
    for(int i=1;i<=n/2;++i) sum[findfa(i)]+=key[i];
    for(int i=1;i<=n/2;++i) {
	if(fa[i]==fa[n/2+1]) continue;
	if(sum[fa[i]]%26) {puts("NO"); return 0;}
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 896
import java.io.*;
import java.io.BufferedReader;
public class Main{
    public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;
	while((line=br.readLine()) != null){
	    StringBuffer sb = new StringBuffer().append(line);
	System.out.print(sb.reverse()+"\n");
	}
    }
}

Measured memory_bytes: 24192
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int a, b, x;
  cin >> x >> a >> b;
  char ans = 'A';
  if (abs(x - a) > abs(x - b)) ans = 'B';
  cout << ans << endl;
}


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

int main(){
    string s;
    cin>>s;
    string t=s;
    if(s=="keyence"){
        cout<<"YES"<<endl;
        return 0;
    }
    
    for(int i=0;i<s.size();i++){
        for(int j=0;j<s.size();j++){
            string u=t;
            string r=u.erase(i,j);
            if(r=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
   long long n,m;
   scanf("%lld%lld",&n,&m);
   if(abs(n-m)>1)
    printf("0\n");
   else
   {
       long long ans=1;
       if(n==m)
        ans*=2;
       for(int i=2;i<=n;i++)
       {
           ans*=i;
           ans%=mod;
       }
       for(int i=2;i<=m;i++)
        {
           ans*=i;
           ans%=mod;
       }
       printf("%lld\n",ans);
   }
}



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

def solve(i, j):
    for a in range(H):
        for b in range(W):
            if 0 <= i + a < N and 0 <= j + b < N:
                continue
            else:
                return False
    return True

ans = 0

for i in range(N):
    for j in range(N):
        if solve(i, j):
            ans += 1

print(ans)

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

// 一番sが大きいものを決める
int main(){
  int D;
  cin>>D;
  vector<int> c(26+1);
  for(int i(1);i<27;i++){
    cin>>c[i];
  }
  vector<vector<int>> s(D+1,vector<int>(26+1));
  for(int i(1);i<=D;i++){
    for(int j(1);j<=26;j++){
      cin>>s[i][j];
    }
  }
  for(int i(1);i<=D;i++){
    int maxj = 0,maxp = 0;
    for(int j(0);j<=26;j++){
      if(maxp < s[i][j]){
        maxp = s[i][j];
        maxj = j;
      }
    }
    cout << maxj << endl;
  }

  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;


template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n) { // nの素因数分解を求める
        map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

void Main() {
	ll N; cin >> N;
	ll res = 0;
	PrimeFact<ll> pf(N);
	FOR(i,1,N) {
		auto pf_res = pf.get(N - i);
		ll tmp = 1;
		for(pair<ll, ll> p : pf_res) {
			tmp *= p.second + 1;
		}
		res += tmp;
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 11096
#include<bits/stdc++.h>
using namespace std;
int n,k,x,y,a[100005],b[100005],ans=2147483647;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int k;
		scanf("%d",&k);
		if(k>0)	a[++x]=k;
		else	b[++y]=-k;
	}
	sort(a+1,a+x+1);
	sort(b+1,b+y+1);
	for(int i=0;i<=k&&i<=x;i++)
	{
		if(k-i<=y)
		{
		int sum=a[i]+b[k-i]+min(a[i],b[k-i]);
		ans=min(ans,sum);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	char a[100001];
	int i,count=1,n;
	scanf("%d",&n);
	getchar();
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i+1])
			count=count+0;
		else
			count=count+1;
	}
	printf("%d\n",count);
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> P(N+1), sum(N+1);
    for(int i = 1; i<= N; i++){
        cin >> P[i];
        sum[i] = sum[i-1] + P[i];
    } 
    int ans = 0;
    for(int i = 0; i < N - K + 1; i++){
        ans = max(ans, sum[i + K] - sum[i]);
    }

    cout << fixed << setprecision(2);
    cout << (double)(ans + K) / 2.0 << endl;
}

Measured memory_bytes: 1792
main = do
  [a,b,c,d] <- getLine
  let x = read [a,b] :: Int
      y = read [c,d] :: Int
  let xm = 1 <= x && x <= 12
      ym = 1 <= y && y <= 12
  putStrLn $ case (xm, ym) of
    (True, True) -> "AMBIGUOUS"
    (True, False) -> "MMYY"
    (False, True) -> "YYMM"
    (False, False) -> "NA"


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define endl "\n"
#define ll long long int
#define vll vector<long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define umap unordered_map 
#define mod 1000000007
#define fori(a,n) for(int i=a;i<n;i++)
#define forj(a,n) for(int j=a;j<n;j++)
#define MAX 300303
using namespace std;
vi dp(100001,INT_MAX);
int n,k;
signed main()
{
    io
    cin >> n >> k;
    vi h(n);
    fori(0,n)cin >> h[i];
    dp[0] = 0;
    fori(0,n){
        forj(i+1,min(i+k+1,n)){
            dp[j] = min(dp[j] , dp[i] + abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << endl;
}

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

using namespace std;

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

	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans=0;
	ans+=min(a, k);
	k-=min(a, k);
	k-=min(b, k);
	ans-=min(c, k);
	k-=min(c, k);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>

using ll = long long;

using namespace std;

#define fi first
#define se second

int main() {
    long n, x, d;
    cin >> n >> x >> d;
    if (d < 0) {
        x += (n-1) * d;
        d = -d;
    }
    if (d == 0) {
        cout << (x == 0 ? 1 : n+1) << '\n';
        return 0;
    }
    long ma[n+1], mi[n+1];
    for (long i=0; i<=n; i++) {
        ma[i] = (n - i + n - 1) * i / 2 + 1;
        mi[i] = (0 + i - 1) * i / 2;
        // cerr << i << ' ' << mi[i] << ' ' << ma[i] << '\n';
    }
    map<long, map<long, int>> segs;
    for (int k=0; k<=n; k++) {
        long mul = x * k, r = (mul % d + d) % d;
        segs[r][mi[k] + (mul - r) / d] += 1;
        segs[r][ma[k] + (mul - r) / d] -= 1;
        // cerr << k << ' ' << mi[k] + (mul - r) / d << ' ' << ma[k] + (mul - r) / d << '\n';
    }
    long ans = 0;
    for (auto &sp:segs) {
        auto seg = sp.se;
        // cerr << sp.fi << '\n';
        long flag = 0, start;
        for (auto &s:seg) {
            // cerr << flag << ' ' << s.fi << '\n';
            if (flag == 0 && s.se > 0)
                start = s.fi;
            if (flag > 0 && s.se == -flag)
                ans += s.fi - start;
            flag += s.se;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 53376
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define el '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
        enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int inf = 1e10;

signed main(){
        IOS;
        int n , k;
        cin >> n >> k; 
        vector<int>arr(n),dp(n,inf);
        dp[0] = 0;
        for(int& i : arr) cin >> i ;
        for(int i=0;i<n;i++){
                for(int j=1;j<=k;j++){
                        if(i+j<n){
                                dp[i+j] = min(dp[i]+abs(arr[i+j]-arr[i]),dp[i+j]);
                        }
                }
        }
        cout << dp[n-1] << endl; 
        return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()

BC.sort(key=lambda x: -x[1])

tmp = []

for B, C in BC:
    tmp += [C] * B
    if len(tmp) >= N:
        break
A.extend(tmp)

A.sort(reverse=True)
print(sum(A[:N]))


Measured memory_bytes: 36148
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    n, a, b = reads()
    s = input()
    
    ai, bi = 0, 0
    for c in s:
        if c == 'a':
            if ai+bi < a+b:
                print('Yes')
                ai += 1
            else:
                print('No')
        elif c == 'b':
            if ai+bi < a+b and bi < b:
                print('Yes')
                bi += 1
            else:
                print('No')
        else:
            print('No')

main()


Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long R, G, B, N;
    cin >> R >> G >> B >> N;
 
    int ans = 0;
 
    for (int r = 0; r <= 3000; ++r) {
        for (int g = 0; g <= 3000; ++g) {
            int bB = N - r*R - g*G;
            if (bB >= 0 && bB % B == 0) ans++;
        }
    }
 
    cout << ans << endl;
    return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    ll sum = 0;
    string S; cin>>S;
    rep(i,S.size()){
        int tmp = int(S.at(i)-'0');
        sum += tmp;
        sum %= 9;
    }
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

long long int a, b, k, ac, bc;

int main() {
	cin >> a >> b >> k;
	ac = max(0ll, a - k);
	k -= (a - ac);
	b = max(0ll, b - k);
	cout << ac << ' ' << b;
	return 0;
}
	


Measured memory_bytes: 256
/**
 *  @author: pr4shan7 (प्रशांत)
 */
// #define _DEBUG

#ifndef _DEBUG
#define NDEBUG
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_set;

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

#ifdef _DEBUG
  ifstream cin("input.txt");
  // ofstream cout("output.txt");
#endif

  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n & 1)
    cout << "No" << '\n';
  else {
    if (s.substr(0, s.length() / 2) == s.substr(s.length() / 2, s.length() / 2))
      cout << "Yes" << '\n';
    else
      cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char str[1005];
	int sum = 0;
	scanf("%s",str);
	while(str[0]!='0'){
		for(int i=0;i<strlen(str);i++){
			sum += str[i]-48;
		}
		printf("%d\n",sum);
		sum=0;
		scanf("%s",str);
	}
	return 0;
}


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

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sArr = Console.ReadLine().Split(' ');
            int a = int.Parse(sArr[0]);
            int b = int.Parse(sArr[1]);

            int s = a * b;
            int l = 2 * (a + b);

            Console.WriteLine(string.Format("{0} {1}", s, l));
            Console.Read();
        }
    }
}

Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		
		if (N < 105) {
			System.out.println(0);
			return;
		}
		int count = 0;
		int sum = 1;
		
		for (int j = 106; j <= N; j++) {
			if (j % 2 == 0) {
				continue;
			}
			for (int i = 1; i <= j; i++) {
				if (j % i == 0) {
					count++;
				}
			}
			
//			System.out.println(count);
			if (count == 8) {
				sum++;
			}
			count = 0;
		}
		
		System.out.println(sum);
		scanner.close();
	}
}

Measured memory_bytes: 21844
#include <cstdio>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	printf("%d\n",n*(n-1)/2-(n/2));
for (int x=1;x<=n;x++){
  for (int y=x+1;y<=n;y++){
    if (x+y!=(n|1)){
      printf("%d %d\n",x,y);
    }
  }
}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(0<=i&&i<a){
            if(s[i]=='-'){
                puts("No");
                return 0;
            }
        }
        else if(i==a){
            if(s[i]!='-'){
                puts("No");
                return 0;
            }
        }
        else{
            if(s[i]=='-'){
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    map<int, int> m;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        m[tmp]++;
    }
    int cnt = 0;
    for(auto i : m) {
        if(i.second % 2 == 1) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4992
ans = []
while True:
    place = range(1,7)
    n = input()
    if n == 0:
        break
    p = 0
    sig = 1
    while p != n:
        direct = raw_input()
        if direct == "North":
            temp = place[1]
            place[1] = place[5]
            place[5] = place[4]
            place[4] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "East":
            temp = place[3]
            place[3] = place[5]
            place[5] = place[2]
            place[2] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "West":
            temp = place[2]
            place[2] = place[5]
            place[5] = place[3]
            place[3] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "South":
            temp = place[4]
            place[4] = place[5]
            place[5] = place[1]
            place[1] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "Right":
            temp = place[1]
            place[1] = place[2]
            place[2] = place[4]
            place[4] = place[3]
            place[3] = temp
            sig += place[0]
        elif direct == "Left":
            temp = place[1]
            place[1] = place[3]
            place[3] = place[4]
            place[4] = place[2]
            place[2] = temp
            sig += place[0]
        p += 1
    ans.append(sig)

for i in ans:
    print i

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std; 
#define deb(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;}; 



void solve(){
	int a , b , c , k;
	cin >> a >> b >> c >> k;
	
	if(k < (a + b)){cout << k << endl; return;}
	
	else cout << a  - (k - (a + b)) << endl;



}





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



Measured memory_bytes: 3620
ans = True
key = 0
s = input()

for i in range(len(s)):
  if i == 0 and s[0] != "A":
    ans = False
  if (i == 1 or i == len(s)-1) and s[i].isupper():
    ans = False
  if 2 <= i <= len(s)-2:
    if s[i] == "C":
      key += 1
    elif s[i].isupper():
      ans = False
if key == 1 and ans:
  print("AC")
else:
  print("WA")

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<iostream>
using namespace std;
typedef long long LL;

const LL MaxN = 3e5 + 5;
const LL MinN = -1e18;
LL sumf,sume,ans,n;
LL dpf[MaxN],dpe[MaxN],a[MaxN];

priority_queue<LL>quee;
priority_queue<LL,vector<LL>,greater<LL> >quef;


void Solve1(int n){
	LL sumf = 0;
for(int i = 1;i <= 3*n;i++){
		quef.push(a[i]);
		sumf += a[i];
		dpf[i] = sumf;
		if(quef.size() > n){
			sumf -= quef.top();
			quef.pop();
			dpf[i] = sumf;
		}
	}
}

void Solve2(int n){
	LL sume = 0;
	for(int i = 3*n;i >= 1;i--){
		quee.push(a[i]);
		sume += a[i];
		dpe[i] = sume;
		if(quee.size() > n){
			sume -= quee.top();
			quee.pop();
			dpe[i] = sume;
		}
	}
}




int main()
{
	cin >> n;
	for(int i = 1;i <= 3*n;i++)cin >> a[i];

	Solve1(n);
	Solve2(n);

	ans = MinN;
	for(int i = n;i <= 2*n;i++){
		ans = max(ans,dpf[i] - dpe[i+1]);
	}
	cout << ans;
	cout << endl;
}

Measured memory_bytes: 9716
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    ll n;
    cin>>n;
    ll sum=0,cur=26,p=0;
    string ans="";
    string A="zabcdefghijklmnopqrstuvwxy";
    while(n)
    {
        ans=A[n%26]+ans;
        if(n%26==0) n-=26;
        else n-=n%26;
        n/=26;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  ll k,a,b,sum=1;
  cin >> k >> a >> b;
  if(b-a<2)cout<<k+1<<endl;
  else{
    if(k<=a)sum=1+k;
    else if((k-a+1)%2==0){
      sum=a;
      sum+=(b-a)*((k-a+1)/2);
    }
    else{
      sum=a;
      sum+=(b-a)*((k-a+1)/2);
      sum++;
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]

k = I()
s = S()
if len(s) <= k:
    print(s)
else:
    print(s[:k] +'...')


Measured memory_bytes: 27164
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 200005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

ll id[N], size[N];
int root(int x)
{
	while(id[x] != x)
	{
		id[x] = id[id[x]];
		x = id[x];
	}
	return x;
}
int union1(int x, int y)
{
	int p = root(x);
	int q = root(y);
	int val = size[p] * size[q];
	size[q] = size[p] + size[q];
	id[p] = q;
	return val;
}
int main()
{
	vector <pair<int, int> > edge;
	vector <ll>  res;
	ll n, m, x, y;
	ll ans = 0, val;
	cin >> n >> m;
	for (int i = 0; i <= n; ++i)
	{
		id[i] = i;
		size[i] = 1;
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> x >> y;
		edge.push_back({x, y});
	}
	reverse(all(edge));
	ans = (n * (n - 1)) / 2;
	for (int i = 0; i < m; ++i)
	{
		res.push_back(ans);
		if(root(edge[i].ff) != root(edge[i].ss))
		{
			val = union1(edge[i].ff, edge[i].ss);
		}
		else
		{
			val = 0;
		}
		ans = ans - val;	
	}
	reverse(all(res));
	for (auto g : res)
		cout << g << "\n";
}


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

int n, q;
int A[20];

bool solve(int i, int m) {
  if (m == 0) return true;
  if (i >= n) return false;
  return solve(i + 1, m - A[i]) || solve(i + 1, m);
}

int main(void){
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    int m;
    cin >> m;
    if (solve(0, m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
string s,t; 
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	    if(s[i]!=t[i]) {cout<<"No";return 0;}
	cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main ()
{
	int x, y;
	while (1){
	cin >> x >> y;
	if ( x == 0 && y == 0 ) break;
	if ( x < y )
		cout << x << " " << y << endl;
	else 
		cout << y << " " << x << endl;
}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}

int main() {
int a,b;
cin>>a>>b;
string s = string(a,b+'0');
string s2 = string(b,a+'0');
cout<<(lexicographical_compare(all(s),all(s2)) ? s : s2)<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define _  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define int long long
#define MOD 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 100 + 5;
const ll inf = 1e18;
using namespace std;

template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T>
void print_container(T &container) {for (auto &t : container) {cout << t << " ";} cout << endl;}
//Pain is temporary Glory is forever!!
//Think quick,Code Fast!!
//Refer https://atcoder.jp/contests/dp/submissions/10848260
int n, w;
pair<int, int> a[N];

void solve() {
	cin >> n >> w;

	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}

	//Stores the maximum profit possible for the given values
	int sum_value = 0;
	for (int i = 0; i < n; i++) {
		sum_value += a[i].second;
	}

	//dp[j] --> Minimun weight in which we can have a profit of j
	vector<int> dp(sum_value + 1, inf);
	dp[0] = 0;// Profit of 0 can be achieved with a weight of 0 !!



	for (int i = 0; i < n; i++) {
		for (int j = sum_value - a[i].second; j >= 0; j--) {
			dp[j + a[i].second] = min(dp[j + a[i].second], dp[j] + a[i].first);
		}
	}

	int ans = 0;
	for (int i = 0; i <= sum_value; i++) {
		// cout << dp[i] << " ";
		if (dp[i] <= w) {
			ans = max(ans, i);
		}
	}

	cout << ans << endl;

}

int32_t main() {
	_

	solve();
}



Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        long sum1 = 0, sum2 = 0;
        long cost1 = 0, cost2 = 0;
        long sign1 = 1, sign2 = -1;
        for (int i = 0; i < n; i++) {
            final long a = scanner.nextLong();
            sum1 += a;
            sum2 += a;

            if (sign1 == 1 && sum1 < 1) {
                cost1 += 1 - sum1;
                sum1 = 1;
            } else if (sign1 == -1 && sum1 > -1) {
                cost1 += sum1 + 1;
                sum1 = -1;
            }

            if (sign2 == 1 && sum2 < 1) {
                cost2 += 1 - sum2;
                sum2 = 1;
            } else if (sign2 == -1 && sum2 > -1) {
                cost2 += sum2 + 1;
                sum2 = -1;
            }

            sign1 *= -1;
            sign2 *= -1;
        }

        System.out.println(Math.min(cost1, cost2));
    }
}


Measured memory_bytes: 48912
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
    int n, ji = 0, b4 = 0;
    cin >> n;
    ll t;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        if (t & 1) ji++;
        if (t % 4 == 0) b4++;
    }
    if ((!(n & 1) && b4 >= ji) || ((n & 1) && b4 + 1 >= ji)) cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
war = [[int(i)-1 for i in input().split()] for _ in range(m)]
war.sort(key=lambda x:x[1])
rm = -1
ans = 0
for i in range(m):
    a,b = war[i]
    if a <= rm: continue
    else:
        ans += 1
        rm = b-1
print(ans)

Measured memory_bytes: 22820
#include <stdio.h>
int main(void){
 int w,a,b;
 scanf("%d%d%d",&w,&a,&b);
 if(b>=a&&b<=a+w||b+w>=a&&b+w<=a+w) puts("0");
 else{
  if(a<b) printf("%d",b-a-w);
  else printf("%d",a-b-w);
 }
 return 0;
}

Measured memory_bytes: 128
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;

int N, M, a[MAX], nope[MAX], u, v, ans;

int main()
{
    optimiza_io
    cin >> N >> M;
    for( int i = 1; i <= N; i ++ ) 
        cin >> a[i];
    while( M -- ) {
        int u, v;
        cin >> u >> v;
        if( a[u] >= a[v] ) nope[v] = 1;
        if( a[v] >= a[u] ) nope[u] = 1;
    }
    
    for( int i = 1; i <= N; i ++ )
        ans += nope[i] == 0;
    
    cout << ans;
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  for(int i = 1; i < S.size() / 2; i++) {
    if (S.compare(0,(S.size()- 2 * i) / 2, S.substr((S.size()- 2 * i)/ 2, (S.size()- 2 * i) / 2)) == 0) {
      cout << S.size()- 2 * i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
ans='1' + '0'*(N-1) if N>1 else '0'
chk=[False]*N

for m in range(M):
  s, c = input().split()
  s=int(s)
  if s==1 and c=='0' and N>1:
    print(-1); exit(0)
  if chk[s-1] and c!=ans[s-1]:
    print(-1); exit(0)
  chk[s-1]=True
  ans = ans[:s-1] + c + ans[s:]
  #print(chk, ans)
print(ans)

Measured memory_bytes: 9064
import java.util.*;

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

    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double c = sc.nextDouble();
    double d = sc.nextDouble();
    String ans;

    if(Math.ceil(a / d) < Math.ceil(c / b)){
      ans = "No";
    } else {
      ans = "Yes";
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 37384