akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n,m;
    cin >> n >> m;
    int x[m+1] = {};

    ll ans = 0;
    rep(i,n){
        int k;
        cin >> k;
        rep(i,k){
            int a;
            cin >> a;
            x[a]++;
        }
    }
    rep(i,m+1){
        if(x[i]==n)ans++;
    }

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


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

typedef long long int ll;

int main(){
	string s; cin>>s;
	bool bad = false;
	for(int i=0;i<(int)s.size()-1;i++){
		if(s[i] == s[i+1]){
			bad = true;
		}
	}
	printf("%s",bad ? "Bad" : "Good");
}


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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
     string s;cin >> s;
     int size = s.size();
     int n = atoi(s.c_str());
    int ans = 0;
    if(size==6){
            ans = 90909;
    }else if(size==5){
            ans = 909 + n - 9999;
    }else if(size == 4){
            ans = 909;
    }else if(size == 3){
            ans = 9 + n -99;
    }else if(size == 2){
            ans = 9;
    }else{
          ans = n;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import sys
if __name__ == "__main__":
    n = int(input())
    if n == 0 or n == 1:
        print(1)
        sys.exit(0)
    dp = [0] * (n + 1)
    dp[0] = 1
    dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = dp[i - 1] + dp[i - 2]
    print(dp[n])


Measured memory_bytes: 5604
<?php
$sum = 0;
$amax = 0;
for ($i = 1; $i <= 5; $i++) {
    $s[$i] = trim(fgets(STDIN));
    $sum += (int)(($s[$i]+9)/10)*10;
    if ($s[$i]%10 != 0) {
	  $amax = max($amax, 10 - ($s[$i]%10));
    }    
}
echo $sum - $amax;


Measured memory_bytes: 4856
from sys import stdin

N, M = map(int, stdin.readline().split())
ab = [list(map(int, stdin.readline().split())) for _ in range(M)]

ab.sort()

inf = 10 ** 9

left = -inf
right = inf

ans = 1

for a, b in ab:
    if left <= a and a < right:
        left = a
        if left < b and b <= right:
            right = b
    elif left < b and b <= right:
        right = b
    else:
        ans += 1
        left = a
        right = b

if M == 0:
    print(0)
else:
    print(ans)


Measured memory_bytes: 56540
import java.io.*;
import java.util.ArrayList;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        ArrayList<Integer> x_list = new ArrayList<>();
        ArrayList<Integer> y_list = new ArrayList<>();
 
        int x;
        int y;
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        do {
            String[] line = br.readLine().split(" ");
            x = Integer.parseInt(line[0]);
            y = Integer.parseInt(line[1]);
 
            if (x == 0 && y == 0) {
                break;
            }
 
            x_list.add(x);
            y_list.add(y);
 
        } while (x != 0 || y != 0);
 
        for (int i = 0; i < x_list.size(); i++) {
            if (x_list.get(i) > y_list.get(i)) {
                System.out.println(y_list.get(i) + " " + x_list.get(i));
            } else {
                System.out.println(x_list.get(i) + " " + y_list.get(i));
            }
        }
 
    }
 
}

Measured memory_bytes: 27688
S = gets.chomp
N = S.size
 
OI = N.times.map { |i| (i % 2).to_s }.join
 
match_cnt = 0
unmatch_cnt = 0
S.size.times do |i|
  if S[i] == OI[i]
    match_cnt += 1
  else
    unmatch_cnt += 1
  end
end
 
puts [match_cnt, unmatch_cnt].min

Measured memory_bytes: 9596
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll w, h, x, y; cin >> w >> h >> x >> y;

    cout << fixed << setprecision(10) << (double)(w*h)/2 << " ";
    cout << ((double)x==(double)w/2&&(double)y==(double)h/2) << endl;
    
}

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

#define NIL -1
#define MAX 100000

// left-child, right-sibling representation
class node{
public:
  int parent;
  int left;
  int right;
  int depth;

  node(){
    parent = NIL;
    left = NIL;
    right = NIL;
    depth = NIL;
  }
};

node T[MAX];

void setDepth(int id, int d){
  T[id].depth = d;
  if(T[id].left != NIL) setDepth(T[id].left, d+1);
  if(T[id].right != NIL) setDepth(T[id].right, d);
}

int main(){

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

  for(int i=0; i<n; i++){
    int id, k;
    scanf("%d %d",&id,&k);

    // Save info to Tree
    for(int j=0; j<k; j++){
      int c; int prev_c;
      scanf("%d",&c);
      if(j==0) T[id].left = c;
      else T[prev_c].right = c;
      T[c].parent = id;
      prev_c = c;
    }
  }

  // Find root id.
  int root;
  for(int i=0; i<n; i++){
    if(T[i].parent == NIL){
      root = i;
      break;
    }
  }

  // Calculate depth recurrently
  setDepth(root, 0);

  //print result
  for(int i=0; i<n; i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,T[i].depth);

    if(T[i].parent == NIL){
      printf("root, ");
    }
    else if(T[i].left != NIL){
      printf("internal node, ");
    }
    else{
      printf("leaf, ");
    }

    printf("[");
    for(int j=0, c = T[i].left; c != NIL; j++, c = T[c].right){
      if(j != 0) printf(", ");
      printf("%d",c);
    }
    printf("]\n");
  }

  return 0;
}



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    string s;
    cin >> s;
    char a = 'a';
    sort(all(s));
    int n = s.size();
    bool flg= true;
    if(s[0] != 'a'){
        cout << 'a' << '\n';
        return 0;
    }   
    for(int i=0;i<26;i++){
        if(!binary_search(all(s),a)){
            cout << a << '\n';
            return 0;
        }
        a = (int)a + 1;
    }   
    cout << "None" << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

bool notprime[100010];
int likecount[100010];

int main() {
    int max = 100000;
    notprime[1] = true;
    for (int i = 2; i <= max; i++) {
        if (!notprime[i]) {
            for (int j = i * 2; j <= max; j += i) {
                notprime[j] = true;
            }
        }
    }
    for (int i = 1; i < max; i += 2) {
        if (notprime[i] || notprime[(i + 1) / 2]) {
            likecount[i] = likecount[i - 2];
        } else {
            likecount[i] = likecount[i - 2] + 1;
        }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << likecount[r] - likecount[l - 2] << endl;
    }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    
    int maxH = 0;
    int c = 0;
    rep (i, n) {
        if (maxH <= h[i]) {
c++;
        }
        maxH = max(maxH, h[i]);
    }
    put(c)
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, a, x=0;
    cin>>n;
    int v[n];
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    sort(v, v+n);
    a=v[0];
    while(x<a){
        if(x!=0)
            a=x;
        for(int i=0; i<n; i++){
            if(v[i]==a){
                continue;
            }
            else
                v[i]=v[i]%a;
        }
        sort(v, v+n);
        for(int i=0; i<n; i++){
            if(v[i]!=0){
                x=v[i];
                break;
            }
        }

    }
    cout<<x;

    return 0;
}


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

int main(){
  ll n, k;
  cin >> n >> k;
  ll a, b;
  vector<ll> v(1e5+1,0);
  rep(i,n) {
    cin >> a >> b;
    v[a] += b;
  }
  ll c = 0;
  rep(i,1e5+1) {
    c += v[i];
    if(c >= k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    
    if (n % 2 == 0){
        for (int i = n; i >=2; i-=2) cout << a[i] << " ";
        for (int i = 1; i <= n-3; i+= 2) cout << a[i] << " ";
        cout << a[n-1] << endl;
    }
    else {
        for (int i = n; i >=1; i-=2) cout << a[i] << " ";
        for (int i = 2; i <= n-3; i+= 2) cout << a[i] << " ";
       if (n >= 3) cout << a[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 4056
H,W = [int(i) for i in input().split()]
ans = H * W

for x in range(1,W):
    y1 = H // 2
    Sa1 = H * x
    Sb1 = (W - x) * y1
    Sc1 = (W - x) * (H - y1)
    M = max(Sa1,Sb1,Sc1)
    m = min(Sa1,Sb1,Sc1)

    y2 = (W - x) // 2
    Sa2 = H * x
    Sb2 = H * y2
    Sc2 = H * (W - x - y2)
    M2 = max(Sa2,Sb2,Sc2)
    m2 = min(Sa2,Sb2,Sc2)

    if ans > min(M-m,M2-m2):
        ans = min(M-m,M2-m2)

H,W = W,H
for x in range(1,W):
    y = H // 2
    Sa1 = H * x
    Sb1 = (W - x) * y
    Sc1 = (W - x) * (H - y)
    M = max(Sa1,Sb1,Sc1)
    m = min(Sa1,Sb1,Sc1)

    y2 = (W - x) // 2
    Sa2 = H * x
    Sb2 = H * y2
    Sc2 = H * (W - x - y2)
    M2 = max(Sa2,Sb2,Sc2)
    m2 = min(Sa2,Sb2,Sc2)

    if ans > min(M-m,M2-m2):
        ans = min(M-m,M2-m2)

print(ans)


Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main() {
	int N = 0;
	cin >> N;
	string in[N];
	string out[N];
	for(int i = 0; i < N; ++i){
		cin >> in[i];
		out[i] = in[i];
	}
	// Bubble Sort
	for(int i = 0; i < N; ++i){
		for(int j = N - 1; j > i; --j){
			if(out[j].at(1) < out[j - 1].at(1)){
				string str = out[j];
				out[j] = out[j - 1];
				out[j - 1] = str;
			} 
		}
	}
	for(int i = 0; i < N; ++i){
		if(i != N - 1) cout << out[i] << " ";
		else cout << out[i] << endl;
	}
	cout << "Stable" << endl;
	
	// Selection Sort
	for(int i = 0; i < N; ++i){
		int minj = i;
		for(int j = i; j < N; ++j){
			if(in[j].at(1) < in[minj].at(1)){
				minj = j;
			}
		}
		string s = in[i];
		in[i] = in[minj];
		in[minj] = s;
	}
	for(int i = 0; i < N; ++i){
		if(i != N - 1) cout << in[i] << " ";
		else cout << in[i] << endl;
	}
	for(int i = 0; i < N; ++i){
		if(in[i] != out[i]){
			cout << "Not stable" << endl;
			return 0;
		}
	}
	cout << "Stable" << endl;
	
	return 0;
}

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

typedef long long lint;
typedef long double louble;

#define so(a) ((int)((a).size()))

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 11;
const int biao [] = { 0,1,2,4,7,12,20,29,38,52,73 };

int n;
lint dis[_][_]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();

	lint now=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<i;j++)
			dis[i][j]=dis[j][i]=(now+1)*biao[j];
		now=now-dis[i-1][i-2]+dis[i][i-1]+dis[i][i-2];
	}

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cout<<dis[i][j]<<" \n"[j==n];

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<map>
#include<stack>
const int maxn = 1e5+10;
#define INF 1e9+10
using namespace std;
int main()
{
    string s;
    cin >> s;
    int cnt = 0, l = s.length();
    for(int i = 0; i < l; i ++)
    {
        if(s[i]=='p')cnt ++;
    }
     cout << l/2-cnt << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define xxl long long int
using namespace std;

int main(int argc, char const *argv[])
{
	xxl n;
	scanf("%lld",&n);
	xxl a[n],b[n],sum=0;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		scanf("%lld %lld",&a[i],&b[i]);
	}
	xxl temp=0;
	for (int i = n-1; i >= 0; --i)
	{
		/* code */
		a[i]+=sum;
		if(a[i]%b[i]) 
		{
			sum+=b[i]-a[i]%b[i];
		}
	}
	printf("%lld\n",sum );
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[55],k;
int main(void){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(abs(a[i])>abs(a[k])){
			k=i;
		}
	}
	if(k==0){
		k=1;
	}
	cout<<n*2-1<<endl;
	for(int i=1;i<=n;i++){
		cout<<k<<" "<<i<<endl;
		a[i]=a[i]+a[k];
	}
	if(a[k]>0){
		for(int i=1;i<n;i++){
			cout<<i<<" "<<i+1<<endl;
			a[i+1]=a[i+1]+a[i];
		}
	}else{
		for(int i=n;i>1;i--){
			cout<<i<<" "<<i-1<<endl;
			a[i-1]=a[i-1]+a[i];
		}
	}
	/*for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}*/
	
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, s string
	fmt.Scan(&n)
	for i := len(n) - 1; i >= 0; i-- {
		s += string(n[i])
	}
	if n == s {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>

ll dp[3003][3003], arr[3003];
bool mk[3003][3003];

ll solve(ll l, ll r){
    if(l>r)
        return 0;

    if(mk[l][r])
        return dp[l][r];

    mk[l][r]=true;
    ll ans=max(arr[l]-solve(l+1, r), arr[r]-solve(l, r-1));

    dp[l][r]=ans;
    return ans;
}

int main() {
    FAST
    
    ll n,la,lb;
    cin>>n;
    
    for(la=1;la<=n;la++)
        cin>>arr[la];

    ll ans=solve(1, n);
    cout<<ans<<endl;

    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int x, t;
  std::cin >> x >> t;
  print(max(x - t, (int)0));
}


Measured memory_bytes: 256
import sys
from itertools import accumulate as accum

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = list(accum((A[1:])[::-1]))[::-1]

    ans = 1
    v_count = 1
    for a, b in zip(A[:-1], B):
        if a > 0:
            if a > v_count:
                ans = -1
                break
            else:
                v_count -= a
        v_count = min(2 * v_count, b)
        ans += v_count

    if v_count != A[-1]:
        ans = -1

    print(ans)


if __name__ == "__main__":
    main()


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

char C;
bool n[10];

int main(){
    int N[4];
    cin >> N[0] >> N[1] >> N[2] >> N[3];
    REP(i,4)
    {
        n[N[i]]=true;
    }
    if(n[1] && n[9] && n[7] && n[4])cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
S = input().strip()
N = len(S)
T = input().strip()
K = len(T)
flag = 0
ind = -1
for i in range(N-K,-1,-1):
    A = list(S[i:i+K])
    flag = 0
    for j in range(K):
        if A[j]!="?" and A[j]!=T[j]:
            flag = 1
            break
    if flag == 0:
        ind = i
        break
if ind<0:
    print("UNRESTORABLE")
else:
    S = list(S)
    for j in range(K):
        if S[ind+j]=="?":
            S[ind+j] = T[j]
    for i in range(N):
        if S[i]=="?":
            S[i]="a"
    print("".join(S))

Measured memory_bytes: 62064
#include<stdio.h>
#include<string.h>
int main(){
    char a[105];
    gets(a);
    int i,l=strlen(a);
    for(i=0;i<l;i++){
        if(i%2==0){
            if(a[i]=='L'){
                printf("No\n");
                return 0;
            }
        }
        else{
            if(a[i]=='R'){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	string c;
	cin>>c;
	c[b-1]+=32;
	cout<<c<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"unicode"
)

var A, B int
var S string

func main() {
	fmt.Scanf("%d %d", &A, &B)
	fmt.Scanf("%s", &S)

	ok := true
	if len(S) != A+B+1 {
		ok = false
	} else {
		for i := 0; i < len(S); i++ {
			if i == A {
				if S[i] != '-' {
					ok = false
				}
			} else if !unicode.IsDigit([]rune(S)[i]) {
				ok = false
			}
		}
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <iostream>
 
using namespace std;
 
int n, m, ans, table[9][9];
 
int chack(){
    for(int i=0; i<n; i++){
        int tmp=0;
        for(int j=0; j<n; j++) tmp += table[i][j];
        if(tmp) return 0;
    }
    return 1;
}
 
 
void solve(int x, int y){
    if(y < n-1) y++;
    else if(x < n-1){
        y=0;
        x++;
    }else {
        ans += chack();
        return;
    }
     
    if(y==0 && 0<x){
        int tmp =0;
        for(int i=0; i<n; i++) tmp +=table[x-1][i];
        if(tmp) return;
    }   
 
    if(table[x][y] == 0 && x != y){
        table[x][y] = 1;
        table[y][x] = -1;
        solve(x, y);
 
        table[x][y] = -1;
        table[y][x] = 1;
        solve(x, y);
 
        table[x][y] = table[y][x] = 0;
    } else solve(x, y);
}
 
 
int main(void) {
    while(1) {
        cin >> n;
        if(!n) break;
        fill(table[0], table[8], 0);
        cin >> m;
        for(int i=0; i<m; i++){
            int x, y; cin >> x >> y;
            x--; y--;
            table[x][y] = 1;
            table[y][x] = -1;
        }
 
        ans = 0;
        solve(0, 0);
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
	long long N;
	cin >> N;
	vector<string>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	vector<pair<long long, string>>B;
	long long j = 0;
	B.push_back(make_pair(1, A.at(0)));
	for (long long i = 1; i < N; i++) {
		if (A.at(i) == A.at(i - 1)) B.at(j).first++;
		else {
			B.push_back(make_pair(1, A.at(i)));
			j++;
		}
	}
	sort(B.begin(), B.end(), greater<pair<long long, string>>());
	long long const MAX = B.at(0).first;
	vector<string>ans;
	for (long long i = 0; i < B.size(); i++) {
		if (B.at(i).first == MAX) ans.push_back(B.at(i).second);
	}
	sort(ans.begin(), ans.end());
	for (long long i = 0; i < ans.size(); i++) {
		cout << ans.at(i) << endl;
	}
}

Measured memory_bytes: 22384
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	int i;
	int d1, d2;
	int flg = 0;
	for (i = 0; i < n; i++)
	{
		cin >> d1 >> d2;
		if (d1 == d2)
			cnt++;
		else
			cnt = 0;
		if (cnt == 3)
			flg = 1;
	}
	if (flg == 1)
	{
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    while(K--){
        vector<int> B(N+1);
        for(int i=0; i<N; i++){
            int l = max(0, i-A[i]);
            int r = min(N-1, i+A[i]);
            B[l]++;
            B[r+1]--;
        }
        for(int i=0; i<N; i++){
            B[i+1] += B[i];
            A[i] = B[i]; 
        }
        if(*min_element(A.begin(), A.end()) == N) break;
    }

    for(int i=0; i<N; i++) cout << A[i] << " \n"[i==N-1];
    return 0;
}


Measured memory_bytes: 4844
import math
def ip():return int(input())
def inp():return map(int,input().split())
def inpstr():return map(str,input().split())
def linp():return list(map(int,input().split()))
def linpstr():return list(map(str,input().split()))

a,b,c=inp()
k=b//a
if k>c:print(c)
else:print(k)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string s;
	cin >> s;
	for(int i =0;i<s.size()-1;i++) {
		if (s[i] == s[i+1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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;

//竸プロは楽しい！！！！！！！！
//AtCoderさんいつもありがとうございます！！！！！！！！
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    vector<int> fr(n,-1),ba(n,-1);
    
    rep(i,n){
        if(i==0)fr[i]=a[i];
        else fr[i]=max<int>(fr[i-1],a[i]);
    }

    for(int i=n-1; i>=0; i--){
        if(i==n-1)ba[i]=a[i];
        else ba[i]=max<int>(ba[i+1],a[i]);
    }

    rep(i,n){
        if(i==0)cout<<ba[1]<<endl;
        else if(i==n-1)cout<<fr[n-2]<<endl;
        else cout<<max<int>(fr[i-1],ba[i+1])<<endl;
    }

}

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

typedef long long ll;

int main() {
    int H, W, K, x1, y1, x2, y2, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
    vector<string> c(H);
    rep(i, H) cin >> c[i];
    vector<vector<int>> d(H + 2, vector<int>(W + 2, 1e9));
    queue<vector<int>> q;
    q.push({x1, y1, 0});
    d[x1][y1] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int x0 = p[0], y0 = p[1], d0 = p[2];
        rep(i, 4) {
            rep(j, K) {
                int nx = x0 + dx[i] * (j + 1), ny = y0 + dy[i] * (j + 1);
                if (nx < 1 || nx > H || ny < 1 || ny > W) break;
                if (c[nx - 1][ny - 1] == '@') break;
                if (d[nx][ny] <= d[x0][y0]) break;
                if (d[nx][ny] != 1e9) continue;
                q.push({nx, ny, d0 + 1});
                d[nx][ny] = d0 + 1;
            }
        }
    }
    if (d[x2][y2] == 1e9) cout << "-1\n";
    else cout << d[x2][y2] << "\n";
}

Measured memory_bytes: 20080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll a,b,n,x;

int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> a >> b >> n;
    if(n >= b)
    {
        x = a*(b-1)/b;
    } else
    {
        x = a*n/b;
    }
    cout << x << endl;
    return 0;
}

// floor(Ax/B)-A×floor(x/B)
// floor(A{x/B})
/* when you submit
	1.n = 0 or n = 1 ?
	2.array bounds ?
	3.int overflow ?
	4.multiple test cases ?
	Keep calm  think twice and code once
*/

Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();		
        int b = sc.nextInt();
		int c = sc.nextInt();       
		System.out.println(b+Math.min(a+b+1,c));
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using P = pair<int,int>;
const int inf = 1e8;

int main() {
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        vector<vector<int>> ver(h);
        vector<vector<int>> side(h-1);
        rep(i,2*h-1) {
            if (i%2 == 0) {
                rep(j,w-1) {
                    int x;
                    cin >> x;
                    ver[i/2].push_back(x);
                }
            }
            else rep(j,w) {
                int x;
                cin >> x;
                side[i/2].push_back(x);
            }
        }
        int dis[h][w];
        rep(i,h)rep(j,w) dis[i][j] = inf;
        vector<int> dx = {1,0,-1,0};
        vector<int> dy = {0,1,0,-1};
        queue<P> q;
        q.push(P(0,0));
        dis[0][0] = 1;
        
        while (!q.empty()) {
            P v = q.front(); q.pop();
            rep(i,4) {
                int n_x = v.second + dx[i];
                int n_y = v.first + dy[i];
                if (n_x < 0 || w <= n_x || n_y < 0 || h <= n_y) continue;
                if (i == 0) {
                    if (ver[v.first][v.second] == 1) continue;
                }
                if (i == 1) {
                    if (side[v.first][v.second] == 1) continue;
                }
                if (i == 2) {
                    if (ver[v.first][v.second-1] == 1) continue;
                }
                if (i == 3) {
                    if (side[v.first-1][v.second] == 1) continue;
                }
                if (dis[n_y][n_x] == inf) {
                    dis[n_y][n_x] = dis[v.first][v.second] + 1;
                    q.push(P(n_y,n_x));
                }
            }
        }
        if (dis[h-1][w-1] == inf) cout << 0 << endl;
        else cout << dis[h-1][w-1] << endl;
    }
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)


int main() {

int N,K; cin >> N >> K ;

vector<ll> csum(N+2,0); csum[0]=0;
rep(i,N+1) csum[i+1]=csum[i]+i;

ll ans=0;

for(int i=K;i<=N+1;i++){
  ans+=(csum[N+1]-csum[N+1-i])-(csum[i]-csum[0])+1;
  ans%=1000000007;
}

cout << ans << endl;

return 0;

}

Measured memory_bytes: 4840
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <bitset>

using namespace std;
typedef long double ld;
typedef long long int ll;
void solve();


int main( void ) {

	solve();
	
	return 0;
}

void solve() {

	ll N, X;
	cin >> N >> X;
	ll M = N-X, Y = X;
	ll ans = N;

	while( M > 0 && Y > 0 ) {

		ll y, m, d;
		y = max(M, Y);
		m = min(M, Y);
		d =( (y / m )*2 )*m;
		if( y%m == 0 ) d-=m;
	
		y %= m;
		Y = y;
		M = m;
		ans += d;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
int even(int &n) {
	int count = 0;
	while (n > 0) {
		if (n % 2 == 0) {
			count++;
			n /= 2;
		}
		else {
			break;
		}
		//cout << n << endl;
	}
	return count;
}

int main() {
	int n;
	scanf("%d",& n);
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		ans += even(a);
	}
	cout << ans << endl;

}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    int a[n];
    REP(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    cout << (a[n/2]-a[n/2-1]) << endl;
    return 0;
}    

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

int main(){
    int n, m, X, Y; cin >> n >> m >> X >> Y;
    vector<int> x(n+1), y(m+1);
    x[n] = X; y[m] = Y;
    REP(i, n) cin >> x[i];
    REP(i, m) cin >> y[i];
    RSORT(x);
    SORT(y);
    cout << (x[0] >= y[0] ? "War" : "No War") << "\n";
    return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int, input().split())
dp = [[0]*(W+1) for j in range(N+1)]

for i in range(N):
    for sum_w in range(1,W+1):
        if (sum_w - w[i]) >= 0:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w - w[i]]+v[i])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]
print(dp[N][W])

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

int main() {
  int N;
  cin >> N;
  vector <int> card(N);
  for(int i; i<N; i++){
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int total;
  int Bob;
  for(int i; i<N; i++){
    total += card.at(i);
  }
  for(int i=1; i<N; i+=2){
    Bob += card.at(i);
  }
  cout << total-Bob*2 << endl;  
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,a;
  scanf("%d %d",&n,&a);
  
  int min=a;
  int max=a;
  long sum=a;
  for(int i=1;i<n;i++){
      scanf("%d",&a);
      if(a<min){
          min=a;
      }else if(a>max){
          max=a; 
      }
      sum=sum+a;
  }
  printf("%d %d %ld\n",min,max,sum);
  
return 0;
}


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

int main() {
    string s,t;
    cin >> s >> t;
    int a=s.length(), count=0;
    for (int i=0; i<a;i++){
        if (s.at(i)!=t.at(i)) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class SegTree {
public:
  int n;
  vector<T> data;
  SegTree(int m){
    n=1;
    while(n<m) n*=2;
    data.resize(2*n, 0);
  }
  T query(int l, int r){
    T ret = 0;
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1) ret += data[l++];
      if(r&1) ret += data[--r];
    }
    return ret;
  }
  void update(int k, T a){
    k+=n;
    data[k]=a;
    while(k>0){
      k = k/2;
      data[k] = data[k*2] + data[k*2+1];
    }
  }
  inline T operator[](int idx){ return data[idx+n]; }
};

deque<int> dq[26];

int main(){
  string s;
  cin>>s;
  int n = s.size();

  rep(i,n) dq[s[i]-'a'].push_back(i);
  int odd = 0;
  rep(i,26) odd += dq[i].size()%2;
  if(odd>1){
    cout << -1 << endl;
    return 0;
  }

  SegTree<int> st(n);
  long ans = 0;
  rep(i,n/2){
    int cand = -1;
    int cost = INF;
    rep(j,26) if(dq[j].size()>=2){
      int f = dq[j].front();
      int b = dq[j].back();
      int ncost = f - st.query(0,f) + (n-b-1) - st.query(b,n);
      if(ncost < cost){
        cost = ncost;
        cand = j;
      }
    }
    st.update(dq[cand].front(), 1);
    st.update(dq[cand].back(), 1);
    dq[cand].pop_back();
    dq[cand].pop_front();
    ans += cost;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) {
  v = vector<T>(n, x);
}
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
vector<lli> h;
vector<lli> c;
int main() {
  cin >> n; read_n(h, n);
  init_n(c, n, 0);
  c[1] = abs(h[1] - h[0]);
  for (lli i=2; i<n; ++i) {
    c[i] = min(c[i-2] + abs(h[i-2] - h[i]),
	c[i-1] + abs(h[i-1] - h[i]));
  }
  cout << c[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll k,a,b,f=0;
    cin>>k>>a>>b;
    for(ll i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            f=1;
            break;
        }
    }
    if(f==1)
        cout<<"OK";
    else
        cout<<"NG";
    return 0;
}

Measured memory_bytes: 3608
num = int(input())
l = ['1', '1', '1', '2', '1', '2', '1', '5', '2', '2', '1', '5', '1', '2', '1', '14', '1', '5', '1', '5', '2', '2', '1', '15', '2', '2', '5', '4', '1', '4', '1', '51']
print(l[num - 1])

Measured memory_bytes: 3060
n,p = map(int,input().split())
ai = [int(i)%2 for i in input().split()]

zero = ai.count(0)
one = ai.count(1)


# 再帰制限に引っかかった場合に外す
# import sys
# sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

tmp = 2**zero
ans = 0
for i in range(one//2+1):
    if p == 0:
        if i*2 > one:
            break
        ans += cmb(one,0+i*2)
    else:
        if i*2+1 > one:
            break
        ans += cmb(one,1+i*2)
print(int(ans*tmp))

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

int main(){
  string s;
  cin >> s;
  
  if(s[0] == s[s.size() - 1]){
    if(s.size() % 2 == 0){
      cout << "First" << endl;
      return 0;
    }else{
      cout << "Second" << endl;
      return 0;
    }
  }else{
    if(s.size() % 2 == 0){
      cout << "Second" << endl;
      return 0;
    }else{
      cout << "First" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 512
#include <stdio.h>

int AV(int a) {
	if (a < 0)
		return -a;
	else
		return a;
}

int MaxWH(int W) {
	if (W < 0)
		return 0;
	else
		return W;
}

int MinWH(int W) {
	if (W > 0)
		return 0;
	else
		return W;
}

int MaxWr(int n[5]) {
	return n[2] + n[4];
}

int MinWr(int n[5]) {
	return n[2] - n[4];
}

int MaxHr(int n[5]) {
	return n[3] + n[4];
}

int MinHr(int n[5]) {
	return n[3] - n[4];
}

int test(int n[5]) {
	if (MaxWr(n) <= MaxWH(n[0]) && MinWH(n[0]) <= MinWr(n) && MaxHr(n) <= MaxWH(n[1]) && MinWH(n[1]) <= MinHr(n))
		return 1;
	else
		return 0;
}

int main() {
	int n[5];
	for (int i = 0; i < 5; i++) {
		scanf("%d", &n[i]);
	}
	
	if (test(n) == 1)
		printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 2692