akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    east = [0] * (N + 1)
    west = [0] * (N + 1)
    for i in range(N):
        east[i + 1] = east[i] + (1 if S[i] == 'E' else 0)
        west[i + 1] = west[i] + (1 if S[i] == 'W' else 0)

    ans = INF
    for i in range(N):
        if ans > west[i] + east[N] - east[i + 1]:
            ans = west[i] + east[N] - east[i + 1]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32980
import java.util.*;class Main{public static void main(String[]_){Scanner S=new Scanner(System.in);int i;for(double x,y,a[]=new double[6];S.hasNext();System.out.printf("%.3f %.3f\n",x,y)){for(x=y=i=0;i<6;)a[i++]=S.nextInt();if(a[1]==0&&a[4]==0){x=a[0]==0?a[5]/a[3]:a[2]/a[0];}else{if(a[0]!=0&&a[3]!=0){x=a[0];for(i=0;i<6;a[i]*=i++>2?x:a[3]);for(i=0;i<3;)a[i]-=a[i+++3];}if(a[0]!=0){y=a[5]/a[4];x=(a[2]-y*a[1])/a[0];}if(a[3]!=0){y=a[2]/a[1];x=(a[5]-y*a[4])/a[3];}}x=x==-0?0:x;y=y==-0?0:y;}}}

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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1024;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

const i64 MOD=998244353;
i64 N,S,Cnt[3010],Dp[3010][3010],inv2=(1ll+MOD>>1),Frac[3010],InvF[3010];

inline i64 fpow(i64 a,i64 x){
    i64 ans=1;
    for(;x;x>>=1,a=a*a%MOD) if(x&1) ans=ans*a%MOD;
    return ans;
}

inline i64 C(i64 n,i64 m){
    if(n<m) return 0;
    return Frac[n]*InvF[n-m]%MOD*InvF[m]%MOD;
}

inline void pre(){
    Frac[0]=1;
    f(i,1,I,3001)
        Frac[i]=Frac[i-1]*i%MOD;
    InvF[3001]=fpow(Frac[3001],MOD-2);
    g(i,3000,I,0)
        InvF[i]=InvF[i+1]*(i+1)%MOD;
}

inline i64 ans(){
    pre();
    Dp[0][0]=fpow(2,N);
    f(i,1,I,3000)
        for(i32 k=0;k<=Cnt[i];k++)
            f(j,k*i,J,S)
                Dp[i][j]=(Dp[i][j]+C(Cnt[i],k)*Dp[i-1][j-k*i]%MOD*fpow(inv2,k)%MOD)%MOD;
    return Dp[3000][S];
}

int main(){
    N=read();
    S=read();
    f(i,1,I,N) Cnt[read()]++;
    print( ans() );
    output();
    return 0;
}

Measured memory_bytes: 74224
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define N 300012
#define ll long long
#define ld long double
#define lli long long 
#define pb push_back
#define pf push_front
#define INF 1e18
// #define INF 10000000000
#define mod 1000000007
#define MOD 1000000007
#define mp make_pair
#define loop(n) for (lli i = 0; i < n; i++)
#define FOR(a,b) for (lli i = a; i < b; i+=1)
#define st(v) v.begin(),v.end()
#define F first
#define S second
#define mp make_pair
#define pii pair<lli,lli>
#define itr :: iterator it
#define w(t) cin>>t; while(t --)
#define inputarr(a,n) for(lli i=1;i<=n;i++)cin>>a[i];
#define input(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.push_back(x);}
#define printarr(a,n) for(lli i=0;i<n;i++)cout<<a[i]; cout<<endl;
#define print(vec) for(auto xt : vec)cout<<xt; cout<<endl;
#define printset(st) for(auto xt : st) cout<<xt<<" ";    cout<<endl;
struct Edge;
typedef list<Edge>::iterator iter;
// const int N=(int)(1 * 1e5 + 10);
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// // typedef tree<int,null_type,less<int>,rb_tree_tag,
// // tree_order_statistics_node_update> indexed_set;
// typedef tree<int, null_type, less_equal<int>, 
//              rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     ordered_set; 
std::vector<lli> v1;
std::vector<lli> dp(N,-1);
lli solve(lli k){

	if(dp[k]!=-1)return dp[k];

	if(k==0)return dp[k]=0;

	lli ans=0;
	for(auto x:v1){
		if(x>k)continue; 
		if(solve(k-x)==0 ){
			ans=1;
			break;
		}
	}
	return dp[k]=ans;
}

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

	lli n,k;

	
	cin>>n>>k;
	// std::vector<lli> v1;
	input(v1,n);

	cout<<((solve(k))?"First":"Second");

}

Measured memory_bytes: 10320
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int main()
{
    int n;
    
    scanf("%d",&n);
    
    char str[n+1];
    
    scanf("%s",&str);
    
    int x=0,ans=0;
    
    for(int i=0;str[i]!='\0';i++)
    {
        str[i]=='I'?x++:x--;
        
        ans=max(ans,x);
    }
    
    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 3776
#![allow(dead_code)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

use std::io::Read;
impl Scanner {
    
    fn new() -> Scanner {
        let mut buffer = String::new();
        std::io::Read::read_to_string(&mut std::io::stdin(), &mut buffer).unwrap();
        Scanner {
            line: buffer.trim().split_ascii_whitespace().collect::<Vec<&str>>().iter().map(|&s| String::from(s)).collect(),
            idx: 0,
        }
    }
    fn next<T>(&mut self) -> T 
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug, 
    {
        let ret: T = self.line[self.idx].parse::<T>().unwrap();
        self.idx += 1;
        ret
    }
    fn next_vec<T>(&mut self, n: usize) -> Vec<T> 
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug, 
    {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
    fn next_chars(&mut self) -> Vec<char> {
        let s: String = self.next();
        s.chars().collect::<Vec<char>>()
    }
}


fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(u: usize, p: usize, dp: &mut Vec<i32>, ans: &mut Vec<usize>, a: &Vec<i32>, edge: &Vec<Vec<usize>>) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    dp[idx] = a[u];
    ans[u] = lower_bound(dp, &i32::max_value());

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge);
    for x in ans {
        println!("{}", x);
    }
}


Measured memory_bytes: 65912
#include<stdio.h>
int main(){
  int i,n;
  long long int j=1;
  scanf("%d",&n);
  if(n>=1 && n<=20){
    for(i=n;i>0;i--){
      j=i*j;
    }
    printf("%lld\n",j);
  }
  return 0;
}

Measured memory_bytes: 0
while True:
    x=int(input())
    if x==0:
        break

    else: 
        otsuri=1000-x;
        a=otsuri%500
        b=a%100
        c=b%50
        d=c%10
        e=d%5
        maisuu=otsuri//500+a//100+b//50+c//10+d//5+e
        print(maisuu)


Measured memory_bytes: 5588
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int a,b,c;
	int i=0;
	int ans=0;
	cin>>a>>b>>c;
	for(i=a; i<=b; ++i){
		if(c%i==0) ++ans;


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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

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

signed main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i,N) cin >> A[i] >> B[i];
    
    const int width = 20000;
    vector<int> dp(width+1,INT_MAX);
    dp[0] = 0;
    int ans = INT_MAX;
    
    rep(i,N){
        rep(h,width){
            if(A[i] <= h){
                chmin(dp[h], dp[h-A[i]]+B[i]);
            }
        }
    }
    reps(i,H,width){
        chmin(ans, dp[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 384
import sys
from collections import deque


def main():
    n, m = map(int, sys.stdin.readline().split())

    to = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = map(int, sys.stdin.readline().split())
        to[a].append(b)
        to[b].append(a)
    INF = float("inf")

    dist = [INF] * (n + 1)
    dist[1] = 0
    pre = [0] * (n + 1)
    que = deque([])
    que.append(1)

    while que:
        p = que.popleft()
        for i in to[p]:
            if dist[i] == INF:
                dist[i] = dist[p] + 1
                pre[i] = p
                que.append(i)

    print("Yes")
    for i in range(2, n + 1):
        print(pre[i])


if __name__ == "__main__":
    main()

Measured memory_bytes: 34876
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys
T = sys.stdin.readline().rstrip()
NT = len(T)
P = sys.stdin.readline().rstrip()
NP = len(P)
if NT < NP:
    exit()
#https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
MOD = 2**61-1 #prime
A = [ord(c) for c in T]
pows = [1]*(NT+1)
shash = [0]*(NT+1)
for i in range(NT):
    pows[i+1] = (pows[i]*126)%MOD
    shash[i+1] = (shash[i]*126+A[i])%MOD
ph = 0
for i in range(NP):
    ph = (ph*126+ord(P[i]))%MOD
for i in range(len(T)-NP+1):
    if ph == (shash[i+NP]-shash[i]*pows[NP])%MOD:
        print(i)


Measured memory_bytes: 110944
import java.util.*;
public 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 D = scanner.nextInt();
        int count = 0;
        while (A > 0 && C > 0) {
            if (count % 2 == 0) {
                C = C - B;
            } else {
                A = A - D;
            }
            count++;
        }

        if (A>0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35764
#include<iostream>
#include<cstdio>

using namespace std;

#define N 194481
enum coins{ ten = 0, fifty, hundred, five_hundred, coin_max };
const int kcoin[coin_max] = {10,50,100,500};

int money_table[N][6];

inline int minimumExchange(int m, int *nums)
{
	int t = 0;
	int ans = 0;
	
	t = m / 500;
	m -= 500 * t;
	nums[3] = t;
	ans += t;

	t = m / 100;
	m -= 100 * t;
	nums[2] = t;
	ans += t;

	t = m / 50;
	m -= 50 * t;
	nums[1] = t;
	ans += t;

	t = m / 10;
	m -= 10 * t;
	nums[0] = t;
	ans += t;

	return ans;
}

int main(){
	bool bFirstDataSet = true;
	int num;
	coins coin;
	
	num = 0;
	coin = ten;
	for(int i=0;i<N;++i){
		if(i>0&&i%9261==0){ ++num; }
		money_table[i][0] += kcoin[coin] * num;
		money_table[i][1] += num;
		money_table[i][2] = num;
	}
	

	num = 0;
	coin = fifty;
	for(int i=0;i<N;++i){
		if(i>0&&i%9261==0){ num = -1; }
		if(i>0&&i%441==0){ ++num; }
		money_table[i][0] += kcoin[coin] * num;
		money_table[i][1] += num;
		money_table[i][3] = num;
	}

	num = 0;
	coin = hundred;
	for(int i=0;i<N;++i){
		if(i>0&&i%441==0){ num = -1; }
		if(i>0&&i%21==0){ ++num; }
		money_table[i][0] += kcoin[coin] * num;
		money_table[i][1] += num;
		money_table[i][4] = num;
	}

	num = 0;
	coin = five_hundred;
	for(int i=0;i<N;++i){
		if(i>0&&i%21==0){ num = -1; }
		if(i>0){ ++num; }
		money_table[i][0] += kcoin[coin] * num;
		money_table[i][1] += num;
		money_table[i][5] = num;
	}

	while(true){
		int M;
		int num_total = 0;
		int nums[coin_max] = {0,};
		int min_coins = 100;
		int ans_total = 0;
		int ans_nums[coin_max] = {0,};

		scanf("%d", &M);
		if(M==0)break;
		
		for(int i = 0; i < coin_max; ++i){
			scanf("%d", nums+i);
			num_total += nums[i];
		}

		if( !bFirstDataSet )
			printf("\n");
		bFirstDataSet = false;

		for(int i = 0; i < N; ++i){
			if( M <= money_table[i][0] ){
					int t;
					bool bSkip = false;
					int exchange_nums[coin_max];
					
					for(int j = 0; j < 4; ++j){
						if( nums[j] < money_table[i][j+2] )
							bSkip = true;
					}
					if( bSkip )
						continue;
					
					t = num_total - money_table[i][1] + minimumExchange( money_table[i][0] - M, exchange_nums );
					
					/*for(int j = 0; j < 4; ++j){
						if( nums[j] > 0 && exchange_nums[j] > 0 )
							bSkip = true;
					}
					if( bSkip )
						continue;*/

					if( min_coins > t ){
						min_coins = t;
						for(int j=0;j<4;++j)
							ans_nums[j] = money_table[i][j+2];
					}
				}
		}

		for(int i = 0; i < 4; ++i){
			if( ans_nums[i] ){
				printf("%d %d\n", kcoin[i], ans_nums[i]);
			}
		}
	}

	return 0;
}

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

int main(){
  string str, maxlen, maxfreq;
  int freq = 0, len = 0;
  map<string, int> s;
  while(cin){
    cin >> str;
    if(s.find(str) == s.end())s[str] = 0;
    s[str]++;
    if(len < str.size()){
      len = str.size();
      maxlen = str;
    }
    if(freq < s[str]){
      freq = s[str];
      maxfreq = str;
    }
  }
  cout << maxfreq << " " << maxlen << endl;
  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef long long LL; 
typedef pair<int,LL> P;//Pでpair<-,->を表す。

/*ここから*/
int V;//頂点の個数
vector<P> e[200010];//iから出る辺
P t[200010];//親情報の記録媒体

//すでにある辺と頂点の情報から木の作成
void Tree(int s){//sは一番根元
    for(int i=1;i<=V;i++){
        t[i].first=i;//初期情報
        t[i].second=0;
    }
    queue <int> q;
    q.push(s);
    while(!q.empty()){
        int from;
        from=q.front();
        q.pop();
        while(!e[from].empty()){
            P p;
            p=e[from].back();
            int to=p.first;
            e[from].pop_back();
            if(to!=t[from].first){
                t[to].first=from;
                t[to].second=p.second;
                q.push(to);
            }
        }
    }
}

int C[100010];
bool C_f[100010];
void Color(int s){
    if(s==1){C[s]=0;C_f[s]=true;}
    else{
        if(!C_f[t[s].first]){Color(t[s].first);}
        if(t[s].second%2==1){C[s]=(C[t[s].first]+1)%2;}
        else{C[s]=C[t[s].first];}
        C_f[s]=true;
    }
}

int main()
{ 
    int n;
    cin>>n;
    //基本用法
    V=n;
    for(int i=0;i<V-1;i++){
        int a,b;
        cin>>a>>b;
        LL c;
        cin>>c;
        P p;
        p.first=b;
        p.second=c;
        e[a].push_back(p);
        p.first=a;
        e[b].push_back(p);
    }
    Tree(1);
    for(int i=0;i<=V;i++){
        C[i]=0;
        C_f[i]=false;
    }
    for(int i=1;i<=V;i++){Color(i);}  
    for(int i=1;i<=V;i++){
        cout<<C[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
int h,w,ans,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
bool mp[100][100];
void dfs(int x,int y,int c){
  ans=max(ans,c);
  mp[y][x]=0;
  for(int i=0;i<4;i++)
    if(mp[dy[i]+y][dx[i]+x])dfs(x+dx[i],y+dy[i],c+1);
  mp[y][x]=1;
}
int main(){
  while(cin>>w>>h&&w){
    memset(mp,0,sizeof(mp));
    ans=0;
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)cin>>mp[i][j];
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)if(mp[i][j])dfs(j,i,1);
  cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1, 0);
  for (int X = 1; X <= 100; X++) {
    for (int Y = 1; Y <= 100; Y++) {
      for (int Z = 1; Z <= 100; Z++) {
        if (X * X + Y * Y + Z * Z + X * Y + Y * Z + Z * X <= N) {
          A.at(X * X + Y * Y + Z * Z + X * Y + Y * Z + Z * X)++;
        }
      }
    }
  }
  for (int i = 1; i <= N; i++) cout << A.at(i) << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

int main() {
	int N, M;
	
	cin >> N >> M;

	vector<int> H(N);
	vector<vector<int>> A(M, vector<int>(2, 0));
	vector<vector<int>> B(M, vector<int>(2, 0));
	int X, Y;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}

	for (int i = 0; i < M; i++){
		cin >> X >> Y;
		A[i][0] = X;
		A[i][1] = Y;
		B[i][0] = Y;
		B[i][1] = X;
	}
	vector<int> C(N, 0);
	
	for(int i = 0; i < M; i++){
		if(H[A[i][0] - 1] <= H[A[i][1] - 1]){
			C[A[i][0] - 1] = 1;
		}
		if(H[B[i][0] -1] <= H[B[i][1] - 1]){
			C[B[i][0] - 1] = 1;
		}
	}
	
	int ans = 0;
	for(int i = 0; i < N; i++){
		if(C[i] == 0){
			ans++;
		}
	}
	
	cout << ans;
	return 0;
}

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

int SelctionSort(vector<int>A, int N){
    int sw=0;
    for(int i=0;i<N-1;++i){
        int minj=i;
        for(int j=i;j<N;++j){
          if(A[j]<A[minj]) minj=j;
        }
        swap(A[i], A[minj]);
        if(i!=minj) ++sw;
    }
    for(int i=0;i<N;++i){
        if(i!=N-1) cout << A[i] <<" ";
        else cout << A[i];
    }
    cout << endl;
    return sw;
}

int main() {
    int N; cin >> N; vector<int> A(N);
    for(int i=0;i<N;++i) cin >> A[i];
    int sw = SelctionSort(A, N);
    
    cout << sw << endl;
    return 0;
}

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

int n, a = 0, b = 0;
string s, t;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s >> t;
		if (s == t) {
			a++;
			b++;
		}
		else if (s < t) {
			b += 3;
		}
		else {
			a += 3;
		}
	}
	cout << a << " " << b << endl;


	return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N_MAX = 10000;
typedef pair<int,int> P;
int main()
{
  int a,b,res;
  cin >> a >> b;
  if(a==b) res=a*2;
  else if(a>b) res=a*2-1;
  else res=b*2-1;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Array.IArray
import Control.Monad

main :: IO ()
main = do
    [h,w] <- map read . words <$> getLine :: IO [Int]
    s <- BS.unpack . BS.concat . BS.lines <$> BS.getContents
    let a = listArray ((0,0),(w-1,h-1)) s :: Array (Int,Int) Char
    let ans = do
        i <- [0..w-1]
        j <- [0..h-1]
        guard $ a!(i,j) == '#'
        return $ i > 0 && a!(i-1,j) == '#'
              || i < w-1 && a!(i+1,j) == '#'
              || j > 0 && a!(i,j-1) == '#'
              || j < h-1 && a!(i,j+1) == '#'
    putStrLn $
        if all (==True) ans then "Yes" else "No"


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'

int32_t main()
{
	ninja
	int t; 
	cin>>t;
	string s;
	map<string, int> mp;
	while(t--){
		cin>>s;
		mp[s]++;
	}
	cout<<mp.size();
}



Measured memory_bytes: 19240
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



N = int(input())
An = list(map(int, sys.stdin.readline().rstrip().split()))

Bn = {}
for a in An:
  if a not in Bn:
    Bn[a] = 1
  else:
    Bn[a] += 1

ans = 0
for b in Bn:
  if Bn[b] < b:
    ans += Bn[b]
  else:
    ans += Bn[b] - b

print(ans)

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

int main(){

  while(1){
      int x, y;
      cin>>x>>y;
      if (x == 0 && y == 0) break;


      if(x > y) swap(x, y);
      cout<<x<<" "<<y<<endl;
  }

  return 0;
}




Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
template<class T>struct SegTree{
	T *dat;
	int n;
	SegTree(int size = 1000000){
		for(n = 1; n < size; n *= 2);
		dat = new T[2 * n - 1];
		init();
	}
	~SegTree(){ delete [] dat; }
	
	void init(){
		rep(i, 2 * n - 1) dat[i] = pi(127, -1);
	}
	void update(int k, T a){
		k += n - 1;
		dat[k] = a;
		
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return pi(127, -1);
		if(a <= l && r <= b) return dat[k];
		
		T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		
		return min(vl, vr);
	}
	T query(int a, int b){ return query(a, b, 0, 0, n); }
};
const int MX = 200010;
int bit[MX];
int sum(int i){
	int s = 0;
	for(; i; i -= i & -i) s += bit[i];
	return s;
}
void add(int i, int x){
	for(; i < MX; i += i & -i) bit[i] += x;
}
inline int find(int k){
	int lo = 0, hi = 1 << 32 - __builtin_clz(MX), mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(mid > MX || bit[mid] >= k) hi = mid;
		else k -= bit[lo = mid];
	}
	return hi;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string s, ans;
	int k;
	cin >> s >> k;
	int n = s.size();
	SegTree<pi> seg(n);
	rep(i, n) seg.update(i, pi(s[i], i));
	rep(i, n) add(i + 1, 1);
	
	rep(i, n){
		int r = min(n, find(k + 1)); //dbg(i, r);
		pi c = seg.query(0, r);
		ans += c.first;
		k -= sum(c.second);
		add(c.second + 1, -1);
		seg.update(c.second, pi(127, -1));
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 8420
from math import gcd
from collections import deque
from bisect import bisect_left,bisect_right

q=int(input())
lr=[tuple(map(int,input().split())) for _ in range(q)]

rmax=max(e[1] for e in lr)
anslst=[]
candlst=deque([2])
pprod=2
for i in range(3,rmax+1,2):
  tmp=2*candlst[0]-1
  if gcd(pprod,i)==1: 
    candlst.append(i)
    pprod*=i
    if tmp==i:
      anslst.append(tmp)
  if tmp==i:
    candlst.popleft()

for e in lr:
  print(bisect_right(anslst,e[1])-bisect_left(anslst,e[0]))

Measured memory_bytes: 23036
import java.util.*;
import java.util.stream.*;
import java.io.*;


class Monster implements Comparable<Monster> {
    final long x, h;

    Monster(long x, long h){
        this.x = x;
        this.h = h;
    }

    public int compareTo(Monster m){
        return Long.compare(this.x, m.x);
    }
}

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in1 = br.readLine().split(" ");
        long N = Long.parseLong(in1[0]);
        long D = Long.parseLong(in1[1]);
        long A = Long.parseLong(in1[2]);
        List<Monster> monsters = new ArrayList<>();
        for(int i = 0; i < N; i++){
            in1 = br.readLine().split(" ");
            long X = Long.parseLong(in1[0]);
            long H = Long.parseLong(in1[1]);
            monsters.add(new Monster(X, H));
        }
        br.close();

        Collections.sort(monsters);
        Queue<long[]> position = new ArrayDeque<>();
        long tmp_attack_count = 0L;
        long total_attack_count = 0L;

        for(int n = 0; n < N; n++){

            long now_x = monsters.get(n).x;
            long now_h = monsters.get(n).h;

            while(!position.isEmpty() && position.peek()[0] + 2 * D < now_x){
                tmp_attack_count -= position.poll()[1];
            }

            long attack_count = (now_h - tmp_attack_count * A + A - 1L) / A;
            if(attack_count <= 0) continue;

            total_attack_count += attack_count;
            tmp_attack_count += attack_count;
            position.add(new long[] {now_x, attack_count});
        }

        System.out.println(total_attack_count);
    }
}

Measured memory_bytes: 63356
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int a,b;
    string ans="Positive";
    cin>>a>>b;
    if(a*b<=0)ans="Zero";
    else if(b<0&&(b-a)%2==0)ans="Negative";
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

const int MAX_H = 32, MAX_W = 32;
int H, W;
int F[MAX_H][MAX_W];
int sum[MAX_H + 1][MAX_W + 1];
void init() {
    for (int i = 0; i <= H; i++) sum[i][0] = 0;
    for (int j = 0; j <= W; j++) sum[0][j] = 0;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + F[i][j];
}
// (y, x) \in [sy, gy) × [sx, gx) を満たす(y, x)について, F[y][x]の総和を返す
int getSum(int sy, int sx, int gy, int gx) {
    return sum[gy][gx] - sum[gy][sx] - sum[sy][gx] + sum[sy][sx];
}

int S;
bool Input() {
    cin >> H >> W >> S;
    if (H == 0 && W == 0 && S == 0) return false;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> F[i][j];
    return true;
}

const int INF = 1<<28;

int u;
pair<int, int> memo[MAX_H][MAX_W][MAX_H + 1][MAX_W + 1];
pair<int, int> dfs(int sy, int sx, int gy, int gx) {
    if (memo[sy][sx][gy][gx].first >= 0) return memo[sy][sx][gy][gx];
    if (getSum(sy, sx, gy, gx) < u) return make_pair(0, 0);
    pair<int, int> ret = make_pair(1, getSum(sy, sx, gy, gx));
    for (int y = sy + 1; y < gy; y++) {
        pair<int, int> p = dfs(sy, sx, y, gx);
        pair<int, int> q = dfs(y, sx, gy, gx);
        ret = max(ret, make_pair(p.first + q.first, min(p.second, q.second)));
    }
    for (int x = sx + 1; x < gx; x++) {
        pair<int, int> p = dfs(sy, sx, gy, x);
        pair<int, int> q = dfs(sy, x, gy, gx);
        ret = max(ret, make_pair(p.first + q.first, min(p.second, q.second)));
    }
    return memo[sy][sx][gy][gx] = ret;
}
void Solve() {
    init();
    u = getSum(0, 0, H, W) - S;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        for (int y = 0; y <= H; y++) for (int x = 0; x <= W; x++) {
            memo[i][j][y][x] = make_pair(-1, -1);
        }
    }
    pair<int, int> Ans = dfs(0, 0, H, W);
    cout << Ans.first << " " << Ans.second - u << endl;
}

int main() {
    while (Input()) Solve();
    return 0;
}

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

using namespace std;
using ll = long long;
int main(){

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

    ll a, b, c;
    cin >> a >> b >> c;

    ll cnt = 0LL;

    if(a+b >= c-1){
        cout << c+b << endl;
    }
    else{
        cout << (a+2*b+1) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import bisect
from itertools import accumulate

n, m, k = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))

aaa = [0] + list(accumulate(aaa))
bbb = [0] + list(accumulate(bbb))


ans = 0
for i in range(len(aaa)):
    rest = k - aaa[i]
    if rest >= 0:
        div = bisect.bisect_right(bbb, rest) - 1
        ans = max(ans, i + div)

print(ans)

Measured memory_bytes: 41300
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef long double ld;
#define rep(i,s,t) for(ll i=s ; i<t ; i++)
//typedef pair<int,int> P;
//typedef pair<int,P> pp;
const int INF = 1e5;
string s[20];
int h,w;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const ll mod = 1e9+7;
vector<vector<pair<int,int> > > G;
vector<int> color;
void dfs(int i, int pre, int pre_c){
  int cnt = 1;
  for(auto ni:G[i]){
    if(ni.fi == pre) continue;
    if(cnt == pre_c) cnt++;

    color[ni.se] = cnt;
    dfs(ni.fi, i, cnt);
    cnt++;
  }
}
int main(){
  int n;  cin >> n;
  G.resize(n);
  color.resize(n-1);
  rep(i,0,n-1){
    int x,y;  cin >> x >> y;
    --x;  --y;
    G[x].push_back(make_pair(y,i));
    G[y].push_back(make_pair(x,i));
  }
  int maxc = 0, start = 0;
  rep(i,0,n){
    if(maxc<G[i].size()){
      maxc = G[i].size();
      start = i;
    }
  }
  cout << maxc << endl;
  dfs(0,-1,-1);
  rep(i,0,n-1){
    cout << color[i] << endl;
  }
  return 0;
}


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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var fst = Console.ReadLine().Split();
            var s = fst[0];
            var t = fst[1];

            var scd = Console.ReadLine().Split();
            var a = int.Parse(scd[0]);
            var b = int.Parse(scd[1]);

            var u = Console.ReadLine().Trim();

            if(u.Equals(s)){
                a -= 1;
            }else if(u.Equals(t)){
                b -= 1;
            }

            Console.WriteLine(string.Format("{0} {1}",a,b));
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0){
      continue;
    }
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=WHITE;
  }
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE){
      dfs_visit(u);
    }
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

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

int main()
{
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int c, a, n, m = 0, m0 = -1;
		cin >> c >> a >> n;

		while (m > m0) {
			m0 = m;

			if (c > 0 && a > 0 && n > 0) {
				m++;
				c--;
				a--;
				n--;
			}
			else if (c > 1 && a > 0) {
				m++;
				c -= 2;
				a--;
			}
			else if (c > 2) {
				m++;
				c -= 3;
			}
		}

		cout << m << endl;
	}

	return 0;
}



Measured memory_bytes: 3100
// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba-064a5016a 

#include <bits/stdc++.h>
using namespace std;
#define int     long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod ((int)(1e9 + 7))
signed main()
{
	fast_io
	int h, w;
	cin >> h >> w;
	int dp[h + 1][w + 1];    
	char grid[h + 1][w + 1]; // # or .

	for(int i = 0; i <= h; i++)
		for(int j = 0; j <= w; j++)
			dp[i][j] = 0;
	for(int i = 1; i <= h; i++)
		for(int j = 1; j <= w; j++)
			cin >> grid[i][j];

	dp[1][1] = 1;
	for(int i = 1; i <= h; i++)
	{
		for(int j = 1; j <= w; j++)
		{
			if(grid[i][j] == '#')
				continue;
			if(i - 1 >= 1)
				dp[i][j] = (dp[i][j] + dp[i - 1][j])%mod;
			if(j - 1 >= 1)
				dp[i][j] = (dp[i][j] + dp[i][j - 1])%mod;
		}
	}
	cout << dp[h][w] << endl;
}

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

int main() {
  int n,ans = 1;
  cin >> n;
  while(1){
    if(ans*2 > n) break;
    ans *= 2;
  }
  cout << ans << endl;
}

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

const double PI = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double th = double(h*60+m)/720 * 2*PI;
  double tm = double(m)/60 * 2*PI;
  double xh = a*cos(th), yh = a*sin(th);
  double xm = b*cos(tm), ym = b*sin(tm);
  double dx = xh-xm, dy = yh-ym;
  double ans = sqrt(dx*dx + dy*dy);
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 4036
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, K, Q;
    cin >> N >> K >> Q;

    ll Aans[N + 1];
    REP(i, N){
        Aans[i] = 0;
    }

    ll A;
    REP(i, Q){
        cin >> A;
        Aans[A]++;
    }

    REP(i, N){
        if(Q - Aans[i] < K){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4392
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def main():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [INF]*(n+1)
    dp[0] = 0

    for i in range(n):
        for j in range(1,k+1):
            if i+j>=n:
                break
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp[n-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 55136
s = input()
t = input()

def henkan(s, t):
  #a~zまでのリスト
  list = [chr(i) for i in range(97, 97+26)]
  #a~zまでの辞書
  dic = dict.fromkeys(list, 0)
  
  #sの文字を一つずつ見ていく
  for i in range(len(s)):
  #辞書にない文字だったら 辞書(s[i]) = t[i]
    if dic[s[i]] == 0:
      dic[s[i]] = t[i]
    
  #辞書にある文字だったら 辞書(s[i]) != t[i] だったら　return 0
    else:
      if dic[s[i]] != t[i]:
        return 0
  #最後まで行ったら return 1
  return 1
  
if henkan(s, t) and henkan(t, s):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


int main() 
{
	// ios::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	
	ll n,W;
	cin>>n>>W;
	vector<ll> w(n),v(n);
	ll sum = 0;
	loop(i,0,n){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}

	vector<ll> dp(sum+1,INT_MAX);

	dp[0] = 0;

	loop(i,1,n+1){
		for(ll sl = sum-v[i-1];sl>=0;sl--)
			dp[sl+v[i-1]] = min(dp[sl+v[i-1]],dp[sl] + w[i-1]);

	}
	ll ans = 0;

	loop(i,1,sum+1){
		if(dp[i]<=W)
			ans = i;
	}

	cout<<ans;
}

Measured memory_bytes: 4064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 2000000;
const ll MOD = 1000000007;
ll n, k, r, s, p;
string t;

int main() {
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    ll rNum = 0;
    ll sNum = 0;
    ll pNum = 0;
    ll score = 0;
    for(ll i=0; i<n; i++){
        if(i<k){
            if(t[i]=='r')rNum++;
            if(t[i]=='s')sNum++;
            if(t[i]=='p')pNum++;
        }else{
            if(t[i-k]==t[i]){
                t.replace(i,1,"X");
            }else{
                if(t[i]=='r')rNum++;
                if(t[i]=='s')sNum++;
                if(t[i]=='p')pNum++;
            }
        }
    }
    score = rNum * p + sNum * r + pNum * s;
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
  int A[3];
  rep(i,3) cin >> A[i];

  int ans = 1e9;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (i == j || j == k || i == k) continue;
        ans = min(ans, abs(A[i]-A[j]) + abs(A[j]-A[k]));
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	vector<int>A(N);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	cout << A[N - 1] - A[0] << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
      double D=double.Parse(str[0]);
      double T=double.Parse(str[1]);
      double S=double.Parse(str[2]);
      if((D/S)<=T){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }
    }
    
  }

}


Measured memory_bytes: 27520
def main():
    N = int(input() )
    S = [i for i in input().split() ]
#    print(S)
    
    remove_overlap_S = list(set(S) )
#    print(remove_overlap_S)
    
    if(len(remove_overlap_S ) < 4):
        print("Three")
    else:
        print("Four")
    
if __name__=="__main__":
    main()

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

class Node{
	public:
		Node* prev;
		Node* next;
		int data;
		Node(){
			prev=0;
			next=0;
			data=0;
		}
};

class List{
	private:
		Node head;
	public:
		List(){
			head.prev=&head;
			head.next=&head;
		}
		int insert(int x);
		int del(int x);
		int deleteFirst();
		int deleteLast();
		void print();
};

int List::insert(int x){
	Node* p=new Node();
	if(p==0){
		return -1;
	}
	Node* q=&head;
	Node* r=head.next;
	p->prev=q;
	p->next=r;
	p->data=x;
	q->next=p;
	r->prev=p;
	return 0;
}

int List::del(int x){
	Node* p;
	for(p=head.next;p!=&head;p=p->next){
		if(p->data==x){
			break;
		}
	}
	if(p==&head){
		return -2;
	}
	Node* q=p->prev;
	Node* r=p->next;
	q->next=r;
	r->prev=q;
	delete p;
	return 0;
}

int List::deleteFirst(){
	Node* p=head.next;
	if(p==&head){
		return -2;
	}
	Node* q=p->prev;
	Node* r=p->next;
	q->next=r;
	r->prev=q;
	delete p;
	return 0;
}
	
int List::deleteLast(){
	Node* p=head.prev;
	if(p==&head){
		return -2;
	}
	Node* q=p->prev;
	Node* r=p->next;
	q->next=r;
	r->prev=q;
	delete p;
	return 0;
}

void List::print(){
	for(Node* p=head.next;p!=&head;p=p->next){
		cout<<p->data;
		if(p->next!=&head){
			cout<<' ';
		}else{
			cout<<endl;
		}
	}
}

int main(){
	List L;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		char com[20];
		cin>>com;
		if(com[0]=='i'){
			int x;
			cin>>x;
			L.insert(x);
		}else if(com[6]=='F'){
			L.deleteFirst();
		}else if(com[6]=='L'){
			L.deleteLast();
		}else{
			int x;
			cin>>x;
			L.del(x);
		}
	}
	L.print();

	return 0;
}

Measured memory_bytes: 34300
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicLong;

public class Main {

	static long first = -1;
	static int w = -1;

	// 14:33-
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		int n = sc.nextInt();
		w = sc.nextInt();

		ArrayList[] ws = new ArrayList[4];
		for (int i = 0; i < ws.length; i++) ws[i] = new ArrayList();

		for (int i = 0; i < n; i++) {
			int wi = sc.nextInt();
			if (i == 0) first = wi;
			int vi = sc.nextInt();

			ws[(int) (wi - first)].add(vi);
		}

		for (int i = 0; i < ws.length; i++) Collections.sort(ws[i]);

		ArrayList[] prf = new ArrayList[4];
		for (int i = 0; i < prf.length; i++) {
			prf[i] = new ArrayList();
			prf[i].add(0L);
		}

		for (int i = 0; i < ws.length; i++) {
			int k = 1;
			int lastElem = ws[i].size() - 1;
			for (int j = lastElem; j >= 0; j--) {
				long val = (Integer) ws[i].get(j);
				val += (long) prf[i].get(k-1);
				prf[i].add(val);
				k++;
			}
		}


		AtomicLong max = new AtomicLong();
		int[] choice = new int[4];
		doit(choice, ws, prf, 0, max);

		System.out.println(max.get());
	}

	private static void doit(int[] choice, ArrayList[] ws, ArrayList[] prf, int pos, AtomicLong max) {
		if (pos == ws.length) {
			long avail = w;
			long worth = 0;
			for (int i = 0; i < choice.length; i++) {
				avail -= choice[i] * (first + i);
				if (avail < 0) break;
//				for (int j = 0; j < choice[i]; j++) worth += (Integer) ws[i].get(ws[i].size() - 1 - j);
				worth += (long) prf[i].get(choice[i]);
			}
			if (avail >= 0) max.set(Math.max(worth, max.get()));
			return;
		}

		for (int i = 0; i <= ws[pos].size(); i++) {
			choice[pos] = i;
			doit(choice, ws, prf, pos + 1, max);
		}
	}
}


Measured memory_bytes: 23508
#include <cstdio>
#include <cstring>

int h, w;
char s[6];

int main(){
	scanf("%d %d", &h, &w);
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j){
			scanf("%s", s);
			if(strcmp(s, "snuke") == 0) printf("%c%d\n", 'A'+j, i+1);
		}
}

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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
int was[N];
int deg[N];

int main () {
   SpeedForce;
	cin >> s;
	s = '#' + s;
	n = sz(s);
	for (int i = 1; i < n; i ++) {
		if (s[i] == '<') g[i].pb(i+1), u[i+1] = 1;
		else g[i+1].pb(i), u[i] = 1;
	}

	queue < int > q;
	for (int i = 1; i <= n; i ++) if (!u[i]) {
		was[i] = 1;
		q.push(i);
	}
	for (int i = 1; i <= n; i ++) deg[i] = sz(g[i]);

	while (q.size()) {
		int v = q.front();
		q.pop();

		for (auto to : g[v]) {
			deg[to]--;
			if (!deg[to]) {
				was[to] = 1;
				q.push(to);
			}
			a[to] = max(a[to], a[v] + 1);
		}
	}
	
	cout << accumulate(a + 1, a + n + 1, 0ll);
   return Accepted;
}

// B...a


Measured memory_bytes: 40880