akhauriyash/Code-Regression huggingface dataset:
#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;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	string s; cin >> s;
	string r = "";
	for(int i = 0 ; i < (int)s.size() ; i++){
		if(s[i] == 'B' && (int)r.size() > 0)
			r=r.substr(0,r.size()-1);
		else if(s[i] != 'B')
			r+=s[i];
	}
	cout<<r;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	while(T--){
		test_case();
	}
	return 0;
}


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

int main() {
  int k,a,b;
  cin>>k>>a>>b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
}


Measured memory_bytes: 3552
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000//10^12
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define PI acos(-1)

using namespace std;


//void型なので返り値は無し　d[]に結果が格納されるので欲しいものをansに
int main(void)
{
	//変数の宣言
	int n;
	double x[110];
	double y[110];
	double a,b,c;
	int map[110][110];
	double slope1,slope2;
	double probab[110];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);


	for(i=0;i<n;i++){
		scanf("%lf %lf",&x[i],&y[i]);
//		scanf_s("%lf %lf",&x[i],&y[i]);
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

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

	if(n==2){
		printf("0.5\n0.5\n");
		return 0;
	}

	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			a=y[j]-y[i];
			b=x[i]-x[j];
			c=x[i]*y[j]-x[j]*y[i];
			flag=0;
			for(k=0;k<n;k++){
				if(flag==0){
					if(a*x[k]+b*y[k]-c>0){
						flag=1;
					}else if(a*x[k]+b*y[k]-c<0){
						flag=-1;
					}else{
						if((x[i]-x[k])*(x[k]-x[j])<0||(y[i]-y[k])*(y[k]-y[j])<0){
							flag=-2;
							break;
						}
					}
				}else{
					if(flag==-1&&a*x[k]+b*y[k]-c>0){
						flag=-2;
						break;
					}else if(flag==1&&a*x[k]+b*y[k]-c<0){
						flag=-2;
						break;
					}else{
						if(a*x[k]+b*y[k]-c==0&&((x[i]-x[k])*(x[k]-x[j])<0||(y[i]-y[k])*(y[k]-y[j])<0)){
							flag=-2;
							break;
						}
					}
				}
			}
			if(flag==0){
				temp1=i;
				temp2=j;
				for(i=0;i<n;i++){
					if(i==temp1||i==temp2){
						printf("0.5\n");
					}else{
						printf("0\n");
					}
				}
				return 0;
			}else if(flag!=-2){
				map[i][j]=flag;
				map[j][i]=flag;
			}
		}
	}
/*	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			printf("%d ",map[i][j]);
		}
		printf("\n");
	}*/
	for(i=0;i<n;i++){
		temp1=-1;
		temp2=-1;
		temp=1;
		for(j=0;j<n;j++){
			if(abs(map[i][j])==1){
				temp=temp*map[i][j];
				temp2=temp1;
				temp1=j;
			}
		}

		if(temp1==-1){
			probab[i]=0;
			continue;
		}

		if(x[i]==x[temp1]){
			slope1=90;
		}else{
			slope1=(180/PI)*atan((y[temp1]-y[i])/(x[temp1]-x[i]));
		}
		if(x[i]==x[temp2]){
			slope2=90;
		}else{
			slope2=(180/PI)*atan((y[temp2]-y[i])/(x[temp2]-x[i]));
		}
		
		probab[i]=fabs(slope1-slope2)/360;

		if((x[temp1]-x[i])*(x[temp2]-x[i])>0){
			probab[i]=0.5-probab[i];
		}else if(x[temp1]==x[i]&&(y[i]-y[temp1])*(x[temp2]-x[i])<0){
			probab[i]=0.5-probab[i];
		}else if(x[temp2]==x[i]&&(y[i]-y[temp2])*(x[temp1]-x[i])<0){
			probab[i]=0.5-probab[i];
		}
	}


	//	printf("計算部分終了\n");

	//出力
	
	for(i=0;i<n;i++){
		printf("%1.10lf\n",probab[i]);
	}

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<vector>

using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64, i64>;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n;
    string s;
    cin >> s;
    n = s.size();
    vector<vector<i64>> dp(100005, vector<i64>(13, 0));
    dp[0][0] = 1;
    rep(i, n) {
        i64 c;
        if (s[i] == '?') c = -1;
        else c = s[i] - '0';

        rep(j, 10) {
            if (c != -1 && c != j)continue;
            rep(k, 13) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        rep(j, 13)dp[i + 1][j] %= 1000000007;
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 16640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
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; }

signed main() {
    int K, X;
    cin >> K >> X;
    if (K*500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import nsmallest

s = input()
K = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, min(i + 6, len(s) + 1)):
        subs.add(s[i:j])
arr = list(subs)
print(nsmallest(K, arr)[-1])


Measured memory_bytes: 4592
#!/usr/bin/env pypy3


import functools
import sys


MAXSIZE = 2 ** 16
REC_LIMIT = 10000


def main():
    N, W = (int(x) for x in input().split())
    w = [-1 for _ in range(N)]
    v = [-1 for _ in range(N)]
    for i in range(N):
        w[i], v[i] = (int(x) for x in input().split())

    @functools.lru_cache(maxsize=MAXSIZE)
    def rec(i, j):
        if i == N:
            res = 0
        elif j < w[i]:
            res = rec(i + 1, j)
        else:
            res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])
        return res
    ans = rec(0, W)
    print(ans)


if __name__ == '__main__':
    sys.setrecursionlimit(REC_LIMIT)
    main()


Measured memory_bytes: 104536
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
LIMIT = 10 ** 18
n=int(input())
#a=(int,read.split())
a=[int(i) for i in input().split()]
if 0 in a:
	print(0)
	exit()

ans = 1
for i in a:
	ans *= i
	if ans > LIMIT:
		print(-1)
		exit()
print(ans)
	

Measured memory_bytes: 21592
fn solve(s: &str, t: &str) -> String {
    let sn = s.len();
    let tn = t.len();
    let s = s.chars().collect::<Vec<_>>();
    let t = t.chars().collect::<Vec<_>>();

    let mut dp = vec![vec![0; tn + 1]; sn + 1];

    for i in 0..sn {
        let sc = s[i];
        for j in 0..tn {
            let tc = t[j];
            if sc == tc {
                dp[i + 1][j + 1] = dp[i][j] + 1
            } else {
                if dp[i][j + 1] > dp[i + 1][j] {
                    dp[i + 1][j + 1] = dp[i][j + 1];
                } else {
                    dp[i + 1][j + 1] = dp[i + 1][j];
                }
            }
        }
    }

    let mut i = sn;
    let mut j = tn;
    let mut ans = "".to_owned();

    while i > 0 && j > 0 {
        if s[i - 1] == t[j - 1] {
            ans.push(s[i - 1]);
            i -= 1;
            j -= 1;
        } else if dp[i][j] == dp[i][j - 1] {
            j -= 1;
        } else {
            i -= 1;
        }
    }

    ans.chars().rev().collect()
}

#[test]
fn solve_test() {
    assert_eq!(solve("axyb", "abyxb"), "ayb".to_owned());
    assert_eq!(solve("aa", "xayaz"), "aa".to_owned());
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let s = read_line!();
    let t = read_line!();

    println!("{}", solve(&s, &t));
}


Measured memory_bytes: 41212
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int countA = 0,countB = 0;
        for(int i = 0;i<s.length;i++){
            if(i%2==0){
                if(s[i]=='1'){
                    countA ++;
                }
                if(s[i]=='0'){
                    countB++;
                }
            }
            if(i%2!=0){
                if(s[i]=='0'){
                    countA ++;
                }
                if(s[i]=='1'){
                    countB ++;
                }
            }
        }
        System.out.println(Math.min(countA,countB));
    }
}


Measured memory_bytes: 25836
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    Vpll pos, neg;
    string w;
    string s[n];
    rep(i,0,n){
        cin>>s[i];
        ll n = s[i].length();
        ll a=0, b=0;
        rep(j,0,n){
            if(s[i][j]=='(')   b++;
            else b--;
            a=min(a,b);
        }   
        if(a<0){
            if(b<0) neg.pb({a-b,i});
            else pos.pb({a,i});
        }
        else{
            w += s[i];
        }
    }
    sort(all(pos));
    reverse(all(pos));
    sort(all(neg));
    for(auto i:pos) w+=s[i.sd];
    for(auto i:neg) w+=s[i.sd];
    ll tot=0,f=0;
    for(auto i:w){
        if(i=='(')  tot++;
        else tot--;
        if(tot<0)   f=1;
    }
    if(tot!=0)  f=1;
    if(f)   cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 45200
a,b,c=gets.split
a=a.to_i
b=b.to_i
c=c.to_i
sum=a+b+c

if a==b && b==c && a%2==0 && b%2==0&& c%2==0
    puts -1
    exit
end

i=0
loop{
   
   if a%2==1 || b%2==1 || c%2==1
       puts i
       exit
   end
       
       i+=1
       a,b,c=(sum-a)/2,(sum-b)/2,(sum-c)/2
   
}


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(){
  int n,m;//n:カード枚数 m:ゲート数
  cin>>n>>m;
  int s,e,start,end=n,count=0;
  while(count!=m){
    cin>>s>>e;
    if(count==0||s>start)start=s;
    if(e<end)end=e;
    count++;
  }
  if(end>=start)cout<<end-start+1<<endl;
  else cout<<0;
}



Measured memory_bytes: 256
l = gets.chomp
n = l.size
M = 10 ** 9 + 7

def pow(x, n)
    n == 0 ? 1 : (n.odd? ? x : 1) * pow(x ** 2 % M, n / 2) % M
end

fac = Array.new(n+1, 1)
1.upto(n) {|i| fac[i] = fac[i-1] * i % M}

rfac = Array.new(n+1)
rfac[-1] = pow(fac[-1], M - 2)
(n-1).downto(0) {|i| rfac[i] = rfac[i+1] * (i+1) % M}

ans = 0
t = 1
n.times do |i|
    next if l[i] == ?0
    ans = (ans + pow(3, n-i-1) * t % M) % M
    t = t * 2 % M
end

p (ans + t) % M

Measured memory_bytes: 3580
#include <iostream>

using namespace std;
typedef long long ll;
int main()
{
string s,t;
cin>>s;
cin>>t;
int l1= s.length();
int l2=t.length();
int dp[l1+1][l2+1];
for(int i=0;i<=l1;i++){
    for(int j=0;j<=l2;j++){
        if(i==0 || j==0){
            dp[i][j]=0;
        }
        else{
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
}
int count=dp[l1][l2];
string ans[count];
ll k=count-1;
int i1=l1;
int j1=l2;
while(i1!=0 && j1!=0){
    if(dp[i1][j1]==max(dp[i1-1][j1],dp[i1][j1-1])){
        if(dp[i1-1][j1]>dp[i1][j1-1]){
            i1--;
        }
        else{
            j1--;
        }
    }
    else{
        ans[k]=s[i1-1];
        k--;
        i1--;
        j1--;
    }
}
for(int i=0;i<count;i++){
    cout<<ans[i];
} 

return 0;
}


Measured memory_bytes: 38864
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    string s;
    cin >> s;
    if(s[0]==s[2])cout << "Yes" << endl;
    else cout << "No" << endl;
 }


Measured memory_bytes: 256
s = input()
N = len( s )
K = int( input() )

s_set = set()
for j in range( 1, K + 1 ):
  for i in range( N - j + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

print( sorted( list( s_set ) )[ K - 1 ] )

Measured memory_bytes: 4592
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    ll ans = 0;
    sort(v.rbegin(),v.rend());
    ans += v[0];
    int i = 0;
    int cnt = 2;
    n--;
    while(--n){
        // cout << cnt << endl;
        // cout << ans << endl;
        if(cnt %2 == 0) i++;
        ans += v[i];
        cnt++;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int n,ans=0;
    string ar;
    string dr;
    cin>>n;
    cin>>ar;
    int red=0,w=0;
    for(int i=0; ar[i]!='\0'; i++)
    {
        if(ar[i]=='R')
            red++;
        else
            w++;
    }
    while(red--)
    {
        dr+='R';
    }
    while(w--)
    {
        dr+='W';
    }
    for(int i=0; ar[i]!='\0'; i++)
    {
        if(ar[i]!=dr[i])
        {
            ans++;
        }
    }
    cout<<ans/2;
}


Measured memory_bytes: 3848
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(var,init,end) for(int var=init;var<end;var++)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int facctorialMethod(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

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

	if (n > 999) {
		cout << "ABD";
	}
	else {
		cout << "ABC";
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a, b, c, x, y;
	scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
	if (x > y) {
		Swap(&a, &b);
		Swap(&x, &y);
	}
	int ans = 1e9;
	int money1, money2,money3;
	money1 = a*x + b*x;
	money2 = b*(y - x);
	if (money1 + money2 < ans)ans = money1 + money2;
	money3 = c*(y - x) * 2;
	if (money1 + money3 < ans)ans = money1 + money3;
	money1 = c * x * 2;
	if (money1 + money2 < ans)ans = money1 + money2;
	if (money1 + money3 < ans)ans = money1 + money3;
	PRINTD(ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
constexpr ll INF = 1000000007;

int main() {
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC\n";
    else if (s == "ARC") cout << "ABC\n";
    
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define int long long 
 
 
const int inf = 1e18L;
 
signed main(){
	int n,w;
	cin>>n>>w;
	vector<pair<int,int>> a(n);
	int s=0;
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
		s+=a[i].second;
	}
 
	vector<int> dp(s+1,inf);
	// dp[i]-represents the minimum weight using values atleast i
	
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=s-a[i].second;j>=0;j--){
			dp[j+a[i].second]=min(dp[j+a[i].second],dp[j]+a[i].first);
		}
	}
 
	int ans=0;
	for(int i=0;i<=s;i++){
		if(dp[i]<=w){
			ans=i;
		}
	}
 
	cout<<ans<<endl;
 
}

Measured memory_bytes: 1024
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
l=[0,0,0]

for i in range(N):
    if P[i]<=A:
        l[0]=l[0]+1
    elif P[i]<=B:
        l[1]=l[1]+1
    else:
        l[2]=l[2]+1
print(min(l))

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

struct BIT{
    int n;
    vector<int> v;

    BIT(int _n) : n(_n){
        v.resize(n+1, 0);
    }

    void add(int i, int x){
        while(i <= n){
            v[i] += x;
            i += i&-i;
        }
    }

    int sum(int i){
        int ret = 0;
        while(i > 0){
            ret += v[i];
            i -= i&-i;
        }
        return ret;
    }
};

typedef pair<int,int> pii;
typedef long long ll;
const int mod = 998244353;

int main(){
    int n;
    cin >> n;
    vector<pii> vp;
    vector<int> y;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        vp.push_back({a,b});
        y.push_back(b);
    }
    sort(y.begin(), y.end());
    BIT bit(n);
    for(int i = 1; i <= n; i++) bit.add(i, 1);
    sort(vp.begin(), vp.end());
    vector<ll> fact(n+1, 1);
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*2%mod;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int down = lower_bound(y.begin(),y.end(),vp[i].second)-y.begin();
        int up = n-1-down;
        bit.add(down+1, -1);
        
        // select vp[i]
        (ans += fact[n-1]) %= mod;   
        
        int s[4];
        s[3] = bit.sum(down+1);
        s[1] = bit.sum(n)-bit.sum(down+1);
        s[2] = down-s[3];
        s[0] = up-s[1];
        bool all = true;
        ll alladd = 1;
        for(int x = 0; x < 4; x++){
            all &= s[x]>0;
            (alladd *= fact[s[x]]-1) %= mod;
            if(x < 2 && s[x] > 0 && s[3-x] > 0){
                (ans += (fact[s[x]]-1)*(fact[s[3-x]]-1)%mod) %= mod;
            }
            bool ok = true;
            ll tmp = 1;
            for(int y = 0; y < 4; y++){
                if(x != y)  ok &= s[y]>0, (tmp *= fact[s[y]]-1) %= mod;
            }
            if(ok)  (ans += tmp) %= mod;
        }
        if(all) (ans += alladd) %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5232
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    HashMap<Character,Integer> dictCI = new HashMap<Character,Integer>();
    HashMap<Integer,Character> dictIC = new HashMap<Integer,Character>();
    for (int i = 0; i < 26; i++) {
      dictCI.put((char)(i+'a'),i);
      dictIC.put(i,(char)(i+'a'));
    }
    int n = Integer.parseInt(sc.nextLine());
    for (int i = 0; i < n; i++) {
      String str = sc.nextLine();
      String[] strArr = str.split(" ");
      int j = 1;
      int[] key = new int[2];
      searchKey:
      while (true) {
        if (j%2 == 0 || j%13 == 0) {
          j++;
          continue;
        }
        for (int k = 0; k < 27; k++) {
          for (int l = 0; l < strArr.length; l++) {
            String strTemp = "";
            for (int m = 0; m < strArr[l].length(); m++) {
              int intTemp = (dictCI.get(strArr[l].charAt(m))*j + k)%26;
              strTemp += String.valueOf(dictIC.get(intTemp));
            }
            if (strTemp.equals("this") || strTemp.equals("that")) {
              key[0] = j;
              key[1] = k;
              break searchKey;
            }
          }
        }
        j++;
      }
      String strResult = "";
      for (j = 0; j < str.length(); j++) {
        if (str.charAt(j) < 'a' || str.charAt(j) > 'z') {
          strResult += String.valueOf(str.charAt(j));
        }
        else {
          int intResult = (dictCI.get(str.charAt(j))*key[0] + key[1])%26;
          strResult += String.valueOf(dictIC.get(intResult));
        }
      }
      System.out.println(strResult);
    }
  }
}

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

int main() {
    int n;
    cin >> n;
    int h[100];
    for(int i=0; i<n; i++) cin >> h[i];

    int l=0, r=l, cnt=0;
    while(l<n) {
        if(h[l]==0) {
            l++;
            continue;
        }
        r=l;
        while(h[r]>0 && r<n) {
            h[r]--;
            r++;
        }
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
def matrix_product(X,Y,M):
    XY = [[0]*3 for _ in range(3)]

    for i in range(3):
        for j in range(3):
            for k in range(3):
                XY[i][j] += X[i][k]*Y[k][j] % M
            XY[i][j] %= M
    
    return XY

def power(X,n,M):
    res = [[1,0,0],[0,1,0],[0,0,1]]

    if n == 0: return res

    while n > 0:
        if n & 1: res = matrix_product(res,X,M)
        X = matrix_product(X,X,M)
        n //= 2
    
    return res

L, A, B, M = map(int,input().split())

X = [0,A,1]

for d in range(1,19):
    if L == 0: break

    
    l = (10**(d-1) - A + B-1) // B
    r = (10**d - A) // B
    if (10**d - A) % B == 0: r -= 1
    
    if l < 0: l = 0
    if r < 0: r = -1
    
    C = min(r-l+1,L)
    L -= C

    Y = power([[10**d,0,0],[1,1,0],[0,B,1]],C,M)
    
    next_X = [0,0,0]
    for i in range(3):
        for j in range(3):
            next_X[i] += X[j] * Y[j][i] % M
        next_X[i] %= M
    X = next_X

print(X[0])









Measured memory_bytes: 9304
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    int n,ans=0;
    cin >> n;
    int x[n];
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    
    
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(x[j]<x[minj])
                minj =j;
        }
        if(i!=minj){
            swap(x[i],x[minj]);
            ans++;
        }
    }
    
    
    for (int i=0; i<n; i++) {
        if(i==0)cout<< x[i];
        else cout <<" "<< x[i];
    }
    cout << endl << ans << endl;
    
}




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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

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

    string s;
    cin >> s;

    int ans = 0;

    for( int i = 0; i < s.length(); i++){

        if( s[i] == '+'){
            ans++;
        }
        else{
            ans--;

        }
    }

    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 256
#include <iostream>

unsigned int Max = 100004;

int table[100004];

int main(int argc, char const* argv[]) {
	using namespace std;

	for (unsigned int i = 0; i < Max; i++) {
		table[i] = 0;
		if (i % 2 == 0)
			table[i] = 1;
	}

	table[0] = 1;
	table[1] = 1;
	table[2] = 0;

	int h = Max / 2;

	for (unsigned int i = 3; i <= h; i++) {
		for (unsigned int k = i * 2; k < Max; k = k + i) {
			table[k] = 1;
		}
	}

	/*
	for (int i = 0; i < Max; i++) {
		if (table[i] == 0)
			cout << i << endl;
	}
	*/

	unsigned int x;
	cin >> x;

	for (unsigned int i = x; i < Max; i++) {
		if (table[i] == 0) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 640
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A = many_int()

temp = list(zip(A, [i+1 for i in range(len(A))]))


temp2 = sorted(temp,key=lambda x: x[0])

output=[]
for i in temp2:
    output.append(str(i[1]))


print(" ".join(output))

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

using namespace std;

typedef long long ll;

void print(vector<ll> v) {
  for(ll x: v) cout << x << " ";
  cout << endl;
}

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

  int n, m;
  ll k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < m; ++i) cin >> b[i];

  vector<ll> sa(n + 1), sb(m + 1);
  for(int i = 1; i <= n; ++i) sa[i] = a[i - 1] + sa[i - 1];
  for(int i = 1; i <= m; ++i) sb[i] = b[i - 1] + sb[i - 1];

  // print(sa);
  // print(sb);

  int ans = 0;
  for(int i = 0; i <= n; ++i) {
    ll rem = k - sa[i];
    if(rem < 0) break;

    /*
    int l = 0, r = m;
    while(l < r) {
      int mid = l + (r - l) / 2;
      if(sb[mid] > rem) {
        r = mid - 1;
      } else if(sb[mid] < rem) {
        if(mid + 1 <= m && sb[mid + 1] <= rem) {
          l = mid + 1;
        }
        else {
          l = mid;
          break;
        }
      } else {
        l = mid;
        r = mid;
        break;
      }
    }
    */
    auto up = upper_bound(sb.begin(), sb.end(), rem);
    int pos = up - sb.begin() - 1;

    // cout << "found: " << sb[pos] << " <= " << rem << endl;
    ans = max(ans, i + pos);
    // cout << "found: " << sb[l] << " <= " << rem << endl;
    // ans = max(ans, i + l);
  }

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


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

using namespace std;

int main() {
    int n;
    cin >> n;
    long long A[n];
    for(int i=0; i<n; i++) cin >> A[i];

    long long L[n], R[n];
    for(int i=0; i<n; i++) {
        L[i] = 0;
        R[i] = 0;
    }

    long long cnt = 0;
    for(int i=0; i<n; i++) {
        if(i-A[i]>=0) {
            cnt += R[i-A[i]];
            L[i-A[i]]++;
        }
        if(i+A[i]<n) {
            cnt += L[i+A[i]];
            R[i+A[i]]++;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

vector<int> L[100100];
int P[100100];
int D[100100];
int ans[100100];

int dfs(int v){
    if(D[v] >= 0) return D[v];
    int d = -1;
    int idx = 0;
    for(int i = 0; i < L[v].size(); i++){
        int next = L[v][i];
        int x = dfs(next);
        if(d < x){
            d = x;
            idx = next;
        }
    }
    D[v] = d+1;
    P[v] = idx+1;
    return D[v];
}


int main(){
    int N, M;
    cin >> N >> M;
    set<int> vv;
    REP(i, N-1+M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        L[b].push_back(a);
        vv.insert(b);
    }

    int root;
    REP(i, N){
        if(vv.find(i) == vv.end()){
            root = i;
            break;
        }
        if(i == N-1) return -1;
    }
    //printf("root:%d\n", root);

    fill(P, P+N, -1);
    fill(D, D+N, -1);
    //dfs(root);
    REP(i,N){
        dfs(i);
    }
    P[root] = 0;

    REP(i,N){
        printf("%d\n", P[i]);
    }
    return 0;
}


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

#define N_MAX 10001

bitset<N_MAX> primes;

void make_cache() {
    primes.set();
    for (int i = 2; i < N_MAX; i++) {
        if (primes[i]) {
            for (int j = i + i; j < N_MAX; j+=i) {
                primes.reset(j);
            }
        }
    }
}

void solve(int n) {
    for (int i = n; 4 <= i; i--) {
        if (primes[i] && primes[i-2]) {
            cout << i-2 << ' ' << i << endl;
            break;
        }
    }
}

int main() {
    make_cache();
    int n;
    while (cin >> n) {
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

Measured memory_bytes: 864
from collections import defaultdict


def calc(x):
    return x*(x-1)//2


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

dd = defaultdict(int)
for i in range(N):
    dd[A[i]] += 1

count = 0
for k, v in dd.items():
    if v >= 2:
        count += calc(v)
for i in range(N):
    ans = 0
    if dd[A[i]] >= 3:
        ans = count - calc(dd[A[i]]) + calc(dd[A[i]]-1)
    elif dd[A[i]] == 2:
        ans = count - 1
    elif dd[A[i]] == 1:
        ans = count
    print(ans)

Measured memory_bytes: 93260
from collections import deque

n, m = map(int, input().split())
G = [[] for _ in range(n+1)]
par = [0] * (n+1)

for _ in range(m):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)

visited = [0] + [1] + [0] * (n-1)
q = deque()
q.append(1)
while q:
    now = q.popleft()
    #print("now:", now)
    visited[now] = 1
    for next in G[now]:
        #print("next:", next)
        #print("visited:", visited)
        if visited[next]:
            continue
        q.append(next)
        par[next] = now
        visited[next] = 1
print("Yes")
print("\n".join(map(str, par[2:])))


Measured memory_bytes: 42684
import sys

def longestcommonsubsequence():
    seq1 = raw_input()
    seq2 = raw_input()

    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        #x1 = [0 for i2 in range(b+1)]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1]<x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]

n = input()
for i2 in range(n):

    print longestcommonsubsequence()

Measured memory_bytes: 4328
#include <iostream>
using namespace std;
string s[400];
int dp[400][400];
long long h,w,t[]={-1,0,0,1},u[]={0,-1,1,0},a,b,ans,x,y;
void f(int i,int j,int k){
    for(int ii=0;ii<4;ii++){
        x=t[ii],y=u[ii];
        if(i+x>=0&&i+x<h&&j+y>=0&&j+y<w&&dp[i+x][y+j]==0){
            if(k==0&&s[i+x][y+j]=='.'){dp[i+x][y+j]=1;b++;f(i+x,y+j,1);}
            else if(k==1&&s[i+x][y+j]=='#'){dp[i+x][y+j]=1;a++;f(i+x,y+j,0);}
        }
    }
    return ;
}
int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            a=0,b=0;
            if(s[i][j]=='#'&&dp[i][j]==0){
                a++;
                dp[i][j]=1;
                f(i,j,0);
                ans+=a*b;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13568
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath> // fabs, pow, sqrt, sin, fmod
#include <chrono> // system_clock 
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

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

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

    vector<int> c(26);
    rep(i, 26) {
        cin >> c.at(i);
    }

    vector<vector<int>> s(D, vector<int>(26));
    rep(d, D) {
        rep(i, 26) {
            cin >> s.at(d).at(i);
        }
    }

    vector<int> t(D); //その日に選んだコンテスト

    /*
    rep(d, D) {
        int max = 0;
        t[d] = 1;
        rep(i, 26) {
            if(max < s[d][i]) {
                max = s[d][i];
                t[d] = i;
            }
        }
    }
    */

    //スコア計算
    int score = 0;

    vector<int> last(26);
    rep(i,26) last[i]= -1;

    rep(d, D) { //d:day
        int max_t = 0;
        int max_score = score;

        rep(i, 26) { //i:contest
            int tmp_score = score;
            vector<int> tmp_last = last;
            t[d] = i;
            tmp_last[t.at(d)] = d;
            tmp_score += s[d][t[d]];
            rep(j, 26) { 
                tmp_score -= c[j] * (d - tmp_last[j]);
            }
            if(max_score < tmp_score) {
                max_t = i;
                max_score = tmp_score;
            }
        }
        t[d] = max_t;
        last[max_t] = d;
    }

    rep(d, D) {
        cout << t[d]+1 << endl;
    }
    
}

Measured memory_bytes: 3684
N=int(input())
H=list(map(int,input().split()))
M=[0]*N

while(1):
	count=0
	for i in range (N-1):
		if H[i]>H[i+1]:
			if M[i]==1:
				print("No")
				exit()
			else:
				M[i]=1
				H[i]=H[i]-1
		else:
			count+=1
	if count==N-1:
		print("Yes")
		exit()

Measured memory_bytes: 14396
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        S: chars,
    }
    let mut flag = false;
    let mut prev = ' ';
    let mut ans = 0;

    for c in S {
        if flag {
            flag = false;
            prev = ' ';
            ans += 1;
        } else if c == prev {
            flag = true;
            prev = c;
        } else {
            ans += 1;
            prev = c;
        }
    }

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int n, w;
int wt[101], val[101];
int dp[101][100001];
int fun(int idx, int totalWt){
    if(idx == n || totalWt >= w){
        return 0;
    }
    if(dp[idx][totalWt] != -1){
        return dp[idx][totalWt];
    }
    int temp = fun(idx+1, totalWt);
    if(totalWt + wt[idx] <= w){
        dp[idx][totalWt] = max(val[idx] + fun(idx+1, totalWt + wt[idx]), temp);
        return dp[idx][totalWt];
    }else{
        dp[idx][totalWt] = temp;
        return dp[idx][totalWt];
    }
}
signed main(){
    cin >> n >> w;
    for(int i=0; n>i; i++){
        cin >> wt[i] >> val[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << fun(0, 0) << endl;
}
 
 
 


Measured memory_bytes: 80256
#include<stdio.h>
#define N 500
#define NIL -2000000001
typedef struct{
  int k, p, l, r;
} node;

node A[N];

int main(){
  int hs, i;
  scanf("%d", &hs); 
  for(i = 1; i <= N; i++){
    A[i].k = NIL;
    A[i].p = NIL;
    A[i].l = NIL;
    A[i].r = NIL;
  }
  for(i = 1; i <= hs; i++){
    scanf("%d", &A[i].k);
  }
  for(i = 1; i <= hs; i++){
    if(i != 1) A[i].p = A[i/2].k;
    if(A[2*i].k) A[i].l = A[2*i].k;
    if(A[2*i+1].k != NIL) A[i].r = A[2*i+1].k;
  }
  for(i = 1; i <= hs; i++){
    printf("node %d: key = %d, ", i, A[i].k);
    if(A[i].p != NIL) printf("parent key = %d, ", A[i].p);
    if(A[i].l != NIL) printf("left key = %d, ", A[i].l);
    if(A[i].r != NIL) printf("right key = %d, ", A[i].r);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 1000000
int main(){
	int n;
	while(cin >> n , n){
		int mx = 0,mn = INF;
		for(int i=0;i<n;i++){
			int sum = 0;
			for(int j=0;j<5;j++){
				int score;
				cin >> score;
				sum += score;
			}
			mx = max(mx,sum);
			mn = min(mn,sum);
		}
		cout << mx << " " << mn << endl;
	}
}

Measured memory_bytes: 1160
import sys
inf = float('inf')

n, A, B, C, *l = map(int, sys.stdin.read().split())

def cost(a, b, c, cnt, i):
    if i == n:
        if not (a and b and c): return inf
        return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3)
    return min(cost(a, b, c, cnt, i+1), 
               cost(a+l[i], b, c, cnt+1, i+1),
               cost(a, b+l[i], c, cnt+1, i+1),
               cost(a, b, c+l[i], cnt+1, i+1))

def main():
    print(cost(0, 0, 0, 0, 0))

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3064
N = int(input()) #桁数を指定

S = input()

ans = 0
for i in range(10):
    x = S.find(str(i))
    if x != -1:
        for j in range(10):
            y = S.find(str(j), x+1)
            if y != -1:
                for k in range(10):
                    z = S.find(str(k), y+1)
                    if z != -1:
                        ans += 1

print(ans)


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

typedef long long ll;
typedef pair<int, int> ii; 

int main(int argc, char const *argv[]) {
	int n; cin >> n; int arr[2*n];
	for(int i = 0; i < 2*n; i++) cin >> arr[i];
	sort(arr, arr + 2*n);
	int sum = 0;
	for(int i = 0; i < 2*n; i += 2) sum += arr[i];
	cout << sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int X, Y, Z;

int main()
{
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define int long long
using namespace std;

struct Edge {
	int from, to, flow, rev;
	Edge() {}
	Edge(int from, int to, int flow, int rev) {
		this->from = from;
		this->to = to;
		this->flow = flow;
		this->rev = rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

const int VMAX = 102;

void add_edge(Graph &g, int s, int t, int flow) {
	g[s].push_back(Edge(s, t, flow, g[t].size()));
	g[t].push_back(Edge(t, s, 0, g[s].size() - 1));
}

int dfs(Graph &g, int s, int t, int level[], int seenEdgeCount[], int flow) {
	if (s == t) return flow;
	
	for (int &i = seenEdgeCount[s]; i < g[s].size(); i++) {
		int nv = g[s][i].to;
		if (level[nv] != level[s] + 1 || g[s][i].flow <= 0) continue;	//辺残量も確認する！
		int f = dfs(g, nv, t, level, seenEdgeCount, min(flow, g[s][i].flow));
		if (f <= 0) continue;
		//s --> nv間にfだけ流す
		g[s][i].flow -= f;
		g[nv][g[s][i].rev].flow += f;
		return f;
	}
	return 0;
}

int maxflow(Graph g, int s, int t) {
	int i, level[VMAX], ret = 0;

	while (true) {
		for (i = 0; i < g.size(); i++) level[i] = -1;
		queue<int> que;
		
		level[s] = 0;
		que.push(s);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (i = 0; i < g[v].size(); i++) {
				if (g[v][i].flow <= 0) continue;
				int nv = g[v][i].to;
				if (level[nv] == -1) {
					level[nv] = level[v] + 1;
					que.push(nv);
				}
			}
		}
		if (level[t] == -1) break;
		
		int seenEdgeCount[VMAX] = {0};
		
		int flowINF = 1e+11;	//辺容量の最大値よりも大きな値にする
		
		while (true) {
			int f = dfs(g, s, t, level, seenEdgeCount, flowINF);
			if (f <= 0) break;
			ret += f;
		}
	}
	return ret;
}

int n;
int a[101];
Graph g;

signed main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i + 1];
	
	//各宝石を割るかどうかを独立に選べるとしたら、最大いくら貰えるか
	int risou = 0;
	for (i = 1; i <= n; i++) {
		if (a[i] > 0) risou += a[i];	//価値が正の宝石だけ割る
	}
	
	//そこからいくら引かれるか
	//（各宝石を割るグループ, 割らないグループに分けたとき, いくらペナルティーが発生するか）<-> S--Tカットと対応させる！
	//S -- Tカットの容量は、S側からT側に張られた辺のコストの和で定義される。T側からS側に張られた辺のコストはカウントしないことに注意。
	g.resize(n + 2);
	
	//割るグループS(頂点0) --> 割らないグループT(頂点n + 1)
	for (i = 1; i <= n; i++) {
		if (a[i] < 0) add_edge(g, 0, i, -a[i]);
	}
	
	int flowINF = 1e+11;
	for (i = 1; i <= n; i++) {
		for (j = 2 * i; j <= n; j += i) {
			//i --> jと辺をはる条件 … 「iを割る⇒jを割る」。違反をする＝S->T辺を切る、という風に対応づける。
			add_edge(g, i, j, flowINF);
		}
	}
	
	for (i = 1; i <= n; i++) {
		if (a[i] > 0) add_edge(g, i, n + 1, a[i]);
	}
	
	//最小カットの容量と、最大流で流れた量は等しい
	int penalty = maxflow(g, 0, n + 1);
	
	cout << risou - penalty << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;
ll MAXN = 10000002;
ll spf[10000002];

ll f(ll n)
{   
    map<ll,ll>mp;
    while (n != 1) 
    { 
        mp[spf[n]]++;
        n = n / spf[n]; 
    } 
    ll ret = 1;
    for(auto it:mp)
    {
        ret=ret*(it.second+1);
    }

    return ret;
}

int main()

{   
    boost;
    ll n ;
    cin>>n;

    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++)spf[i] = i; 
  
    for (ll i=4; i<MAXN; i+=2)spf[i] = 2; 
  
    for (ll i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    }

    ll sum =0;

    for(ll i = 1 ; i <= n ; i++)
    {
        sum=(sum+i*f(i));
    }

    cout<<sum<<endl;

}

Measured memory_bytes: 81784