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

#define SPEED cin.tie(0);ios::sync_with_stdio(false);
template <class T> void chmax(T& a, const T b){a=max(a,b);}

int main() {
    SPEED
    int N; cin >> N;
    vector<int> V(N+1),W(N+1);
    for(int i = 1; i <= N; ++i) cin >> V[i] >> W[i];

    //O(Q)
    constexpr int nl = 1<<10,nr=1<<8,L_max=100001;
    array<int,nl> msb;
    for(int i = 1; i < nl; ++i) msb[i]=31-__builtin_clz(i);

    array<int,nl> bit_w_dp;
    array<int,nl> bit_v_dp;
    vector<vector<int>> dp(nl,vector<int>(L_max,0));
    //前計算
    int m = min(nl,N+1);
    for(int n = 1; n < m; ++n) {
        int k = 2*n;
        vector<int> l;
        while(k/=2) l.push_back(k);
        int sz=l.size();
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[l[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[l[msb[i]]];
            if(bit_w_dp[i]<=L_max) chmax(dp[n][bit_w_dp[i]],bit_v_dp[i]);
        }
        //累積max
        for(int i = 1; i < L_max; ++i) {
            chmax(dp[n][i],dp[n][i-1]);
        }
    }

    int Q; cin >> Q;
    string ans_str="";

    //クエリ
    while(Q--) {
        int p,L,l_idx=0;; cin >> p >> L;
        vector<int> r;
        p *= 2;
        while(p/=2) {
            if(p<nl) chmax(l_idx,p);
            else r.push_back(p);
        }
        int sz = r.size(),ans=dp[l_idx][L];
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[r[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[r[msb[i]]];
            if(bit_w_dp[i]<=L) chmax(ans,dp[l_idx][L - bit_w_dp[i]]+bit_v_dp[i]);
        }
        ans_str += to_string(ans)+"\n";
    }
    cout << ans_str;

    return 0;
}


Measured memory_bytes: 408236
#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>;

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

Measured memory_bytes: 256
a = int(input())
b = 2+1#int(input())
x = list(map(int, input().split()))
dp = [0]+[10**10]*(a-1)
dp[1] = abs(x[1]-x[0])
for i,h in enumerate(x):
    for j in range(i+1,min(i+b,a)):
        dp[j] = min(dp[j],dp[i]+abs(h-x[j]))
#print(dp)
print(dp[a-1])

Measured memory_bytes: 13976
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

signed main(){
	int n,m;
	cin>>n>>m;
	vector<int>v;
	for(int i=1;i*i<=m;i++){
		if(m%i)continue;
		v.push_back(i);
		if(i*i!=m)v.push_back(m/i);
	}

	sort(v.begin(),v.end(),greater<int>());

	for(int j=0;j<v.size();j++){
		int i=v[j];
		//cout<<i<<endl;
		if(i*(n-1)>=m)continue;
		int x=i*(n-1);
		int p=m-x;
		if(__gcd(p,i)==i){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
fun main() {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toDouble() }
    val jub = A.sum() / (4.0 * M)

    val ans = A.filter { it >= jub }

    if (ans.size >= M) {
        println("Yes")
    } else {
        println("No")
    }

}



Measured memory_bytes: 37968
#include<stdio.h>

#define abs(OPR) ((OPR) < 0 ? -(OPR) : (OPR))

int main(void){
    long a,v,b,w,t;
    scanf("%ld%ld%ld%ld%ld",&a,&v,&b,&w,&t);
    printf((long long)abs(b-a) <= (v-w) * (long long)t ? "YES" : "NO");
}


Measured memory_bytes: 1732
import sys
sys.setrecursionlimit(10**6)


class UnionFind:
    def __init__(self, num):
        self.parent = list(range(num))
        self.size = [1] * num

    def get_root(self, node):
        root = self.parent[node]
        if root == node:
            return root
        else:
            root = self.get_root(root)
            self.parent[node] = root
            return root

    def are_in_same_union(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        if root1 == root2:
            return True
        else:
            return False

    def combine(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        self.parent[root2] = root1
        self.size[root1] += self.size[root2]


n, m = map(int, input().split())
pairs = [list(map(int, input().split())) for _ in range(m)]
pairs = pairs[::-1]
answers = []
UF = UnionFind(n+1)
ans = n*(n-1)//2
answers.append(ans)

for land1, land2 in pairs:
    if UF.are_in_same_union(land1, land2):
        ans = ans
    else:
        root1, root2 = UF.get_root(land1), UF.get_root(land2)
        ans -= UF.size[root1] * UF.size[root2]
        UF.combine(land1, land2)
    answers.append(ans)

answers.pop()
answers = answers[::-1]

for x in answers:
    print(x)



Measured memory_bytes: 47584
q = int(input())
 
def lcss(x,y):
     
    lcs = [0]*(len(x)+1)
    for i in range(len(y)):
        w1 = y[i]
        lcs_2 = lcs[:]
        for j in range(len(x)):
            if x[j] == w1:
                lcs[j+1] = lcs_2[j] + 1  
            elif lcs[j+1] < lcs[j]:
                lcs[j+1] = lcs[j]
    return lcs[-1]
 
for i in range(q):
    x = input()
    y = input()
    print(lcss(x,y))

Measured memory_bytes: 7704
/**
 * author:    Ziel
 * created:   16.04.2020 14:29:31
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const double EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

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

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n, m;
	cin >> n >> m;
	
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 2;
	}
	
	ll l = a[0];
	for (int i = 1; i < n; i++) {
		l = lcm(l, a[i]);
	}
	
	if (l > m) return !(cout << 0);
	
	for (int i = 0; i < n; i++) {
		if ((l / a[i]) % 2 == 0) return !(cout << 0);
	}
	
	cout << (m / l + 1) / 2;
	
	return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc =new Scanner(System.in);

        int R = sc.nextInt();


          if (R < 1200){
            System.out.println("ABC");
          }else if (R < 2800 && R >= 1200){
            System.out.println("ARC");
          }else {
            System.out.println("AGC");
          }

    }
}


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

ll solve() {
    cout.setf(ios::fixed);
    cout.precision(16);
    ll R;
    cin >> R;
    cout << R * M_PI * 2 << "\n";
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#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 ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mk make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
}



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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int a,b,c;cin>>a>>b>>c;
  int x,y;cin>>x>>y;
  c*=2;

  ll ans=INF;
  for (int i=0; i<=max(x,y); i++) {
    ll m=0;
    m = c*i;
    m += a * max(0, x-i);
    m += b * max(0, y-i);
    ans = min(ans, m);
  }

  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {

  ll n,a,b;
  cin>>n>>a>>b;
  if(abs(b-a)%2==0){
    cout<<abs(b-a)/2<<endl;
  }else{
    ll tmp=min(a-1,n-b);
    cout<<tmp+(b-a+1)/2<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
     
    LL ce(LL a,LL b){
    	if(b==1)return a;
    	if(b==0)return 1e16;
    	return(a+b-1)/b;
    	}
    int main(){
    	LL n;
    	cin>>n;
    	LL a,b;
    	cin>>a>>b;
    	for(int x=1;x<n;x++){
    		LL c,d;
    		cin>>c>>d;
    		LL ca,da;
    		ca=ce(a,c);
    		da=ce(b,d);
    		LL m=max(ca,da);
    		a=c*m;
    		b=d*m;
    		}
    		cout<<a+b<<endl;
    		return 0;
    	}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
  int i,j,n,key1,key2,roop,graph[101][101];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=0;j<=n;j++){
      graph[i][j]=0;
    }
  }


  for(i=1;i<=n;i++){
    scanf("%d%d",&key1,&roop);

    for(j=0;j<roop;j++){
      scanf("%d",&key2);
      graph[key1][key2]=1;
    }

  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      
      if(j!=1)printf(" ");
      printf("%d",graph[i][j]);

    }
    printf("\n");
  }

  return 0;
}



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

typedef unsigned long long int ull;

int main(void)
{
	ull way[21];
	ull next[21];
	int n, i, j;
	int num;
	
	memset(way, 0, sizeof(way));
	
	scanf("%d", &n);
	
	scanf("%d", &num);
	way[num] = 1;
	for (i = 1; i < n - 1; i++){
		memset(next, 0, sizeof(next));
		scanf("%d", &num);
		for (j = 0; j < 21; j++){
			if (j + num <= 20) next[j + num] += way[j];
			if (j - num >= 0) next[j - num] += way[j];
		}
		memcpy(way, next, sizeof(next));
	}
	
	scanf("%d", &num);
	
	printf("%lld\n", way[num]);
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

long long n, f[105][5][5][5], ans, p = 1e9 + 7;
/*
A = 1 T = 2 G = 3 C = 4
134
143
314
13_4
1_34
*/ 
int main()
{
	cin >> n;
	for (int a = 1; a <= 4; a++)
		for (int b = 1; b <= 4; b++)
			for (int c = 1; c <= 4; c++)
				if ((a == 1 && b == 4 && c == 3) ||
						(a == 1 && b == 3 && c == 4) ||
						(a == 3 && b == 1 && c == 4)) ;else f[3][a][b][c] = 1;
	for (int i = 4; i <= n; i++)
	{
		for (int a = 1; a <= 4; a++)
		{
			for (int b = 1; b <= 4; b++)
			{
				for (int c = 1; c <= 4; c++)
				{
					if ((a == 1 && b == 4 && c == 3) ||
						(a == 1 && b == 3 && c == 4) ||
						(a == 3 && b == 1 && c == 4))
					{
						f[i][a][b][c] = 0;
						continue;
					}
					f[i][a][b][c] = (f[i - 1][1][a][b] + f[i - 1][2][a][b] + 
									f[i - 1][3][a][b] + f[i - 1][4][a][b]) % p;
					if ((a == 3 && c == 4) || (b == 3 && c == 4))
						f[i][a][b][c] = (f[i][a][b][c] - f[i - 1][1][a][b] + p) % p;
					//cout << i << " " << a << " " << b << " " << c << " " << f[i][a][b][c] << endl;
				}
			}
		}
	}
	for (int a = 1; a <= 4; a++)
		for (int b = 1; b <= 4; b++)
			for (int c = 1; c <= 4; c++)
				ans = (ans + f[n][a][b][c]) % p;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
p = list(map(int,input().split()))
box = []
for i in p:
    box.append((i+1)/2)

sum_a = sum(box[:K])
max_a = sum_a
for i in range(N-K):
    max_a -= box[i]
    max_a += box[i+K]
    if max_a > sum_a:
        sum_a = max_a

print(sum_a)

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

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

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

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

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

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

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

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

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

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

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

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

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

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	vi w;
	REP(i,4)
		w.PB(read());
	sort(ALL(w));
	if(w==vi{1,4,7,9})
		Yes();
	else
		No();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using System.Security.Cryptography;
using console=System.Console;
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main()
        {
var p = console.ReadLine().Split().Select(s=>long.Parse(s)).ToArray();
if(Abs(p[0]-p[1])>100000000000000000)
console.WriteLine("Unfair");
else if(p.Last()%2==0)
console.WriteLine(p[0]-p[1]);
else
console.WriteLine(p[1]-p[0]);
        }
    }/*
    public static class Extention
    {
        public static IEnumerable<TResult> AggregateOther<TSource,TAccumulate,TResult>(this IEnumerable<TSource> en,TAccumulate seed,Func<TAccumulate,TSource,TAccumulate> f,Func<TAccumulate,TResult> g)
        {
            if(en.Count()<2) throw new SystemException("Can't aggregate each other for 1-element-Enumerable");
            var p = en.Select((v,i)=>new{v,i}).ToArray();
            for(int i = 0;i<en.Count();i++)
            {
                
            }
        }
    }*/
}

Measured memory_bytes: 11476
import heapq
n = int(input())
heap = list(map(int, input().split()))
heapq.heapify(heap)
m = heapq.heappop(heap)
while True:
    heap2 = []
    for i in heap:
        if i%m != 0:
            heapq.heappush(heap2, i%m)
    if len(heap2) == 0:
        print(m)
        exit()
    heapq.heappush(heap2, m)
    m = heapq.heappop(heap2)
    heap = heap2


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint L[N];
  REP(i,N)cin>>L[i];
  sort(L,L+N);
  int ans=0;
  REP(i,N)FOR(j,i+1,N)FOR(k,j+1,N){
    int l[3]={L[i],L[j],L[k]};
    if(l[2]<l[0]+l[1] and l[0]!=l[1] and l[1]!=l[2]){
      ans++;
      // cerr<<l[0]<<l[1]<<l[2]<<endl;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;
ll vis[100002]={0};

/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j,k;
	ll n;
	cin>>n;
	//ll arr[n];
	
	
	for(i=1;i<=100;i++)
	{
		for(j=1;j<=100;j++)
		{
			for(k=1;k<=100;k++)
			{
				ll a = (ll)(pow(i+j,2) + pow(i+k,2) + pow(k+j,2));
				a= a/2;
				vis[a]++;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		cout<<vis[i]<<endl;
	}
	

	


	
	

	
	


	
	return 0;
}

Measured memory_bytes: 4008
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	int N, ans = 0;
	char c[100];
	set<char> S1, S2, S3;

	scanf("%d", &N);
	scanf("%s", c);

	FOR(i, 1, N - 1){
		S1.clear();
		S2.clear();
		S3.clear();
		REP(j, i){
			S1.insert(c[j]);
		}
		FOR(j, i, N){
			S2.insert(c[j]);
		}
		set_intersection(S1.begin(), S1.end(), S2.begin(), S2.end(), inserter(S3, S3.end()));
		if (ans < S3.size()){
			ans = S3.size();
		}

	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ll MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    
    ll H=D-B;
    ll W=C-A;
    REP1(i,H){
        cout<<'U';
    }
    REP1(i,W){
        cout<<'R';
    }
    REP1(i,H){
        cout<<'D';
    }
    W++;
    H++;
    REP1(i,W){
        cout<<'L';
    }
    REP1(i,H){
        cout<<'U';
    }
    REP1(i,W){
        cout<<'R';
    }
    cout<<"DR";
    REP1(i,H){
        cout<<'D';
    }
    REP1(i,W){
        cout<<'L';
    }
    cout<<"U";
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
A,B,C,D = map(int,input().split(' '))

if C % B == 0 :
     rem = C/B
else :
     rem = (C - C%B)/B+1

if A % D == 0 :
     rem2 = A/D
else :
     rem2 = (A - A%D)/D+1

if rem <= rem2 :
    print('Yes')
else :
    print('No')
    

Measured memory_bytes: 9176
def examD():
    N, T =LI()
    A = LI()
    maXI = [0]*N
    maXI[N-1] = A[N-1]
    for i in range(1,N):
        maXI[N-i-1] = max(maXI[N-i],A[N-i-1])
    maXAD = int(0)
    for i in range(N-1):
        maXAD = max(maXAD,maXI[i+1]-A[i])
    cur = int(0)
    for i in range(N-1):
        if maXI[i+1]-A[i]==maXAD:
            cur +=1
    print(cur)



import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


Measured memory_bytes: 14244
#include <stdio.h>

int main(){
 int A[1000],N=0;
 scanf("%d", &N);
 for(int i=0;i<N;i++){
  scanf("%d", &A[i]);
 }
 for(int i=0;i<N;i++){
  int v;
  v = A[i];
  int j = i - 1;
  while( j >= 0 && A[j] > v){
   A[j+1] = A[j];
   j--;
   A[j+1] = v;
  }
  for(int i=0;i<N-1;i++){
   printf("%d ", A[i]);
  }
  printf("%d\n", A[N-1]);
 }
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << '\n';
		return 0;
	}
	long long ans = 0;
	for (int i = 1; i <= h; i++) {
		if (i % 2 == 1) {
			if (w % 2 == 0) {
				ans += (w / 2);
			} else {
				ans += (w / 2) + 1;
			}
		} else {
			ans += (w / 2);
		}
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 256
//
// Created by Wangzhe on 2019/10/19.
//
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxn = 2e5 + 10, INF = 0x3f3f3f3f;

const ll INFF = 1e12;

ll a[maxn];
ll f[maxn];

ll n,k;

bool check(ll x) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll t = a[i] - (x / f[i]);
        if (t > 0) sum += t;
    }
    return sum <= k;
}

int main() {
    cin >> n >>k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> f[i];
    }
    sort(a, a + n, [&](int x, int y){return x > y;});
    sort(f, f + n);

    ll l = 0, r = 1e18 + 10, mid, res;
    while (l <= r) {
        mid = l + r >> 1;
        if (check(mid)) {
            res = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;

int main()
{
    int N, M;
    cin >> N >> M;
    int sum = 0;
    rep(i, 0, M) {
        int tmp;
        cin >> tmp;
        sum += tmp;
    }
    int res;
    res = N - sum;
    res = max(-1, res);
    cout << res << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
    FIO
    ll n;
    cin>>n;
    cout<<2*3.14*n;
    
    return 0;
}

Measured memory_bytes: 3832
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int mod = 998244353;

inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }

inline int fsp(int x, int k = mod - 2) {
	int s = 1;
	while(k) {
		if(k & 1) s = 1LL * s * x % mod;
		x = 1LL * x * x % mod, k >>= 1;
	} return s;
}

int fac[500010];
int ifac[500010];

inline void init(int n) {
	fac[0] = ifac[0] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
	ifac[n] = fsp(fac[n]);
	for(int i = n; i >= 1; i--) ifac[i - 1] = 1LL * i * ifac[i] % mod;
}

inline int C(int n, int m) { return n < m || m < 0 ? 0 : 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod; }

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri, k = ri, res = 0;
	init(k);
	for(int i = n, j = k - i; i <= k; i++, j--) {
		if(i < j) continue;
		if(i == j) Add(res, Mod(C(k - 1, i) + mod - C(k - 1, j - i + n - 2)));
		else Add(res, Mod(C(k, i) + mod - C(k, j - i + n - 1)));
	} cout << res << endl;
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAX=1000;
const int VMAX=10000;
int n,A[MAX],s;
int B[MAX],T[VMAX+1];
int solve()
{
	int ans=0;
	bool V[MAX];
	for(int i=0;i<n;i++)
	{
		B[i]=A[i];
		V[i]=false;
	}
	sort(B,B+n);
	for(int i=0;i<n;i++)
	{
		T[B[i]]=i;
	}
		for(int i=0;i<n;i++)
		{
			if(V[i])
			continue;
			int cur=i;
			int S=0;
			int m=VMAX;
			int an=0;
			while(1)
			{
				V[cur]=true;
				an++;
				int v=A[cur];
				m=min(m,v);
				S=S+v;
				cur=T[v];
				if(V[cur])
				break; 
			}
			ans=ans+min(S+(an-2)*m,m+S+(an+1)*s);
		}	
	return ans;
}
int main()
{
  cin>>n;
  s=VMAX;
  for(int i=0;i<n;i++)
  {
  cin>>A[i];
  s=min(s,A[i]);
}
int ans=solve();
cout<<ans<<endl;
   
return 0;
 }


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

#define N 4
#define M 3

int main(void){
  int i,L[N];
  pair <int, int> path;
  string ans="YES";
  for(i=0;i<N;i++)L[i]=0;
  for(i=0;i<M;i++){
    cin >> path.first >> path.second;
    L[path.first-1]++;
    L[path.second-1]++;
  }
  for(i=0;i<N;i++){
    if(L[i] > 2 )ans="NO";
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import Data.List (elemIndex)
import Data.Maybe (fromJust)

nextN::Int->Char->Char
nextN n c = az !! (n + fromJust (elemIndex c az))
    where az = take 52 $ cycle ['A'..'Z']
main = do
  n <- readLn
  s <- getLine
  putStrLn $ map (\c -> nextN n c ) s

Measured memory_bytes: 1404
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

int n,x,t;

int main(){
    cin >> n >> x >> t;
    cout << ((n-1)/x+1)*t << endl;
    


return 0;
}

Measured memory_bytes: 3632
r=range
h,*s=open(0)
m=9e9
h,w,k=map(int,h.split())
for i in r(512):
 t=[j+1for j in r(h)if i>>j&1]+[h];l=len(t);v=-1;c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v+=f
  if f:c=u
 if g<1:m=min(m,v+l)
print(m)

Measured memory_bytes: 52056
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  int N;
  cin >> N;
  int a[N];
  rep(i,N) cin >> a[i];
  sort(a,a+N,greater<int>());
  int al=0,bo=0;
  rep(i,N){
    if(i%2==0) al+=a[i];
    else bo+=a[i];
  }
  cout << al - bo << endl;
    
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
       cin >> a.at(i);
    }
    ll mini = a.at(n-1);
    for (int i=n-2; i>=0; i--) {
        if (a.at(i) > mini+1) {
            cout << "No" << endl;
            return 0;
        }
        else {
            mini = min(a.at(i), mini);
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$a = strtoupper($key->A[0][0]);
$b = strtoupper($key->A[1][0]);
$c = strtoupper($key->A[2][0]);
printf("%s%s%s\n",$a,$b,$c);


Measured memory_bytes: 3828
import sys
from operator import itemgetter

n, m = map(int, input().split())
a = list(map(int, sys.stdin.readline().split()))
bc = [ tuple(map(int, x.split())) for x in sys.stdin.readlines()]
bc.sort(key = itemgetter(1), reverse=True)
bc.append((n,0))
diff = []
for b, c in bc:
    diff += [c] * b
    if len(diff) > n:
        break

a += diff
a.sort()
print(sum(a[-n:]))


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

def gcd(a, b):
    return b%a

while True:
    A.sort()
    if len(A) == 1:
        break
    a = A[0]
    tmp_A = [a]
    for b in A[1:]:
        b = gcd(a, b)
        if b != 0:
            tmp_A.append(b)
    A = tmp_A
print(A[-1])


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

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

  int n; cin >> n;
  ll su = 0;
  ll mi = LINF;
  REP(i, n) {
    ll a, b; cin >> a >> b;
    su += a;
    if(a > b) chmin(mi, b);
  }

  if(mi == LINF) cout << 0 << endl;
  else cout << su - mi << endl;


}
























Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, = gi()
a, b, c = gi(), gi(), gi()
ans = sum(b)
for k in range(1, n):
	if a[k] - a[k - 1] == 1:
		ans += c[a[k] - 2]
print(ans)

Measured memory_bytes: 3064
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s, t = list(map(str, readline().rstrip().decode('utf-8').split()))
    ans = []
    for i in range(n * 2):
        if i % 2 == 0:
            ans.append(s[i//2])
        else:
            ans.append(t[i//2])
    print("".join(ans))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main(){
    int a[4][4];
    cin>>a[1][1]>>a[1][2]>>a[2][2];
    a[1][3]=a[2][2]*3-a[1][2]-a[1][1];
    a[3][1]=a[2][2]*3-a[2][2]-a[1][3];
    a[3][3]=a[2][2]*3-a[2][2]-a[1][1];
    a[3][2]=a[2][2]*3-a[3][1]-a[3][3];
    a[2][1]=a[2][2]*3-a[1][1]-a[3][1];
    a[2][3]=a[2][2]*3-a[2][1]-a[2][2];
    cout<<a[1][1]<<" "<<a[1][2]<<" "<<a[1][3]<<endl;
    cout<<a[2][1]<<" "<<a[2][2]<<" "<<a[2][3]<<endl;
    cout<<a[3][1]<<" "<<a[3][2]<<" "<<a[3][3]<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main (){
    int N;
    scanf("%d",&N);
    int height[N];
    for (int i = 0; i < N; i++){
        scanf("%d",&height[i]);
    }
    int count=1;
    int idx=0;
    for (int i = 1; i < N; i++){
        if(height[i]>=height[idx]){
            count++;
            idx=i;
        }
    }
    printf("%d",count);
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int n,temp,flag=1;
    long long ans=0,time=0,a[55],max;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    while(flag)
    {
    	flag=0;
    	max=0;
    	for(int i=0;i<n;i++)
    	{
    		if(a[i]>max)
			{
				max=a[i];
				temp=i;
				if(max>=n)flag=1;
			}
		}
        if(flag==1)
        {
            time=a[temp]/n;
            ans+=time;
            a[temp]%=n;
            for(int i=0;i<n;i++)if(i!=temp)a[i]+=time;
        }
    }
    printf("%lld\n",ans);
}

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

ll dp[102][100005]; 
int ww[102], vv[102]; 

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

	for(int i = 0; i < n; i++){
		cin >> ww[i + 1] >> vv[i + 1]; 
	}

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= wmax; j++){
			if(i == 0 || j == 0)
				dp[i][j] = 0; 
			else if(j - ww[i] >= 0)
				dp[i][j] = max(dp[i - 1][j - ww[i]] + vv[i], dp[i - 1][j]);
			else
				dp[i][j] = dp[i - 1][j]; 
		}
	}

	cout << dp[n][wmax] << endl; 
}

Measured memory_bytes: 79104
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, T: "List[int]", V: "List[int]"):
    t_period = [0 for i in range(N+1)]
    for i in range(N):
        t_period[i+1] = t_period[i] + T[i]*2

    limit = np.zeros((t_period[N]+1,))
    for i in range(1, N):
        limit[t_period[i]] = min((V[i-1], V[i]))
    for i in range(N):
        limit[t_period[i]+1:t_period[i+1]] = V[i]
    
    speed = np.zeros((t_period[N]+1,))

    for v in range(1, 201):
        speed[v:t_period[N]+1-v] = np.min(
            [limit[v:t_period[N]+1-v], speed[v-1:t_period[N]-v]+0.5, speed[v+1:t_period[N]+2-v]+0.5],
            axis=0
            )

    total = 0
    for t in range(t_period[N]):
        total += (speed[t] + speed[t+1]) * 0.5 * 0.5
    
    print(total)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, t, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15232
#include <iostream>
#include <vector>

int main()
{
    std::vector<int> data(5, 0);
    for(int i=0; i < 5; i++) {
        std::cin >> data[i];
    }

    for(int i=0; i < 5; i++) {
        if(data[i] == 0) {
            std::cout << i+1 << std::endl;
        }
    }
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
    int a,b;
    char op;
    for(;;){
            scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
        printf("%d\n",a+b);
    }
    else if(op=='-'){
        printf("%d\n",a-b);
    }
    else if(op=='*'){
        printf("%d\n",a*b);
    }
    else if(op=='/'){
        printf("%d\n",a/b);
    }
    else if(op=='?'){
        break;
    }
    }
    return 0;
     
}

Measured memory_bytes: 1808
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int C=55;
int n,c;
int a[10];
double dp[C][10][1<<5];
int main(){
	n=read(),c=read();
	For(i,1,n)
		a[i]=read();
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	double cnt=0,tot=0;
	do {
		clr(dp);
		dp[0][1][0]=1;
		For(i,0,c-1)
			For(t,2,n)
				For(j,0,c-1)
					For(k,1,n){
						if (t==k||j+a[k]<i||(j+a[k]==i&&t>k))
							continue;
						For(s,0,(1<<(n-1))-1){
							if (dp[j][k][s]==0||(s>>(t-2)&1))
								continue;
							int _s=s|1<<(t-2);
							if (j+a[k]>i+a[t]||(j+a[k]==i+a[t]&&k>t))
								dp[j][k][_s]+=dp[j][k][s];
							else
								dp[i][t][_s]+=dp[j][k][s];
						}
					}
		double tmp=0;
		For(j,0,c-1)
			For(k,1,n)
				if (j+a[k]>=c)
					tmp+=dp[j][k][(1<<(n-1))-1];
		tot+=tmp/pow(c,n-1);
		cnt+=1.0;
	} while (prev_permutation(a+2,a+n+1));
	printf("%.12lf\n",tot/cnt);
	return 0;
}

Measured memory_bytes: 640
mycode = r'''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True
ctypedef long long LL
# cython: cdivision=True
from libc.stdio cimport scanf
from libcpp.vector cimport vector
ctypedef vector[LL] vec
ctypedef vector[vec] vec_vec

cdef LL R,C,K,i,j,k

scanf("%lld %lld %lld",&R,&C,&K)

cdef vec_vec dp,ndp,item

dp = vec_vec(C,vec(3,0))
ndp = vec_vec(C,vec(3,0))
item = vec_vec(R,vec(C,0))


cdef LL r,c,v

for i in range(K):
    scanf("%lld %lld %lld",&r,&c,&v)
    item[r-1][c-1] = v

dp[C-1][0] = item[R-1][C-1]
dp[C-1][1] = item[R-1][C-1]
dp[C-1][2] = item[R-1][C-1]

for j in range(C-2,-1,-1):
    dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0])
    dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1])
    dp[j][2]=max(item[R-1][j],dp[j+1][2])

for i in range(R-2,-1,-1):
    ndp = vec_vec(C,vec(3,0))
    ndp[C-1][0]=dp[C-1][0]+item[i][C-1]
    ndp[C-1][1]=dp[C-1][0]+item[i][C-1]
    ndp[C-1][2]=dp[C-1][0]+item[i][C-1]
    for j in range(C-2,-1,-1):
        ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0])
        ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1])
        ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2])
    dp=ndp

print(dp[0][0])

'''

import sys
import os
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


Measured memory_bytes: 151304
x, y = list(map(int, input().split()))
bola = 0
bola1 = 0
quick = 1

l1 = input().split()

for c in range(x):
    bola1 = int(l1[c])

    bola += bola1

    if bola <= y:
        quick += 1

print(quick)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
int w, h;
struct edge { int to, cost; };
int V;
vector<edge> G[100000];
int d[100000];
void init() {
	rep(i, V) {
		G[i].clear();
	}
}
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, (int)MOD);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < (int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main() {
	while (cin >> w >> h, w) {
        int d1[4] = { -(w+2),1,w+2,-1 };
		int c[4];
		init();
		V = (h+2) * (w+2) * 4;
		int board[32][32];
		rep(i, 32) {
			rep(j, 32) {
				board[i][j] = 5;
			}
		}
		rep1(i, h) {
			rep1(j, w) {
				cin >> board[i][j];
			}
		}
		rep(i, 4) {
			cin >> c[i];
		}
		int uni = (h + 2)*(w + 2) * 4;
		rep(i, h+2) {
			rep(j, w+2) {
				if (board[i][j] == 5)continue;
				//kが今の向き
				rep(k, 4) {
					int loc = k * (h + 2)*(w + 2) + i * (w + 2) + j;
					//直進とか
					rep(dir, 4) {
						int cost = c[dir];
						if (dir == board[i][j])cost = 0;
						if (dir == 0) {
							G[loc].push_back({ loc + d1[k],cost });
						}
						else if (dir == 1) {
							G[loc].push_back({ (loc + d1[(k + 1) % 4] + (h + 2)*(w + 2)) % uni,cost });
						}
						else if (dir == 2) {
							G[loc].push_back({ (loc + d1[(k + 2) % 4] + 2*(h + 2)*(w + 2)) % uni,cost });
						}
						else if (dir == 3) {
							G[loc].push_back({ (loc + d1[(k + 3) % 4] + 3*(h + 2)*(w + 2)) % uni,cost });
						}
					}
				}
			}
		}
		int sta = w + 3 + (h + 2)*(w + 2);
		dijkstra(sta);
		int mi = (int)MOD;
		int goal = h * (w + 2) + w;
		rep(i, 4) {
			mi = min(mi, d[goal + i * (h + 2)*(w + 2)]);
		}
		cout << mi << endl;
	}
	return 0;
}


Measured memory_bytes: 5776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(begin(b),end(b),greater<int>());
    rep(i,n){
        if(a[i]==b[0]) cout<<b[1]<<endl;
        else cout<<b[0]<<endl;
    }
}

Measured memory_bytes: 3200