akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll solve(ll num, ll x)
{
  if (num == -1)
  {
    return 0;
  }

  return num / x + 1;
}

int main(void)
{
  ll a, b, x;
  cin >> a >> b >> x;

  ll result = solve(b, x) - solve(a - 1, x);

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
x,y = [int(it) for it in input().split()]

s = 1000000001

ds = y-x
if (ds>=0):
  s = min(s,ds)
ds = y+x
if (ds>=0):
  s = min(s,1+ds)
ds = -y-x
if (ds>=0):
  s = min(s,1+ds)
ds = -y+x
if (ds>=0):
  s = min(s,2+ds)
print (s)
  


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define swap(a,b) ((a != b) && (a += b,b = a - b,a -= b))
using namespace std;

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}

int main()
{
    int n;
    cin >> n;
    vector<int> v(n,0);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }

    int sum=accumulate(v.begin(), v.end(), 0);
    if(sum%10){
            cout << sum << endl;
            return 0;
        }


    sort(v.begin(), v.end());

    for(int i=0;i<v.size();i++){
        if(v[i]%10){
            cout << sum-v[i] << endl;
            return 0;
        }
    }

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






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int N; cin>>N;
  vector<int> P(N), Q(N);
  for(int i=0; i<N; i++){
    cin>>P[i];
  }
  for(int i=0; i<N; i++){
    cin>>Q[i];
  }
  vector<int> test(N);
  for(int i=0; i<N; i++){
    test[i]=i+1;
  }
  int p,q,ans;
  int count=1;
  do{
    if(P==test){
      p=count;
    }
    if(Q==test){
      q=count;
    }
    count++;
  }while(next_permutation(test.begin(), test.end()));
  ans=max(p-q, q-p);
  cout<<ans<<endl;
}

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

int main() {
  int N,A,I;
  cin >> N >>A;
  I = N % 500 - A;
  if(I <= 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

// input
int N, W;
int w[110];
ll  v[110];

// dp[i][j]: i番目までの品物から像重量がjを越えないように選んだ時の合計価値の最大値
ll dp[110][100010];

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    // 初期化
    for (int j = 0; j <= W; j++) dp[0][j] = 0;

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

    cout << dp[N][W] << endl;
    
    return 0;
}

Measured memory_bytes: 80128
S = raw_input().split()

maxi = 0
for s in S:
    length = len(s)
    if (length > maxi):
        maxi = length
        maxs = s

S.sort()
i = 0
maxm = 0
mode = 0
while (i < len(S) - 1):
    cnt = 1
    while True:
        if (S[i] == S[i + 1]):
            i += 1
            cnt += 1
            if (i >= len(S) - 1):
                break
        else:
            break
        
    if (cnt > maxm):
        maxm = cnt
        mode = i
        
    i += 1
        
print S[mode], maxs

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

class Problem{
public:
  int solve(int x, string s){
    int u = 0;
    for(int i = 0; i < x; ++i){
      string t = s.substr(i, 3);
      if(t == "ABC")u++;
    }
    return u;
  }
};


int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  Problem B;
  cout<<B.solve(n, s)<<endl;  
  return 0;
}


Measured memory_bytes: 256
import System.IO                                                                                                                                       
import Control.Monad                                                                                                                                   
main = do                                                                                                                                              
     end <- isEOF                                                                                                                                      
     when (not end) $ do                                                                                                                               
          rs <- getLine                                                                                                                                
          print $ length . show . sum . map (read::String->Int) $ words rs
          main

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

bool schedule[10];
vector<vector<ll>> f;
vector<vector<ll>> p;
ll ma = -1000000000;

void culc_value(){
    ll count[f.size()];
    rep(i, f.size())
        count[i] = 0;

    bool check = false;
    rep(i, 10){
        if(schedule[i] == true){
            check = true;
            rep(j, f.size()){
                if(f[j][i] == true)
                    count[j]++;
            }
        }
    }
    if(check == false)
        return;

    ll sum = 0;
    rep(i, f.size()){
        sum += p[i][count[i]];
    }
    ma = max(ma, sum);
}

void dfs(ll dp){
    if(dp == 10){
        culc_value();
        return;
    }
    schedule[dp] = false;
    dfs(dp+1);
    schedule[dp] = true;
    dfs(dp+1);
}

int main(void){
    ll n;
    cin >> n;

    rep(i, n){
        ll tmp;
        f.push_back({});
        rep(j, 10){
            cin >> tmp;
            f[i].push_back(tmp);
        }
    }
    rep(i, n){
        ll tmp;
        p.push_back({});
        rep(j, 11){
            cin >> tmp;
            p[i].push_back(tmp);
        }
    }

    dfs(0);
    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

/* prototype declaration */
long long factorial(int n);

int main(int argc, const char *argv[])
{
	int n;
	scanf("%d", &n);
	printf("%lld\n", factorial(n));	
	
	return 0;
}

long long factorial(int n)
{
	int i;
	long long ans = 1;
	
	for(i=1; i<=n; i++)
		ans *= i;
	
	return ans;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define vl vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：
// 問題文URL：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n;

vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ans;
  ll index = -1;
  for (ll i = 2; i <= n; i++) {
    if (i > sqrt(n)) {
      ans.push_back(make_pair(n, 1));
      break;
    }
    if (n % i == 0) {
      ans.push_back(make_pair(i, 0));
      index++;
    }
    while (n % i == 0) {
      n /= i;
      ans[index].second++;
    }
  }
  return ans;
}

void solve() {
  vector<pair<ll, ll>> a = primeFac(n);
  ll ans = 0;
  rep(i, a.size()) {
    ll index = a[i].second;
    ll m = 0;
    while (index >= (m + 1) * (m + 2) / 2) {
      m++;
    }
    ans += m;
    // cout << "底:" << a[i].first << " 指数:" << index << " m:" << m << endl;
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  solve();
  return 0;
}


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


void solve(long long a, std::string s){
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    std::string s;
    std::cin >> s;
    solve(a, s);
    return 0;
}


Measured memory_bytes: 256
/*
|| Suyash Yadav | B.Tech (3rd Year CSE) | Tier-3 (NCR,India)
|| suyashky@gmail.com | "suyashky" @linkedIn
||
||		   /\_/\
||		  ( o.o )
|| 	 	   > ^ <
|| To infinity and beyond!
*/

# include <bits/stdc++.h>
using namespace std;
# define INF (long long int)1e28
# define MOD 1000000007
# define all(con) con.begin() , con.end()
# define MAX numeric_limits<int64>::max()
# define MIN numeric_limits<int64>::min()
# define watch1(x) cout<<#x<<": "<<x<<endl
# define watch2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
# define watch3(x,y,z) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
# define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int64 n, d;
	cin >> n >> d;

	int64 a, b, cnt = 0;
	double temp;
	while (n--)
	{
		cin >> a >> b;
		temp = a * a + b * b;
		temp = sqrt(temp);
		if (temp <= d)
			cnt++;
	}
	cout << cnt;
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long A, long long B, long long C) {
    auto money = B;
    auto ans = 0;
    loop (i, 1, 10000) {
        if (A <= money) {
            money -= A;
            ans++;
            if (ans == C) {
                break;
            }
        } else {
            break;
        }
    }
    cout << ans << endl;
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 3756
#include <stdio.h>

void disp(int a[],int n)
{
	int i=0;
	for(i=0;i<n;i++)
	{
		if(i>0) printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
}
//插入排序法！
void sort(int a[],int n)
{
	int v,i,j;
	for(i=1;i<n;i++)
	{
		v=a[i];
		j=i-1;
		while(j>=0&&a[j]>v)
		{
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		disp(a,n);
	}
}

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


Measured memory_bytes: 2712
// E - Sum of gcd of Tuples (Hard)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
// a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
ll modpow(ll a,ll n){return n?modpow(a*a%MOD,n/2)*(n%2?a:1)%MOD:1;}

ll cnt[100001]; // [gcd:[1,K]] gcd 毎の個数

int main(){
	int N,K; cin>>N>>K;
	ll ans = 0;
	for(int g=K; g>=1; --g){ // g: gcd を固定
		ll c = modpow(K/g, N); // g の倍数の個数
		for(int n=2; n*g<=K; ++n) c -= cnt[n*g]; // g*1 以外を除去
		ans = (ans + (c * g % MOD)) % MOD;
		cnt[g] = c;
	}
	cout<< (ans+MOD)%MOD <<endl; // 負数の修正
}

Measured memory_bytes: 4428
import java.util.*;
import static java.lang.Math.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for(int i=0; i<n; i++){
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        int min = Integer.MAX_VALUE;
        for(int i=0; i+k-1<n; i++){
            min = min(min,h[i+k-1] - h[i]);
        }
        System.out.println(min);
        
    }
}

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

string s;
int K;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s >> K;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a') continue;
    int cost = ('z' - s[i]) + 1;
    if (K >= cost) {
      K -= cost;
      s[i] = 'a';
    }
  }  
  s.back() = char(((s.back() - 'a') + K) % 26 + 'a');
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 592
import java.util.*;

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

        List<Store> storeList = new ArrayList<>();
        for (int i = 0; i < n; i++){
            long price = sc.nextLong();
            long amount = sc.nextLong();
            Store store = new Store(price, amount);
            storeList.add(store);
        }

        storeList.sort(Comparator.comparingLong(a -> a.price));

        long money = 0L;
        int drinkAmount = 0;
        for (Store store : storeList){
            if (drinkAmount + store.amount >= m){
                money += store.price * (m - drinkAmount);
                break;
            }
            money += store.price * store.amount;
            drinkAmount += store.amount;
        }

        System.out.println(money);
    }

    static class Store{
        long price;
        long amount;
        public Store(long p, long a){
            price = p;
            amount = a;
        }
    }

}

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

int main()
{
    int n;
    int a;
    int i;
    int flag=0;
    while(scanf("%d",&n)==1)
    {
        flag=0;
        for(i=1;;i++)
        {
            if(i*4>n)
            {
                flag=0;
                break;
            }
            if(i*4==n)
            {
                flag=1;
                break;
            }
            a=n-i*4;
            if(a%7==0 || n%7==0)
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int l = 0, r = sz(s) - 1;
  int res = 0;
  while (l < r) {
    if (s[l] == s[r]) l++, r--;
    else if (s[l] == 'x') l++, res++;
    else if (s[r] == 'x') r--, res++;
    else {
      cout << -1 << endl;
      return 0;
    }
  }  
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s;
    cin >> s;
    ll n = atoi(s.c_str());
    ll sn = 0;
    rep(i, 0, s.size()){
        sn += (ll)(s[i]-'0');
    }
    if(n%sn == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#include<unordered_map>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define all(x) (x).begin(),(x).end()
#define INF 0x3f3f3f3f3f3f3
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}
#define deb1(a) cout<<(a)<<endl;
#define deb2(a,b) cout<<(a)<<" "<<(b)<<endl;
#define deb3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
#define RAND(x,y) ((x) + (rand()%(y-x+1)))

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 1e9+7;

ll nop = 2;
vi primes(nop,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}


bool isVowel(char ch) { ch = tolower(ch);return (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'); }

ll gcd(ll a,ll b){    //a larger, b smaller
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans *num)%mod;
        }
        num = (num*num)%mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    return mexp(a,mod-2);
}

void solve() {
    int n;
    cin>>n;
    deb1(n+n*n+n*n*n);

}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        //cout<<"Case #"<<T<<": ";
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


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

int a, b, c;

void solve()
{
	int musiccount = b / a;
	if (musiccount > c)
	{
		cout << c << endl;
	}
	else cout << musiccount << endl;
}

int main()
{

	cin >> a >> b >> c;
	solve();
	return 0;



}

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

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> P(N);
  for(int i=0;i<N;i++){
    cin >> P[i].first;
    P[i].second = i+1;
  }
  sort(P.begin(),P.end());
  
  for(int j=0;j<N;j++){
    cout << P[j].second << ' ';
  }
 
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll mp[111111];
ll s[111111];
ll n, ans;

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

	cin >> n;
	REP(i, n)cin >> s[i];
	for(ll i = 1;i < n/2;i++){
		ll l = 0;
		ll r = n - 1;
		ll now = 0;
		while(1){
			l += i;
			r -= i;
			if(l > n - 1 || mp[l] == i)break;
			if(r < i || mp[r] == i)break;
			if(l == r)break;
			now += s[l];
			mp[l] = i;
			now += s[r];
			mp[r] = i;
			ans = max(ans, now);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>

using namespace std;

int j;
long long f[50][500];

void h(long long a, long long b, long long c, int i){
  int k,l;
  for (k=b+1;k<a-b+1;++k) {
    if (a%k==b) {
      ++j;
      long long p=pow(2,k);
      f[i][j]=c+p;
      f[i][0]=j;
      //cout << i << " " << j << " " << pow(2,k)+c << endl;
    } else {
      l=1;
      long long p=pow(2,k);
      while (b+k*l<a) {
        h(a, b+k*l, c+p, i);
        l++;
      }
    }
  }
}

int main(){
  int N,i,k,l;
  cin >> N;
  long long a[N],b[N],C=0,S=0;
  for (i=0;i<N;++i) {
    cin >> a[i];
    for (j=0;j<500;++j) {
      f[i][j]=0;
    }
  }
  for (i=0;i<N;++i) {
    cin >> b[i];
    if (a[i] < b[i]) {
      cout << -1 << endl;
      return 0;
    }
    j=0;
    h(a[i], b[i], 0, i);
    if (j==0 && a[i]!=b[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int fl[51];
  for (j=0;j<51;++j) {
    fl[j]=0;
  }
  int minj[N];
  int maxi;

  for (k=0;k<N;++k) {
    for (i=0;i<N;++i) {
      minj[i]=1;
      for (j=2;j<1+f[i][0];++j){
        if (f[i][minj[i]]>f[i][j]) minj[i]=j;
      }
    }
    maxi=0;
    for (i=1;i<N;++i) {
      if (f[maxi][minj[maxi]]<f[i][minj[i]]) maxi=i;
    }
    //cout << f[maxi][minj[maxi]] << endl;
    S+=f[maxi][minj[maxi]];
    l=0;
    while (f[maxi][minj[maxi]]>0){
      if (f[maxi][minj[maxi]]%2==1) {
        fl[l]=1;
        for (i=0;i<N;++i) {
          for (j=1;j<1+f[i][0];++j){
            long long p=pow(2,l);
            if ((f[i][j]/ p)%2==1) f[i][j]-=p;
          }
        }
      }
      f[maxi][minj[maxi]]/=2;
      ++l;
    }
    for (j=1;j<1+f[maxi][0];++j){
      f[maxi][j]=0;
    }
  }
  if (S==0){
    for(i=0;i<N;++i) {
      if (a[i]!=b[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << S << endl;
  return 0;
}


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

int main(){
	string S;
	int i;
	vector<int> count(26, 0);
	cin >> S;
	for(i = 0; i < S.size(); i++){
		count[S[i] - 'a']++;
	}
	for(i = 0; i < 26; i++){
		if(count[i] == 0){
			printf("%c\n", 'a' + i);
			return 0;
		}
	}
	printf("None\n");
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Y;
    cin >> N >> Y;
    Y /= 1000;
    REP(i, N + 1) {
        REP(j, N - i + 1) {
            if (9 * i + 4 * j == Y - N) {
                cout << i << " " << j << " " << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map> 
using namespace std;
map<int,int>m;
int n,a,sum;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a);
		m[a]++;
	}
	for(map<int,int>::iterator it=m.begin();it!=m.end();++it){
		if(it->first>it->second){
			sum+=it->second;
		}else{
			sum+=it->second-it->first;
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 7692
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<vector<int>> memo;
int N,S;
void dfs(int sum,int depth,int flag){
	if(depth==10) return;
	for(int i=0;i<10;i++){
		if(!(flag&(1<<i))){
			memo[depth][sum+(depth+1)*i]++;
			dfs(sum+(depth+1)*i,depth+1,flag|(1<<i));
		}
	}
}

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

	memo.resize(10,vector<int>(331,0));
	dfs(0,0,0);

	while(cin>>N){
		S=in();
		if(S>330) out(0);
		else out(memo[N-1][S]);
	}
	return 0;
}


Measured memory_bytes: 3172
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        mut a: [i64; 5],
        k: i64,
    }
    a.sort();

    let ans = if a[4] - a[0] > k { ":(" } else { "Yay!" };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cmath>
long long a, b, n;
long long f(long long x) {
	return (long long)(floor(a * x / b) - a * floor(x / b));
}
int main() {
	scanf("%lld%lld%lld", &a, &b, &n);
	if (b - 1 <= n) printf("%lld", f(b - 1));
	else printf("%lld", f(n));
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
string N;
int a,z;
bool aa,zz;
int main()
{
    cin>>N;
    for(int i=0;i<N.size();i++)
    {
		if(N[i]=='A'){a=i;break;}
	}
    for(int i=a;i<N.size();i++)
    {
		if(N[i]=='Z')z=i;
	}
	
    cout<<z-a+1<<endl;
    return 0;
}

Measured memory_bytes: 640
h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for i in range(h):
  for j in range(w):
    if a[i][j]==-1:
      continue
    ans+=c[a[i][j]][1]
print(ans)

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

int main() {
  string N;
  cin >> N;
  if(N.at(0)=='7'||N.at(1)=='7'||N.at(2)=='7'){
      cout <<"Yes"<< endl;
  }

else{
  cout <<"No"<< endl;
}
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,A,B,x=0,y=0,z=0;
	cin>>n>>A>>B;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<=A)
			x++;
		else if(a[i]>=A+1&&a[i]<=B)
			y++;
		else
			z++;
	}
	cout<<min(min(x,y),z);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define rrep(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define lli long long int
#define vi vector<int> 

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}

int main() {
	char mode = 'a';
	string sa, sb, sc;
	cin >> sa >> sb >> sc;

	while (1) {
		if (mode == 'a') {
			if (sa.empty()) {
				cout << "A" << endl;
				break;
			}
			else {
				mode = *(sa.begin());
				sa.erase(sa.begin());

			}
		}

		else if (mode == 'b') {
			if (sb.empty()) {
				cout << "B" << endl;
				break;
			}
			else {
				mode = *(sb.begin());
				sb.erase(sb.begin());
			}
		}

		else if (mode == 'c') {
			if (sc.empty()) {
				cout << "C" << endl;
				break;
			}
			else {
				mode = *(sc.begin());
				sc.erase(sc.begin());

			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
/*A*/
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

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

	int N;
	cin >> N;
	
	while (1) {
		if (N < 1000) break;
		N -= 1000;
	}

	if (N == 0) cout << N << endl;
	else cout << 1000 - N << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    string s;
    cin >> s;
    ll ans = 0;
    ll mofu = 0;
    for (ll i = 0;i<s.length();i++){
        if (s[i] == 'B'){
            mofu += 1;
        }else{
            ans += mofu;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
K=str(input())
if (int(K[0])%7==0 and int(K[0])!=0 )or (int(K[1])%7==0 and int(K[1])!=0 ) or (int(K[2])%7==0 and int(K[2])!=0 ):
    print('Yes')
else:
    print('No')

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

int a[1000010], sum[1000010];

int main(void){
    int N;
    string S;
    cin >> N >> S;
    bool oneexists=false;
    for(int i=0; i<N; ++i){
        a[i]=S[i]-'1';
        oneexists=oneexists||(a[i]==1);
    }
    sum[0]=0;
    for(int i=1; i<N; ++i){
        sum[i]=sum[i-1];
        int t=i;
        while(t%2==0){
            t /= 2;
            ++sum[i];
        }
    }
    int ans=0;
    if(oneexists){
        for(int i=0; i<N; ++i){
            if(sum[N-1]==sum[i]+sum[N-1-i]){
                (ans += a[i]) %= 2;
            }
        }
    }
    else{
        for(int i=0; i<N; ++i){
            if(sum[N-1]==sum[i]+sum[N-1-i]){
                (ans += a[i]/2) %= 2;
            }
        }
        ans *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9220
import java.util.Scanner;

/**
 * @author ??\???
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		scanner.close();
		
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}

}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main(){
int a,b,c;
cin>>a>>b>>c;

for(int i=0;i<a*b+1;i++){
    if((i*a+b*a)%b==c){
        cout<<"YES"<<endl;
        return 0;
    }
}

cout<<"NO";
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);
#define MAXN 100


typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ll INF = 1e15;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
ll pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a;
	}
	ll ans = pow(a, b / 2);
	ans *= ans;
	ans *= b % 2 == 1 ? a : 1;
	return ans;
}


namespace SOLVE {
	int n, m;
	int visited[MAXN] = { 0 };
	int parent[MAXN] = { 0 };
	int adjmatrix[MAXN][MAXN] = { 0 };
	
	void bfs(int v) {
		visited[v] = 1;
		REP(i, 0, n) {
			if (!visited[i] && adjmatrix[v][i] > 0) {
				parent[i] = v;
				bfs(i);
			}
		}
	}


	void main() {
		int a, b, c;
		cin >> n >> m;


		REP(i, 0, m) {
			cin >> a >> b >> c;
			adjmatrix[a][b] = c;

		}
		int ans = 0;

		while (1) {
			memset(visited, 0, sizeof(visited));
			memset(parent, 0, sizeof(visited));
			bfs(0);
			if (!visited[n - 1]) {
				break;
			}

			int flow = 1e9;
			// go backwards, see the minimum flow
			for (int v = n - 1; v != 0; v = parent[v]) {
				flow = min(flow, adjmatrix[parent[v]][v]);
			}
			// go backwards and subtract the flow from all the edges. also add the flow to the reverse edge.
			for (int v = n - 1; v != 0; v = parent[v]) {
				adjmatrix[parent[v]][v] -= flow;
				adjmatrix[v][parent[v]] += flow;
			}
			ans += flow;
		}
		cout << ans << endl;

	
	}
}


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

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>k>>a>>b;
    ans=1;
    rep(i,k){
        if(ans>=a){
            if(k-i>=2){
            ans-=a;
            ans+=b;
            i++;
            }
            else{
                ans++;
            }
        }
        else{
            ans++;
        }
    }
    Cout(max(ans,k+1));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int l;
	scanf("%d",&l);
	int a;
	scanf("%d",&a);
	int b;
	scanf("%d",&b);
	int c;
	scanf("%d",&c);
	int d;
	scanf("%d",&d);
    int a1,b1,l1;
	a1=(a/c);
	b1=(b/d);
	if(a%c!=0){
	    a1=a1+1.0;
	}
	if(b%d!=0){
	    b1=b1+1.0;
	}
	if(a1<b1){
	    a1=b1;
	}
	l1=l-a1;
	printf("%d\n",l1);
	return 0;
}


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

int t[200000];
int main(){
	int n,k;scanf("%d%d",&n,&k);k--;
	vector<int>v;
	rep(i,n)scanf("%d",&t[i]);
	rep(i,n-1){
		v.push_back(t[i+1]-t[i]-1);
	}
	sort(v.begin(),v.end(),greater<>());
	int cnt=0;
	rep(i,k){
		cnt+=v[i];
	}
	int ans=t[n-1]-t[0]+1;
	cout<<ans-cnt<<endl;
}



Measured memory_bytes: 3944
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    result = [0 for _ in range(N)]
    for i, a in enumerate(As[::-1]):
        num = N - i
        idx = num - 1
        if N // num < 2:
            result[idx] = a
        else:
            sum_ = 0
            cnt = 2
            while True:
                if N < (num * cnt):
                    break
                sum_ += result[(num * cnt) - 1]
                cnt += 1
            if sum_ % 2 == 1:
                result[idx] = 1 if a == 0 else 0
            else:
                result[idx] = 0 if a == 0 else 1
    print(len([x for x in result if x == 1]))
    for i, x in enumerate(result):
        if x == 1:
            print(i + 1, end=' ')


if __name__ == "__main__":
    main()


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

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

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

const int sz=1e5+10;


int main()
{
    fast;
    
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
        ll n,w;
        cin>>n>>w;
        
        ll a[n][2];
        for(int i=0;i<n;i++){
			cin>>a[i][0]>>a[i][1];
		}
		ll dp[n+1][w+1];
		memset(dp,0,sizeof dp);
		dp[0][0]=0;
		for(int i=1;i<=n;i++){
			dp[i][0]=0;
			for(int j=1;j<=w;j++){
				if(j>=a[i-1][0]){
					dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i-1][0]]+a[i-1][1]);
				}else dp[i][j]=dp[i-1][j];
			}
		}
		//~ for(int i=0;i<=n;i++){
			//~ for(int j=0;j<=w;j++){
				//~ cout<<dp[i][j]<<" ";
			//~ }
			//~ cout<<endl;
		//~ }
		cout<<dp[n][w];
	}
    return 0;
}


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

using namespace std;

#define P pair<int, int>

int n,l,i,j,a[100005];
vector <int> ans;

priority_queue <P, vector <P>, greater<P> > b;

int main(){
	scanf("%d%d", &n, &l);
	
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	int ind = -1;
	for(i = 0; i < n - 1; i++){
		if(a[i] + a[i + 1] >= l)
		ind = i;
	}
	
	if(ind == -1)
	return 0 * printf("Impossible\n");
	
	for(i = 0; i < ind; i++)
	ans.push_back(i);
	for(i = n - 2; i > ind; i--)
	ans.push_back(i);
	ans.push_back(ind);
	
	printf("Possible\n");
	for(i = 0; i < ans.size(); i++)
	printf("%d\n", ans[i] + 1);
}


Measured memory_bytes: 1656
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int q = sc.nextInt();
        while(q-->0) {
            String op = sc.next();
            if(op.equals("print")) {
                int a = sc.nextInt();
                int b = sc.nextInt()+1;
                System.out.println(str.substring(a, b));
            } else if(op.equals("reverse")) {
                int a = sc.nextInt();
                int b = sc.nextInt()+1;
                str = str.substring(0, a) + new StringBuilder(str.substring(a, b)).reverse().toString() + str.substring(b);
            } else if(op.equals("replace")) {
                int a = sc.nextInt();
                int b = sc.nextInt()+1;
                String p = sc.next();
                str = str.substring(0, a) + p  + str.substring(b);
            }
        }
    }
}

Measured memory_bytes: 22512
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)
// C
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<string> s(n); rep(i,n) cin >> s[i];
    map<string,int> m;
    rep(i,n) m[s[i]]++;
    int nmax = 0;
    vector<string> ans;
    for(auto i:m){
        if(nmax < i.second){
            nmax = i.second;
            ans = vector<string>();
            ans.push_back(i.first);   
        }else if(nmax == i.second) ans.push_back(i.first);
    }
    rep(i,ans.size()) cout << ans[i] << "\n";
}

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

using namespace std;

int main(){
    int k;
    int n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int len = k - (a[n - 1] - a[0]);
    for(int i = 0; i < n - 1; i++){
        len = max(len, a[i + 1] - a[i]);
    }
    int result = k - len;
    cout << result << endl;
}

Measured memory_bytes: 1024
X=int(input())

def isPrime(n):
  if n < 2:
    # 2未満は素数でない
    return False
  if n == 2:
    # 2は素数
    return True
  for p in range(2, n):
      if n % p == 0:
        # nまでの数で割り切れたら素数ではない
        return False
  # nまでの数で割り切れなかったら素数
  return True
  
while 1==1:
    if isPrime(X)==True:
        print(X)
        quit()
    X+=1

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

using namespace std;


int main() {
    int m,f,b;
    cin >> m >> f >> b;
    if(m + f < b) {
        cout << "NA" << endl;
    } else {
        cout << max((b - m),0) << endl;
    }
}

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

using namespace std;

const int maxn = 10005;
int n, p, d, q;
typedef pair<int, int> pii;
vector<pii> G[maxn];
typedef long long ll;

int main()
{
    int y,m,d;
    scanf("%4d/%2d/%2d",&y,&m,&d);
    if (y >= 2019 && m > 4)
        printf("TBD\n");
    else
        printf("Heisei\n");
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int cnt[4];

signed main()
{
    REP(i,3){
        int a,b; cin>>a>>b;
        a--; b--;
        cnt[a]++; cnt[b]++;
    }
    
    int c=0;
    REP(i,4){
        if(cnt[i]%2==1) c++;
    }
    
    if(c>2)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
 
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
     Scanner sc = new Scanner(System.in);
     int n = 0;
     if(sc.hasNextInt())
            n = sc.nextInt();
        int[] dp = new int[n];
     for(int i = 0 ; i < n ; i++)
     {
         dp[i] = sc.nextInt();
     }
     int[] x = new int[n];
     Arrays.fill(x,Integer.MAX_VALUE);
     x[0] = 0;
     for(int i = 0 ; i < n ; i++)
     {
         for(int j = i+1 ; j < i+3 ; j++)
         {
             if(j < n)
             {
                 x[j] = Math.min(x[j] , x[i]+Math.abs(dp[i]- dp[j]));
             }
         }
     }
     System.out.println(x[n-1]);


    }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n;cin>>n;
	vi b(n),ans;
	rep(i,n)cin>>b[i];
	while(b.size()>0){
		bool a=false;
		for(int i=b.size()-1;i>=0;--i){
			if(b[i]==i+1){
				ans.PB(b[i]);
				b.erase(b.begin()+i,b.begin()+i+1);
				a=true;
				break;
			}
		}
		if(!a){
			cout<<-1<<endl;
			return 0;
		}
	}
    reverse(all(ans));
	rep(i,n){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 256
"""
- https://atcoder.jp/contests/abc131/tasks/abc131_b
- 最もおいしさの絶対値の小さいりんごを食べるのが、最適
"""
base = 0
n, l = map(int, input().split())
eat = min([abs(i+l-1) for i in range(1, n+1)])
for i in range(1, n+1):
    base+=(i+l-1)
    pie = base-eat if l>=0 else base+eat
print(pie)


Measured memory_bytes: 3060
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import numpy as np

d = ni()
c = na()
s = []

for i in range(d):
    ss = na()
    s.append(ss)

c = np.array(c) # 満足度の下がりやすさ
s = np.array(s) # i日目jコン
s_t = s.T # iコンj日目
last = np.zeros(26)

# 評価関数
# 得になった分+その日の満足度
# n: 日数, 
def eva(n, cc, ss):
    return (d-n)*cc + 1*ss

score = 0

for i in range(d): # i日目(0-indexed)
    last += 1 # 一日分追加
    tow = c * last # 満足下がる値 
    sc = -100000
    M = -1
    for j in range(26):
        k = eva(i, tow[j], s[i][j])
        if sc < k:
            sc = k
            M = j
    last[M] = 0
    score -= np.dot(c,last)
    score += s[i][M]
    print(M+1)



Measured memory_bytes: 27272