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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
/*--------------------------------------------*/

int main(){
 //cout.precision(10);
 cin.tie(0);
 ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  if(N >= 2000){
    cout << 1 << endl;
  }else{
    int a = N / 100;
    if(N <= 105 * a){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }


    

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll H, A;
  cin >> H >> A;

  cout << ((H%A==0) ? H/A : H/A+1) << "\n";
  return 0;
}


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


struct Sieve {
        int n;
        vector<int> f,primes;
        
        Sieve(int n=1):n(n),f(n+1){
                f[0] = f[1] = -1;
                for(long long i=2;i<=n;++i){
                        if(f[i]) continue;
                        primes.push_back(i);
                        f[i] = i;
                        for(long long j = i*i;j <= n;j += i) {
                                if(!f[j]) f[j] = i;
                        }
                }
        }
        
        bool isPrime(int x){return f[x] == x;}
        
        vector<int> factorList(int x){
                vector<int> res;
                while(x != 1){
                        res.push_back(f[x]);
                        x /= f[x];
                }
                return res;
        }
        
        vector<pair<int,int>> factor(int x){
                vector<int> fl = factorList(x);
                if(fl.size() == 0) return {};
                vector<pair<int,int>> res(1,pair<int,int>(fl[0],0));
                for(int p:fl){
                        if(res.back().first == p){
                                res.back().second ++;
                        }else{
                                res.emplace_back(p,1);
                        }
                }
                return res;
        }
        
};

 
int main() {
  int n;
  cin >> n;
  Sieve sieve(1005);
  map<int,int> mp;
  for(int i=1;i<=n;i++){
    auto f = sieve.factor(i);
    for(auto p:f){
      mp[p.first] = (mp[p.first]+p.second)%MOD ;
    }
  }
  ll ans = 1;
  for(auto num:mp){
    ans *= num.second+1;
    ans %= MOD;
  }
  cout << ans << endl;
    
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

    int n,k;
    cin >> n >> k;
    double ans = 0;
    double res = 0;

    vector<double> p(n);
    rep(i,n){
        int s;
        cin >> s;
        p[i] = (1.0+s)/2.0;
    }

    rep(i,k){
        res += p[i];
    }
    ans = res;
    rep(i,n-k){
        double x = res;
        res -= p[i];
        res += p[i+k];
        ans = max(ans,res);
    }

    printf("%.15lf\n",ans);
    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc154.contest.atcoder.jp/tasks/abc154_b

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i=0; ;i++){
            int n=sc.nextInt();
            int[] array = new int[n];
            for(int j=1;j<=n;j++){
                array[j-1]=n-j+1;
            }
            int r=sc.nextInt();
            if((n==0)&&(r==0)){
                break;
            }
            for(int j=1;j<=r;j++){
                int p=sc.nextInt();
                int c=sc.nextInt();
                int[] array2 = new int[c];
                for(int k=1;k<=c;k++){
                    array2[k-1]=array[p+k-2];
                }
                for(int k=1;k<=p-1;k++){
                    array[p+c-k-1]=array[p-k-1];
                }
                for(int k=0;k<=c-1;k++){
                    array[k]=array2[k];
                }
            }
            System.out.println(array[0]);
        }
    }
}


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

int main() {
  string S;
  int cnt=0;
  cin >> S;
  rep(i, S.size()) if(S[i]=='0') cnt++;
  cout << min(cnt, int(S.size()-cnt))*2 << endl;    
}

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split())) for _ in range(D)]
    T = list(int(input()) for _ in range(D))

    sat = 0
    last = [0] * 26
    for d in range(D):
        t = T[d] - 1
        sat += S[d][t]
        dsat = 0
        for i in range(26):
            if i == t:
                continue
            dsat += C[i] * ((d + 1) - last[i])
        last[t] = d + 1
        sat -= dsat
        print(sat)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    //取りうる暗証番号は000~999まで
    int ans = 0;
    rep(i,10){
        rep(j,10){
            rep(k,10){
                string t = to_string(i) + to_string(j) + to_string(k);
                int ok=0;
                rep(l,n){
                    if(s[l]==t[ok]) ok++;
                    if(ok==3) break;
                }
                if(ok==3) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = "Yes";
    if (s.length() % 2 == 0)
    {
        string s1 = s.substr(0, s.length() / 2);
        string s2 = s.substr(s.length() / 2, s.length() / 2);

        for (auto i = 0; i < s1.length(); i++)
        {
            if(s1[i] != s2[i]){
                ans = "No";
            }
        }    
    }else{
        ans = "No";
    }

    cout << ans << endl;
}

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

using namespace std;

long long mod(long long a,long long x,long long p)
{
    long long int res=1;
    while(x>0)
    {
        if(x%2)
        {
            res=(res*a)%p;
        }
        a=(a*a)%p;
        x/=2;
    }
    return res;

}

void solve()
{
   string s,r;
   cin>>s;

   map<int,int>mp;
   long long int x,num=0,n=s.size(),w;
   for(int i=0;i<n;i++)
   {
       x=s[i]-'0';
       num=num+(x*mod(10,n-i-1,2019))%2019;
       num%=2019;
       mp[num]++;
   }

   int ans=0;
   ans+=mp[0];

   for(int i=0;i<2019;i++)
   {
       ans+=(mp[i])*(mp[i]-1)/2;
   }

   cout<<ans<<endl;
}

int main()
{

   ios::sync_with_stdio(0);
   cin.tie(NULL);

   solve();

   return 0;
}


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


using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b >= c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String str = sc.next();
        int t = 0;
        int s = 0;
        int ans = 0;
        for(int i = str.length()-1; i>=0; i--) {
            char c = str.charAt(i);
            if(c=='T') {
                t++;
            }
            if(c=='S' && t>0) {
                t--;
                ans++;
            }
        }
	p(str.length()-ans*2);
    }
    public static <T> void p(T element) {
	System.out.println(element);
    }
    public static int min(int a, int b, int c) {
	int min = Math.min(a,b);
	min = Math.min(min,c);
	return min;
    }
    public static int max(int a, int b,int c) {
	int max= Math.max(a,b);
	max = Math.max(max,c);
        return max;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23252
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>

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

using namespace std;

int main(){
	long long int N,T[1000]={},A[1000]={},ct,ca,c;
	long long int ansT=0,ansA=0;
	cin>>N;
	FOR(i,0,N){
		cin>>T[i]>>A[i];
	}
	ansT=T[0];ansA=A[0];
	FOR(i,1,N){
		if(T[i]<ansT||A[i]<ansA){
			ct=ansT%T[i];
			ca=ansA%A[i];
			if(ct==0)ansT=ansT-T[i];
			if(ca==0)ansA=ansA-A[i];
			c=max((ansT-ct)/T[i],(ansA-ca)/A[i]);
			ansT=T[i]*(1+c);ansA=A[i]*(1+c);
		}
		else{
			ansT=T[i];ansA=A[i];
		}
	}
	cout<<(ansT+ansA);
return 0;
}

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

using namespace std;

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

	int t;

	scanf("%d", &t);

	while (t--) {
		long long a, b, c, d;
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
		if (a < b or b > d) {
			puts("No");
			continue ;
		}
		long long gg = __gcd(b, d);
		a = a%b;
		if (a > c) {
			puts("No");
			continue ;
		}
		long long tmp = (c+1ll)/gg;
		tmp *= gg;
		if (tmp <= c) {
			tmp += gg;
		}
		if (tmp < b) {
			puts("No");
		} else {
			puts("Yes");
		}
	}

	return 0;
}


Measured memory_bytes: 256
// Cut and Count

#include <iostream>

using namespace std;

int main(){
	int N;
	cin >> N;
	char S[N];
	for (int i = 0; i < N; ++i)
		cin >> S[i];

	int res = -1;

	for (int i = 1; i < N; ++i){ // i: cut position
		int ntype = 0;
		for (int j = 'a'; j <= 'z'; ++j){
			bool Xflag = false, Yflag = false;

			// [0, i)
			for (int k = 0; k < i; ++k){
				if (S[k] == j)
					Xflag = true;
			}
			// [i, N)
			for (int k = i; k < N; ++k){
				if (S[k] == j)
					Yflag = true;
			}
			if (Xflag && Yflag)
				ntype++;
		}
		res = max(res, ntype);
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

struct UnionFind{
    vector<int>par;
    UnionFind(int N) : par(N){
        rep(i,N)par[i] = i;
    }
    int root(int x){
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)return;
        par[rx] = ry;
    }
    bool same(int x,int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m;cin>>n>>m;
    UnionFind uf(n);
    vector<int>p(n);
    rep(i,n){cin>>p[i];p[i]--;}
    rep(i,m){
        int x,y;cin>>x>>y;
        x--;y--;
        uf.unite(x,y);
    }
    int res = 0;
    rep(i,n){
        if(uf.same(i,p[i]))res++;
    }
    cout<<res<<endl;
}



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

class Magatro
{
    static int N, T;
    static int[] A;
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        N = int.Parse(s[0]);
        T = int.Parse(s[1]);
        A = Console.ReadLine().Split(' ').Select(ss => int.Parse(ss)).ToArray();
        int cnt = 0;
        int max = 0;
        int min=A[0];
        for (int i = 1; i < N; i++) {
            if (A[i] - min > max)
            {
                max = A[i] - min;
                cnt = 1;
            }
            else if (A[i] - min == max)
            {
                cnt++;
            }
            if (min > A[i])
            {
                min = A[i];
            }
        }
       
        
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 13400
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;


int ans[60];
int found;

int main(){
	
	for(int i=6;found<=60;i+=5){
		bool b=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)b=false;
		}
		if(b){
			ans[found]=i;
			found++;
		}
	}
	
	int n;cin>>n;
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define MOD 1000000007

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


    long long powx[401][401];
    for(int i=1; i<=400; i++) powx[i][0] = 1;
    for(int i=1; i<=400; i++)
        for(int j=1; j<=400; j++)
            powx[i][j] = (powx[i][j-1] * i) % MOD;

    long long f[401][401];
    for(int i=0; i<N; i++){
        for(int a=0; a<=C; a++){
            long long tmp = 0;
            for(int x=A[i]; x<=B[i]; x++)
                tmp = (tmp + powx[x][a]) % MOD;
            f[i+1][a] = tmp;
        }
    }

    long long dp[401][401];
    for(int i=0; i<=N; i++)
        for(int j=0; j<=C; j++)
            dp[i][j] = 0;
    dp[0][0] = 1;

    for(int i=1; i<=N; i++){
        for(int j=0; j<=C; j++){
            for(int k=0; k<=C; k++){
                if(j - k < 0) continue;
                dp[i][j] += (dp[i-1][j-k] * f[i][k]) % MOD;
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[N][C] << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  for (int i=0; i<N; i++) {
    int  l, r, sum;
    cin >> l >> r;
    
    sum += r - l + 1;
    
    if (i <N-1) {
      continue;
    }
    
    cout << sum << endl;
  }
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,c,d;
  int res_f,res_s;
  
  scanf("%d%d%d%d",&a,&b,&c,&d);

  res_f = a*b;
  res_s = c*d;
  
  if(res_f >= res_s){
    printf("%d\n",res_f);
  }
  else{
    printf("%d\n",res_s);
  }
  return 0;
}

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

using namespace std;

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int ans = 0;
	if(a % 2 != b % 2 && a % 2 != c % 2) {
		ans++;
		b++;
		c++;
	} else if(b % 2 != a % 2 && b % 2 != c % 2) {
		ans++;
		a++;
		c++;
	} else if(c % 2 != a % 2 && c % 2 != b % 2) {
		ans++;
		a++;
		b++;
	}

	if(a >= b && a >= c) {
		ans += (a - b) / 2 + (a - c) / 2;
	} else if(b >= a && b >= c) {
		ans += (b - a) / 2 + (b - c) / 2;
	} else if(c >= a && c >= b) {
		ans += (c - a) / 2 + (c - b) / 2;
	}

	cout << ans << endl;

	

	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int n;
ll a[110];
ll f(int x){
    ll A = 0;
    for(int i = 1; i <= n; i++){
        A += (x - a[i]) * (x - a[i]);
    }
    return A;
}
int main() {
    ll sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    cout << min(f(sum / n) , f(sum / n + 1)) << endl;
}


Measured memory_bytes: 3620
#include <stdio.h>
int main(){
int sum=0,h=0,i,j,num=0,n,x[10000];
for(i=2;;i++){
for(j=2;j*j<=i;j++){
if(i!=j){if(i%j==0){num=1;}}
}if(num==0){x[h]=i; h++;}num=0;
if(h==10000){break;}
}
while(1){
scanf("%d",&n);
if(n==0) break;
for(i=0;i<n;i++){
	sum+=x[i];
}
printf("%d\n",sum);
sum=0;
}
return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>



using namespace std;

struct peak {
	vector<int> edge;
	int high;
};

int main(void) {

	peak a[100005];
	int n, m;
	cin >> n >> m;

	int h;
	for (int i = 1; i <= n; i++) {
		cin >> h;
		a[i].high = h;
	}
	int ai, bi;
	while (m--) {
		cin >> ai >> bi;
		a[ai].edge.push_back(bi);
		a[bi] .edge.push_back(ai);
	}

	int count = 0;
	bool flag = true;
	for (int i = 1; i <= n; i++) {
		for (int x : a[i].edge) {
			if (a[i].high <= a[x].high) {
				flag = false;
				break;
			}
		}
		if (flag) count++;
		flag = true;

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


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  int k = d-c;
  dump(k, b-a);

  if (a>b) swap(a,b);
  int m = n-1;

  rep(p, (m/2)+1){
    int l = (n-1)-2*p;
    int r = INF;
    if (c*l <= b-a and b-a <= d*l){
      cout << "YES" << endl;
      return 0;
    }
    chmin(r, abs(b-a-c*l));
    chmin(r, abs(b-a-d*l));
    if (p * k >= r){
      dump(p, r);
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
//BFS

namespace D
{
    class Program
    {
        static public readonly int INF=1001001001;
        public struct Pair 
        {
            public int x;
            public int y;
            public Pair(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
        }
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int h = int.Parse(In[0]);
            int w = int.Parse(In[1]);
            var C = new char[h,w];
            for(int i = 0; i < h; i++)
            {
                string s = Console.ReadLine();
                for(int j = 0; j < w; j++)
                {
                    C[i, j] = s[j];
                }
            }
            var di = new int[] {-1,0,1,0};
            var dj = new int[] {0,-1,0,1};
            int ans = 0;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (C[i, j] == '#') continue;
                    //ここから　forループの中にいれるのわすれずに
                    var dist = new int[h, w];
                    for (int zi = 0; zi < h; zi++)
                    {
                        for (int zj = 0; zj < w; zj++)
                        {
                            dist[zi, zj] = INF;
                        }
                    }
                    var q = new Queue<Pair>();
                    void Update(int oi, int oj, int ox)//ローカル関数
                    {
                        if (dist[oi, oj] != INF) return;
                        dist[oi, oj] = ox;
                        q.Enqueue(new Pair(oi, oj));
                    }
                    //ここまで
                    Update(i, j, 0);
                    while (q.Count != 0)
                    {
                        var p = q.Dequeue();
                        for (int dir=0; dir < 4; dir++)
                        {
                            int ni = p.x + di[dir];
                            int nj = p.y + dj[dir];
                            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                            if (C[ni, nj] == '#') continue;
                            Update(ni, nj, dist[p.x, p.y] + 1);
                        }
                    }
                    for (int zi = 0; zi < h; zi++)
                    {
                        for (int zj = 0; zj < w; zj++)
                        {
                            if (dist[zi, zj] == INF) continue;
                            ans = (int)Math.Max(ans, dist[zi, zj]);
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28340
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	pair<int, int> intersection = {1, n};
	int l, r;
	for (int i = 0; i < n; ++i) {
		cin >> l >> r;
		if (l > intersection.second) {
			cout << "0\n";
			return 0;
		}

		intersection.first = max(intersection.first, l);
		intersection.second = min(intersection.second, r);
	}

	cout << intersection.second - intersection.first + 1 << "\n";

	return 0;

}

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

int main() {
	// your code goes here
	string s;
	
	cin>>s;
	
	if(s.size()==2) {
		cout<<s<<endl;
	}else {
		reverse(s.begin(), s.end());
		cout<<s<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>

using namespace std;
#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define DE(...) fprintf(stderr,__VA_ARGS__);
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define ll long long

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int INF=0x3f3f3f,MAXN=1e6+10,MAXM=1e6+10;

int head[MAXN],to[MAXM<<1],_next[MAXM<<1],weigh[MAXM<<1],cnt;

void addedge(int u,int v,int w) {
	cnt++;
	_next[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
	weigh[cnt]=w;
}

int dist[MAXN],inq[MAXN];
queue<int> q;
void SPFA() {
	q.push(1);
	inq[1]=1;
	memset(dist,127,sizeof(dist));
	dist[1]=0;
	while(!q.empty()) {
		int u=q.front();q.pop();
		inq[u]=0;
		for(int i=head[u]; i; i=_next[i]) {
			int v=to[i];
			if(dist[v]>dist[u]+weigh[i]) {
				dist[v]=dist[u]+weigh[i];
				if(!inq[v]) {
					inq[v]=1;
					q.push(v);
				}
			}
		}
	}
}

map<int,int> mp[MAXN];
int tot;
int get(int x,int w) {
	if(!mp[x][w]) mp[x][w]=++tot;
	return mp[x][w];
}

int main() {
	int n=read(),m=read();
	tot=n;
	REP(i,1,m) {
		int u=read(),v=read(),w=read();
		int du=get(u,w),dv=get(v,w);
		addedge(u,du,1);addedge(du,u,1);
		addedge(du,dv,0);addedge(dv,du,0);
		addedge(v,dv,1);addedge(dv,v,1);
	}

	SPFA();

	printf("%d\n",dist[n]>2*n?-1:dist[n]/2);
	return 0;
}



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

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {

        static void Main(string[] args)
        {
//            string[] s = Console.ReadLine().Split(' ');
            int a = Int32.Parse(Console.ReadLine());
 //           int b = Int32.Parse(s[1]);

            if ( a > 81)
            {
                    Console.WriteLine("No");
                    return;

            }

            for (int i=1; i< 10; i++)
            {
                if (( a % i == 0 ) && a/i < 10)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");


        }

        static int rec(int[] n, int i, int j, int x)
        {
            if (i + 1 == j)
            {
                return Math.Min(n[j], x);
            }
            return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
        }


    }
}


Measured memory_bytes: 13140
n = input()
a_list = input().split()
a_list = [int(a) for a in a_list]

fours = 0
twos = 0
others = 0

for a in a_list:
    if a % 4 ==0:
        fours += 1
    elif a % 2 == 0:
        twos += 1
    else:
        others += 1

if others <= fours:
    print("Yes")
elif others-1 == fours and twos==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void){
  char a[51][51],b[50][51];
  char *p;
  int N,M;
  int i,j,offset;
  int flg=0;

  scanf("%d%d%*c",&N,&M);
  for(i=0;i<N;i++) scanf("%s%*c",a[i]);
  for(i=0;i<M;i++) scanf("%s%*c",b[i]);

  offset=0;
  for(i=0;i+M-1<N;i++){
    if((p=strstr(a[i]+offset,b[0]))==NULL){
      offset=0;
      continue;
    }
    offset=p-a[i];
    flg=1;
    for(j=1;j<M;j++){
      if(strncmp(a[i+j]+offset,b[j],M)!=0){
	flg=0;
	break;
      }
    }
    if(flg==1) break;
    i--;
    offset++;
  }
  puts(flg==1?"Yes":"No");
  return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

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

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

  int keta(1);
  int tmp = n;
  int res(0);
  for (;;) {
    tmp /= 10;
    if (tmp > 0) keta++;
    else break;
  }

  for (int i = 1; i <= keta; ++i) {
    if (i % 2 == 1) {
      if (i != keta) {
        res += pow(10, i) - pow(10, i-1);
        //cout << i << "桁目は" << pow(10, i) - pow(10, i-1) << endl;
      } else {
        res += n - pow(10, i-1) + 1;
        //cout << i << "桁目は" <<n - pow(10, i-1) + 1 << endl;
      }
    }
  }

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


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

typedef long long LL;
const int N = 155;
int n, k, mod;

void up(int &x, int y) { x += y - mod, x += x >> 31 & mod; }

void solve0() {
	static int dp[N][N]; k >>= 1, dp[0][0] = 1;
	for (int i = 0; i < n + 1 >> 1; ++i) {
		for (int j = 1; j <= k; ++j)
			dp[i + 1][j] = dp[i][j - 1];
		for (int j = 0; j <= k; ++j)
			up(dp[i + 1][0], dp[i][j]);
	}
	int a = 0, b = 0;
	for (int i = 0; i <= k; ++i)
		up(a, dp[n >> 1][i]), up(b, dp[n + 1 >> 1][i]);
	std::cout << (LL) a * b % mod << '\n';
}

void solve1() {
	static int dp[N][N][N];
	dp[0][0][0] = 1;
	const int L = k >> 1, R = n >> 1;
	for (int i = 0; i < n + k >> 1; ++i)
		for (int j = 0; j <= k + 1; ++j)
			for (int l = 0; l <= n >> 1; ++l)
				if (int v = dp[i][j][l]) {
					up(dp[i + 1][0][0], v);
					if (i >= L)
						up(dp[i + 1][j + !!j][0], v);
					if (i < R)
						up(dp[i + 1][0][l + 1], v);
					if (i >= L && i < R)
						up(dp[i + 1][std::max(j + 1, l + 2)][l + 1], v);
				}
	int ans = 0;
	for (int j = 0; j <= k + 1; ++j)
		for (int l = 0; l <= n >> 1; ++l)
			up(ans, dp[n + k >> 1][j][l]);
	std::cout << ans << '\n';
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> k >> mod;
	if (k & 1) solve1(); else solve0();
	return 0;
}

Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int N,M;bool flag=true;
vector<pair<int,int>> g[size];
pair<int,int> vp[size]={{0,0}};
void dfs(int n,int v,int d){
	for(pair<int,int> p:g[v]){
		int u=p.first;
		if(u==n) continue;
		if(vp[u].first==0){
			vp[u]={1,d+p.second};
			dfs(v,u,vp[u].second);
		}else{
			if(vp[u].second!=d+p.second) flag=false;
		}
	}return;
}
int main(){
	cin>>N>>M;
	int l,r,d;
	rep(i,0,M){
		cin>>l>>r>>d; l--; r--;
		g[l].push_back({r,d});
		g[r].push_back({l,-d});
	}
	rep(i,0,N){
		if(!vp[i].first) dfs(-1,i,0);
	}cout<<(flag ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 12416
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n = inp()
l = inpl()

l.sort()

ans = 0
for i in range(n-2):
    for j in range(i, n-1):
        for k in range(j, n):
            if l[i] < l[j] < l[k] and l[i] + l[j] > l[k]:
                ans += 1
print(ans)


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;;
	vector<string> s(3);
	rep(i,3) cin >>s[i];
	
	int sm=0;
	rep(i, sz(s[0])){
		set<char> st;
		rep(j,3) st.insert(s[j][i]);
		if(sz(st)==3) sm +=2;
		if(sz(st)==2) sm++;
		//cout <<sz(st) <<"  ";
	}
	cout <<  sm <<"\n";
	return 0;
}


Measured memory_bytes: 256
s=input().split()

moji=[]
count=[]
mojisuu=""

for i in range(len(s)):
    n=0
    if(len(mojisuu)<len(s[i])):
        mojisuu=s[i]
    
    for j in range(len(moji)):
        if(moji[j]==s[i]):
            count[j]+=1
            n+=1
            break
    if(n==0):
        moji.append(s[i])
        count.append(1)

max_count=max(count)
max_index=count.index(max_count)
shutugen=moji[max_index]

print(shutugen, mojisuu)


Measured memory_bytes: 5560
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    936 Hours of Solitude
    Quarantine_Day : 39
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 90

bool issqr(int n){
    int sq = sqrt(n);
    return (sq * sq) == n;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll a, b, c, d;
    cin>>a>>b>>c>>d;
    int res(0);
    FOR(i, 0, a){
        FOR(j, 0, b){
            FOR(k, 0, c){
                if(((500 * i) + (100 * j) + (50 * k)) == d)res++;
            }
        }
    }
    cout<<res<<"\n";

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const int INF = 100000000;

int p[100000];
bool comp[100000] = { false };
string s[100000];
int WA[100000] = { 0 };

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        cin >> p[i] >> s[i];
        p[i]--;
    }

    int ac_count = 0;
    int wa_count = 0;
    rep(i, m) {
        if (comp[p[i]] == true) continue;
        else {
            if (s[i] == "AC") {
                ac_count++;
                comp[p[i]] = true;
                wa_count += WA[p[i]];
            }
            else {
                WA[p[i]]++;
            }
        }
    }
    cout << ac_count << " " << wa_count << endl;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <string.h>

char a[21][21];

int main()
{
  int n,x,y,m,s;
  int i;
  char d[3];

  while(1){
    scanf("%d", &n);
    if(n==0)
      break;

    memset(a,0,sizeof(a));

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

    scanf("%d", &m);
    x=10,y=10;
    while(m-- > 0){
      scanf("%s%d", d, &s);
      while(s-- > 0){
	if(d[0] == 'E')x++;
	else if(d[0] == 'S')y--;
	else if(d[0] == 'W')x--;
	else if(d[0] == 'N')y++;
	
	if(a[x][y])n--,a[x][y]=0;
      }
    }

    if(n==0)
      printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}



Measured memory_bytes: 2580
import java.util.Scanner;
 
class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
 
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int x = scanner.nextInt();
    int y = scanner.nextInt();
    int sum = 0;
 
    if(a + b < c * 2){
      sum = a * x + b * y;
      System.out.println(sum);
    }else{
      while(x >= 1 && y >= 1){
        sum += c * 2;
        x--;
        y--;
      }
      int sum2 = sum;
      sum += a * x + b * y;
      if(a > c * 2 || b > c * 2){
        while(x >= 1 || y >= 1){
          sum2 += c * 2;
          x--;
          y--;
        }
        x = 0;
        y = 0;
      }
      sum2 += a * x + b * y;
      if(sum < sum2){
        System.out.println(sum);
      }else{
        System.out.println(sum2);
      }
    }
  }
}

Measured memory_bytes: 21972
//Copyright(c)2017 Mstdream
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
char s[N];
int nxt[N][26],f[N],a['z'+5],n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int t=1,tot=0;
	for(int i=n;i>=1;i--){
		f[i]=f[i+1];
		if(a[s[i]]==0)a[s[i]]=1,tot++;
		if(tot==26){
			memset(a,0,sizeof a),t++;
			tot=0;f[i]++;
		}
	}
	f[n+2]=-1;
	for(int i=0;i<26;i++){
		nxt[n][i]=n+1;
		for(int j=n-1;j>=0;j--){
			if(s[j+1]==i+'a')nxt[j][i]=j+1;
			else nxt[j][i]=nxt[j+1][i];
		}
	}
	int now=0,tt=t;t--;
	for(int i=1;i<=tt;i++){
		for(int j=0;j<26;j++){
			if(f[nxt[now][j]+1]<=t-1){
				now=nxt[now][j];
				putchar(j+'a');
				t--;break;
			}
		}
	}
}

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

using ll  = long long;
using pii = pair<int,int>;
#define dbg(n) cout<<'\n'<<#n<<" is "<<n<<'\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define cs(i) cout<<"Case "<<i+1<<": \n"; 
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N   = 1e2+5;
const int INF = 0x7fffffff;

int n,cap;
int w[N],v[N];
ll dp[100005]; // to gain atleast v value, the min weight have to carry is => dp[v]

int main(){

    ll sum=0;
    cin>>n>>cap;

    for(int i=0; i<n; i++)
        cin >> w[i] >> v[i],sum+=(ll)v[i];

    fill(dp,dp+100000,INF);
    dp[0]=0;
    
    for(int i=0;i<n;i++){
        for(ll j=sum;j>=v[i];j--)
            dp[j]=min(dp[j],dp[j-v[i]]+(ll)w[i]);
    }
    
    for(ll j=sum;j>=0;j--)
        if(dp[j]<=cap)
            return cout<<j, 0;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, m, ans=1;
    cin >> n >> m;
    vector<bool> a(n+1,true);
    rep(i,m){
        ll out;
        cin >> out;
        a[out] = false;
    }
    vector<ll> dp(n+1,0);
    dp[0]=dp[1]=1;
    if(a[1]==false) dp[1]--;
    REP(i,2,n+1){
        if(a[i]==false) dp[i] = 0;
        else dp[i] = ((dp[i-1]%mod)+(dp[i-2]%mod))%mod;
        dp[i] %= mod;
    }
    cout << dp[n]%mod << endl;
    return 0;
}


Measured memory_bytes: 3940
import math
s = input()
s = list(s)

if len(s)%2 == 1:
	l = [0]*(len(s)//2 + 1)
	for i in range(len(s)//2 + 1):
		l[i] = s[2*i]
	L = ''.join(l)
	print(L)
else:
	l = [0]*(len(s)//2)
	for i in range(len(s)//2):
		l[i] = s[2*i]
	L = ''.join(l)
	print(L)

Measured memory_bytes: 10024
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for l in range(K+1):
  for r in range(K-l+1):
    a=[]
    if l+r>N:
      break
    a=V[:l]
    a.extend(V[N-r:])
    b=sum(a)
    a.sort()
    for i in range(min(K-l-r,l+r)):
      if a[i]>=0:
        break
      else:
        b-=a[i]
    ans=max(ans,b)
print(ans)

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

const int maxn = 2e3+115;

template <class TAT>
void Ckmin(TAT &a, const TAT &b)
{
	if (a > b) {
		a = b;
	}
}

int n, m;
int f[maxn][maxn];

int A[maxn * 2][2];
int Bp[maxn][maxn * 2];
int Wp[maxn][maxn * 2];
int Bpos[maxn];
int Wpos[maxn];

void Init()
{
	char s[3];
	int a;
	scanf("%d", &n);
	for (int i = 1; i <= n * 2; ++i) {
		scanf("%s%d", s, &a);
		A[i][0] = a;
		A[i][1] = (s[0] == 'B');
	}
}

void Solve()
{
	memset(f, 0x3f, sizeof(f));
	f[0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i < n) {
				Ckmin(f[i + 1][j], f[i][j] + Wpos[i + 1] - 1 - Wp[i][Wpos[i + 1]] - Bp[j][Wpos[i + 1]]);
			}
			if (j < n) {
				Ckmin(f[i][j + 1], f[i][j] + Bpos[j + 1] - 1 - Wp[i][Bpos[j + 1]] - Bp[j][Bpos[j + 1]]);
			}
		}
	}
	cout << f[n][n] << endl;
}

void Prepare()
{
	for (int i = 1; i <= n * 2; ++i) {
		if (A[i][1] == 0) {
			Wpos[A[i][0]] = i;
		}
		else {
			Bpos[A[i][0]] = i;
		}
	}
	memset(Bp, 0, sizeof(Bp));
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n * 2; ++j) {
			Bp[i][j] = Bp[i][j - 1] + (A[j][1] == 1 && A[j][0] <= i);
		}
	}
	memset(Wp, 0, sizeof(Wp));
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n * 2; ++j) {
			Wp[i][j] = Wp[i][j - 1] + (A[j][1] == 0 && A[j][0] <= i);
		}
	}
}

int main()
{
	Init();
	Prepare();
	Solve();
	return 0;
}


Measured memory_bytes: 87680
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return a-b;
}

const s: string[] = input[0].split('');

if(s[0] === s[1] || s[1] === s[2] || s[2] === s[3]){
    console.log('Bad');
}else{
    console.log('Good');
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int h,w;//型
pair<int,int> ss,gg;//スタートゴール
char s[51][51];
//vector<vector<char>> s(h+1,vector<char>(w+1,'a'));//迷路

vvll bfs(){
    vvll d(h+1,vll(w+1,MOD*10));
    d[ss.first][ss.second]=0;
    queue<pair<ll,ll>> q;
    q.push(ss);
    vector<pair<int,int>> move;
    move.push_back(make_pair(1,0));
    move.push_back(make_pair(-1,0));
    move.push_back(make_pair(0,1));
    move.push_back(make_pair(0,-1));
    while (q.size()!=0){
        auto q1=q.front();
        int x=q1.first;
        int y=q1.second;
        q.pop();
        for (auto z:move){
            int dx=z.first;
            int dy=z.second;
            int x1=x+dx;
            int y1=y+dy;
            if (x1>h || x1<=0 || y1>w || y1<=0){
                continue;
            }
            else{
                if (s[x1][y1]=='#')continue;
                if (d[x1][y1]>d[x][y]+1){
                    d[x1][y1]=d[x][y]+1;
                    q.push(make_pair(x1,y1));
                }             
            }
        }
    }
    return d;
}

int main() {
    cin>>h>>w;
    int c=0;
    rep(i,h){
        rep(j,w){
            cin>>s[i+1][j+1];
            if (s[i+1][j+1]=='#'){
                c+=1;
            }
        }
    }
    //cout<<1<<endl;
    ss=make_pair(1,1);
    auto dd=bfs();
    if (dd[h][w]>MOD){
        cout<<-1<<endl;
    }
    else{
        cout<<h*w-1-dd[h][w]-c<<endl;
    }



    

    return 0;
}

Measured memory_bytes: 256
import math
 
def solve(a,n,k):
  dp = [0]*(n)
  dp[0]=0
  inf = 10**9
  for i in range(1,n):
    dp[i]=inf
    r=max(0,i-k)
    dp[i]=min([abs(a[i]-a[j])+dp[j] for j in range(r,i)])
 
  #print(dp)
  return dp[-1]
n,k=map(int,input().split())
a=list(map(int,input().split()))
print(solve(a,n,k))

Measured memory_bytes: 14104
#include <iostream>

using namespace std;

int main(void){
  int one, zero, minas, K;
  cin >> one >> zero >> minas >> K;

  int ans = ((one <= K)?one:K ) + ((0 < (K -(one + zero) ) )?( (K - (one + zero)) * -1):0 );
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3164