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

int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,Q;
    cin >> n >> Q;

    fenwick_tree<ll> fw(n);
    rep(i,n) {
        int a; cin >> a;
        fw.add(i,a);
    }

    while(Q--) {
        int type;
        cin >> type;
        if(type == 0) {
            int p,x;
            cin >> p >> x;
            fw.add(p,x);
        }
        if(type == 1) {
            int l,r;
            cin >> l >> r;
            cout << fw.sum(l,r) << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 8252
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n, k;
	cin >>n >>k;
	vector<long long> h(n);
	for(long long i = 0; i < n; i++)
		cin >>h[i];
	vector<long long> dp(n, INT_MAX);
	dp[0] = 0;
	for(long long i = 0; i < n; i++) {
		for(long long j = i + 1; j <= i + k; j++) {
			if(j < n) {
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	cout <<dp[n-1];
	return 0;
}


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

int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d)
    {
        int ta,ao;
        if(c%b==0)
            ta=c/b;
        else
            ta=c/b+1;
        if(a%d==0)
            ao=a/d;
        else
            ao=a/d+1;
        if(ta<=ao)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())
    dt = N//K
    ans = min(abs(N - dt * K), abs(N - (dt+1)*K))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 36
#define MAX 1000
 
char getChar(int x){
    return (x < 10 ? x+'0' : x+'A'-10);
}
 
int main(){
    int N,M,Q;
    while(cin >> N >> M >> Q, N){
	string S,B[MAX+1];
	bool sw[MAX+1][MAX_N];
	sw[0][0] = false;
	for(int i = 1 ; i <= Q ; i++){
	    cin >> S >> B[i];
	    for(int j = 0 ; j < N ; j++){
		sw[i][j] = (S[j] == '1' ? !sw[i-1][j] : sw[i-1][j]);
	    }
	}
	string ans;
	for(int i = 0 ; i < M ; i++){
	    bool use[MAX_N];
	    fill(use,use+N,true);
	    for(int j = 1 ; j <= Q ; j++){
		for(int k = 0 ; k < N ; k++){
		    if(!sw[j][k] && B[j][i] == '1' ||
		       sw[j][k] && B[j][i] == '0'){
			use[k] = false;
		    }
		}
	    }
	    bool ok = true;
	    int x = -1;
	    for(int j = 0 ; j < N ; j++){
		if(use[j]){
		    if(x != -1) ok = false;
		    x = j;
		}
	    }
	    ans += (ok ? getChar(x) : '?');
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4116
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
      
n = int(input())
n_list = factorization(n)
oh = []
for i in range(len(n_list)):
  num = n_list[i][0] #2の
  kata = n_list[i][1] #3乗
  for i in range(1, kata+1):
    oh.append(num ** i)
oh.sort()
ans = 0
z = []
for i in range(len(oh)):
  if oh[i] == 1:
    break
  else:
    if n % oh[i] == 0 and oh[i] not in z:
      z.append(oh[i])
      n = n / oh[i]
      ans += 1
print(ans)

Measured memory_bytes: 9528
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 500000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int main()
{
    int k,ans=-1,s=0; scanf("%d",&k);
    rep(i,1,k)
    {
        s=(s*10+7)%k;
        if(s==0) {ans=i; break;}
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                               \
  do {                                                                         \
    cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";                        \
    dump(__VA_ARGS__);                                                         \
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////


int main()
{
  string s;
  cin >> s;

  if (s.back() == 's') cout << s << "es" << "\n";
  else cout << s << "s" << "\n";

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll N;
	string ans;

	cin >> N;

	deque<pair<ll, ll>> job;
	rep(i, N) {
		int A, B;
		cin >> A >> B;
		job.emplace_back(B, A);
	}

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

	ll t = 0;
	ans = "Yes";
	rep(i, N) {
		t += job.front().second;
		if (t > job.front().first) {
			ans = "No";
			break;
		}
		job.pop_front();
	}

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


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    rep(i,t){
        ll n,m,a,b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n,m,a,b) << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    int A, B, T;
    cin >> A >> B >> T;
    cout << (T / A) * B << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2005;
int e[N][N],top[N][N],fa[N][N],ans,rt;
vector<int> v[N];
void dfs(int p){
	for(auto i:v[p])if(i!=fa[rt][p]){fa[rt][i]=p; dfs(i);}
}
void solve(int p,int dq){
	if(e[dq][p]){ans++; dq=p;}
	for(auto i:v[p])if(i!=fa[rt][p])solve(i,dq);
}
void clear(int x,int de){
	top[rt][x]=de;
	for(auto i:v[x])if(i!=fa[rt][x])clear(i,de);
}
void bao(int x,int y,vector<PI> &V){
	e[x][y]=1; //cout<<x<<" "<<y<<" "<<e[x][y]<<" "<<top[x][y]<<endl;
	queue<int> q; q.push(y);
	while(q.size()){
		int u=q.front(); q.pop();
		if(e[x][u]&&u!=y){
			e[x][u]=e[u][x]=0; 
			V.pb(mp(y,u));
			rt=x; clear(y,y);
		}else{
			top[x][u]=y;
			for(auto t:v[u])if(t!=fa[x][u]){
				q.push(t);
			}
		}
	}
}
void add(int x,int y){
	if(e[x][y]||x==y)return;
	if(top[x][y])return add(top[x][y],y);
	if(top[y][x])return add(top[y][x],x);
	vector<PI> V;
	bao(x,y,V); bao(y,x,V);
	for(auto i:V)add(i.fi,i.se);
}
int main(){
	int n=read(),m=read();
	For(i,1,n-1){
		int x=read(),y=read();
		v[x].pb(y); v[y].pb(x);
	}
	For(i,1,n){
		rt=i; dfs(i);
	}
	while(m--){
		int x=read(),y=read();
		add(x,y);
	}
	For(i,1,n){
		rt=i; solve(i,i);
	}
	//For(i,1,n)For(j,1,n)if(e[i][j])cout<<i<<" "<<j<<endl;
	cout<<(ans>>1)<<endl;
}
/*
5 3
1 2
1 3
3 4
1 5
5 4
2 5
1 5

*/

Measured memory_bytes: 47616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int count = 0;
        for (int i = 1; i < n; i++) {
            int now = n/i;
            if (n%i==0) now--;
            count += now;
            // System.out.println(i + " " + now);
        }
        System.out.println(count);
        
        // a*b+c=n
        
        // n=100
        // 1,1,99
        // 1,2,98
        // 1,99,1 1...100-1
        // 2,1,98
        // 2,49,2 2...100/2-1
        // 3,33,1
        // 100
        
        // for (int a = 1; a <= )
    }
}


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

ans = 0
for i in range(N):
    s = min(A[i], B[i])
    A[i] -= s
    B[i] -= s
    ans += s
    s = min(A[i + 1], B[i])
    A[i + 1] -= s
    B[i] -= s
    ans += s

print(ans)


Measured memory_bytes: 18476
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 8005
#define ll long long
#define mod 998244353
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int k, n, fac[N], inv[N];
int Pow(int a, int k)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2);
	if (k & 1)
		return (ll)p * p % mod * a % mod;
	return (ll)p * p % mod;
}
int C(int n, int m)
{
	if (n < m)return 0;
	if (m < 0)return 0;
	return (ll)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main()
{
	fac[0] = 1;
	for (int i = 1; i <= 8000; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[8000] = Pow(fac[8000], mod - 2);
	for (int i = 8000; i >= 1; i--)
		inv[i - 1] = (ll)inv[i] * i % mod;
	Read(k), Read(n);
	for (int i = 2; i <= 2 * k; i++)
	{
		int a, b;
		//printf("%d: ", i);
		if (i & 1)
		{
			if (i <= k + 1)
				a = (i - 1) / 2, b = k - i + 1;
			else
				a = (2 * k - i + 1) / 2, b = i - k - 1;
		}
		else
		{
			if (i <= k + 1)
				a = i / 2 - 1, b = k - i + 1;
			else
				a = (2 * k - i) / 2, b = i - k - 1;
		}
		//printf("(Pairs: %d, Single: %d) ", a, b);
		int ans = 0;
		for (int j = 0; j <= a; j++)
		{
			ans = (ans + (ll)Pow(2, j) * C(a, j) % mod * C(n + b - 1, b + j - 1)) % mod;
			if (!(i & 1))
				ans = (ans + (ll)Pow(2, j) * C(a, j) % mod * C(n + b - 2, b + j - 1)) % mod;
		}
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 110, M = 100100;
int n, W;
ll w[N], v[N];
ll mem[N][M + N];
ll dp(int i, ll wight){
    if(wight > W)
        return -2e9;
    if(i == n)
        return 0;
    ll &ret = mem[i][wight];
    if(ret != -1)
        return ret;
    return ret = max(dp(i+1, wight+w[i]) + v[i], dp(i+1, wight));
}
int main(){
    memset(mem, -1, sizeof mem);
    scanf("%d %d", &n, &W);
    for(int i = 0; i < n; ++i)
        scanf("%lld %lld", &w[i], &v[i]);
    printf("%lld", dp(0, 0));

    return 0;
}


Measured memory_bytes: 86400
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    if N%2==1:
        print("No")
        exit()
    
    if S[:N//2] == S[N//2:]:
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":
    main()

Measured memory_bytes: 61880
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e2+10;
    static const ll MOD=1e9+7;
    int N;
    const char s[5]="ACGT";
    ll dp[MAXN][4][4][4];
    bool check(int i,int j,int k){
        string r="";
        r+=s[i];
        r+=s[j];
        r+=s[k];
        if(r=="AGC")return false;
        return true;
    }
    void solve(){
        cin>>N;
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    if(check(i,j,k)&&check(i,k,j)&&check(j,i,k))
                    dp[3][i][j][k]=1;
                }
            }
        }
        for(int l=4;l<=N;l++){
            for(int i=0;i<4;i++){
                for(int j=0;j<4;j++){
                    for(int k=0;k<4;k++){
                        for(int u=0;u<4;u++){
                            if(check(i,j,k)&&check(i,k,j)&&check(j,i,k)&&check(u,i,k)&&check(u,j,k)){
                                dp[l][i][j][k]=(dp[l][i][j][k]+dp[l-1][u][i][j])%MOD;
                            }
                        }
                    }
                }
            }
        }
        ll ans=0;
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    ans=(ans+dp[N][i][j][k])%MOD;
                }
            }
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int t, x;
    cin >> t >> x;

    double ans = t / (double)x;
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int x;
    cin >> x;
    if (x >= 1800) {
        cout << 1 << endl;
    } else if (x >= 1600) {
        cout << 2 << endl;
    } else if (x >= 1400) {
        cout << 3 << endl;
    } else if (x >= 1200) {
        cout << 4 << endl;
    } else if (x >= 1000) {
        cout << 5 << endl;
    } else if (x >= 800) {
        cout << 6 << endl;
    } else if (x >= 600) {
        cout << 7 << endl;
    } else if (x >= 400) {
        cout << 8 << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
s = 0
b_count = 0
for i in range(m):
    if s + b[i] <= k:
        s += b[i]
        ans += 1
        b_count = i+1
    else:
        break
a_count = 0
while True:
    if a_count < n and s+a[a_count] <= k:
        s += a[a_count]
        a_count += 1
        ans += 1
    else:
        break
now = ans
for i in range(b_count-1, -1, -1):
    s -= b[i]
    now -= 1
    while True:
        if a_count < n and s +a[a_count] <= k:
            s += a[a_count]
            a_count += 1
            now += 1
        else:
            break
    ans = max(now, ans)
print(ans)

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

int main(){
  int N;
  int a[2][100];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[0][i];
  }
  for(int i = 0; i < N; i++){
    cin >> a[1][i];
  }
  
  int sum = 0;
  sum += a[0][0];
  for(int i = 0; i < N; i++){
  	sum += a[1][i];
  }
  
  int max = sum;
  for(int i = 0; i < N-1; i++){
    int diff = -1*a[1][i] + a[0][i+1];
   	if( diff + sum > max) max = sum + diff;
    sum += diff;
  }
  cout << max << endl;
}

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


int main()
{	
	double a;
	cin>>a;
	printf("%.8f %.8f \n",a*a*3.14159265358979,a*2*3.14159265358979);
	return 0;	
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
using namespace std;
const int next[4][2] = {
  {-1,0},{0,-1},{1,0},{0,1},
};
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    int minx,maxx,miny,maxy;
    minx = maxx = miny = maxy = 0;
    vector< pair<int,int> > v;
    v.push_back(make_pair<int,int>(0,0));
    for(int i=0; i<n-1; i++){
      int j,d;
      cin >> j >> d;
      pair<int,int> p = v[j];
      int nx = p.first + next[d][0];
      int ny = p.second + next[d][1];
      if(nx < minx) minx = nx;
      if(nx > maxx) maxx = nx;
      if(ny < miny) miny = ny;
      if(ny > maxy) maxy = ny;
      v.push_back(make_pair<int,int>(nx,ny));
    }
    cout << (maxx - minx + 1) << " " << (maxy - miny + 1) << endl;
  }
  return 0;
}

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

int main(){
  int X;
  cin >> X;
  int ans = 0;
  int t = 0;
  for(int i=0; i<35; i++){
    for(int j=2; j<10; j++){
      t = pow(i,j);
      if(t <= X){
      ans = max(ans,t);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
public class Main {

    private static void solver(InputReader sc, PrintWriter out) throws Exception {
        String s = sc.next();
        char ch = s.charAt(0);
        if(Character.isUpperCase(ch)) out.println("A");
        else out.println("a");
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair implements Comparable<Pair>{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair p){
        return (int)(this.x - p.x);
    }
}
class Tuple{
    String s;
    int x, y;

    public Tuple(String s, int x, int y) {
        this.s = s;
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tuple tuple = (Tuple) o;
        return x == tuple.x &&
                y == tuple.y &&
                s.equals(tuple.s);
    }

    @Override
    public int hashCode() {
        return Objects.hash(s, x, y);
    }
}

Measured memory_bytes: 32948
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7

n = int_input()

if (n%1000 == 0):
    print(0)
else:
    print(1000 - (n%1000))

Measured memory_bytes: 9600
fun main(arg: Array<String>) {
    val S = next()
    val N = S.length
    for (n in 0 until N - 1) {
        if (S[n] == S[n + 1]) {
            return println("${n + 1} ${n + 2}")
        }
        if (n < N - 2 && S[n] == S[n + 2]) {
            return println("${n + 1} ${n + 3}")
        }
    }
    println("-1 -1")
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }



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

int main() {
	int r = 0, c = 0;
	cin >> r >> c;
	int a[101][101] = { {0} };

	for (int i = 0;i < r;i++) {
		for (int j = 0;j < c;j++) {
			cin >> a[i][j];
			a[i][c] += a[i][j];
			a[r][j] += a[i][j];
			a[r][c] += a[i][j];
		}
	}

	for (int i = 0;i < r + 1;i++) {
		for (int j = 0;j < c + 1;j++) {
			cout << a[i][j];
			if (j != c)
				cout << " ";
		}
		cout << endl;
	}
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n, k;
  cin >> n >> k;
  vi64 v(n); cin >> v;
  i64 ans = -1e18;
  for (int i = 0; i <= min(k, n); i++) {
    for (int f = 0; f <= i; f++) {
      int b = i - f;
      vi32 lst;
      rep(j, f) lst.push_back(v[j]);
      rep(j, b) lst.push_back(v[n - j - 1]);
      rsort(lst);
      // cerr << i << " " << lst << '\n';
      for (int r = 0; r <= k - i; r++) {
        i64 sum = 0;
        rep(j, lst.size() - r) sum += lst[j];
        amax(ans, sum);
      }
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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



int main() {
    //string S; cin>>S;
    //int A,B; cin>>A>>B;
    int N; string S;
    cin>>N>>S;
    /*
    bool app[10]={false};
    int after[10][10];
    memset(after,false, sizeof(after));
    */
    vector<int> dpos[10];
    for (int i = 0; i < N; ++i) {
        int tmp=S[i]-'0';
        dpos[tmp].push_back(i);
    }

    int ans=0;
    for (int i = 0; i < 1000; ++i) {
        //cout<<i<<" Ok"<<endl;
        int d[3];
        d[0]=i%10; d[1]=(i%100-d[0])/10; d[2]=i/100;
        if(dpos[d[2]].empty()||dpos[d[1]].empty()||dpos[d[0]].empty()) continue;
        int firstd=*lower_bound(dpos[d[2]].begin(),dpos[d[2]].end(),0);
        //cout<<"maru"<<endl;
        auto secpos=lower_bound(dpos[d[1]].begin(),dpos[d[1]].end(),firstd+1);
        if(secpos==dpos[d[1]].end()) continue;
        //cout<<*secpos<<endl;
        int secondd=*secpos;
        auto thipos=lower_bound(dpos[d[0]].begin(),dpos[d[0]].end(),secondd+1);
        if(thipos==dpos[d[0]].end()) continue;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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






string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int H, W;
//-----------------------------------------------------------------
int main() {
	cin >> H >> W;
	rep(y, 0, H) rep(x, 0, W) {
		string s;
		cin >> s;
		if (s == "snuke") {
			cout << al[x] << (y + 1) << endl;
			return 0;
		}
	}
}

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

using namespace std;

int main(){

    int N, count = 0;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++){
        cin >> L[i];
    }
    // for (int i = 0; i < N; i++){
    //     L[i] = i+1;
    // }

    // int N = 2000, count = 0;
    // vector<int> L(N, 1);

    sort(L.rbegin(), L.rend());

    int a, b, c;
    for (int i = 0; i < N; i++){
        a = L[i];
        for (int j = i+1; j < N; j++){
            b = L[j];
            for (int k = j+1; k < N; k++){
                c = L[k];
                if (a < b+c){
                    count++;
                    // cout << a << " " << b << " " << c << " " << endl;
                } else {
                    break;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n,p,g=0;
    cin>>n>>p;
    if(n==1) g=p;
    else{
        for(ll i=1;pow(i,n)<=p;i++){
            if(p%((int)pow(i,n))==0) g=i;
        }
    }
    cout<<g<<endl;
}


Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX = 500010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long PER(int n,int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] *  finv[n - k] % MOD;
}
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
int main(){
  ll n,m,i;
  cin >> n >> m;
  mint ans=0;
  COMinit();
  for(i=0;i<=n;i++){
    ll ans1=COM(n,i)%mod*PER(m,i)%mod*PER(m-i,n-i)%mod*PER(m-i,n-i)%mod;
    if(i%2==0){
      ans+=ans1;
    }
    else{
      ans-=ans1;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 15444
N,M=map(int,input().split())
a=[1 for i in range(N+1)]
for i in range(M):
    a[int(input())]=0

mod=10**9+7
dp=[0 for i in range(N+1)]
dp[0]=1
for i in range(N):
    j=i+1
    for j in range(j,min(N+1,j+2)):
        if a[j]==1:
            dp[j]+=dp[i]
            dp[j]%=mod

print(dp[N])

Measured memory_bytes: 7784
#include <cstdio>
int main(){
 int asum,bsum,a,b,n,i;
 scanf("%d",&n);
 while(n>0){
 asum=bsum=0;
 for(i=0;i<n;i++){
  scanf("%d %d",&a,&b);
  if (a>b) asum += a+b;
  if (a<b) bsum += a+b;
  if (a==b) { asum += a; bsum += b; }
 };
 printf("%d %d\n",asum,bsum);
 scanf("%d",&n);
 }
 return 0;
};

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

int h, w, c, d;
char a[10][10];
bool flag;

int main()
{
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
            if(a[i][j] == '#' && !flag){
                c = j;
                if(j < d){
                    flag = true;
                }
            }
        }
        d = c;
        c = 0;
    }
    if(!flag)printf("Possible\n");
    else printf("Impossible\n");

    return 0;
}


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

int main(){
  string s; cin >> s;

  for(int i=0; i<s.size(); i++){
    for(int j=i+1; j<s.size(); j++){
      if(s[i] == 'C' && s[j] == 'F'){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
string s;
int main(){
    int n, a, b, c, d;
    while(cin>>n>>a>>b>>c>>d){
        --a;--b;--c;--d;
        ll ans=1;
        cin>>s;
        if(a<b){
            for(int i=b; i<d; ++i){
                if(s[i]=='#'&&s[i+1]=='#'){
                    ans=0;
                }
            }
            for(int i=a; i<c; ++i){
                if(s[i]=='#'&&s[i+1]=='#'){
                    ans=0;
                }
            }
            if(d<c){
                ans=0;
                for(int i=b-1; i<d; ++i){
                    if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')
                        ans=1;
                }
            }
        }
        else{
            swap(a,b);
            swap(d,c);
            for(int i=b; i<d; ++i){
                if(s[i]=='#'&&s[i+1]=='#'){
                    ans=0;
                }
            }
            for(int i=a; i<c; ++i){
                if(s[i]=='#'&&s[i+1]=='#'){
                    ans=0;
                }
            }
            if(d<c){
                ans=0;
                for(int i=b-1; i<d; ++i){
                    if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')
                        ans=1;
                }
            }
        }
        if(ans)
            cout<<"Yes"<<endl;
        else{
            cout<<"No"<<endl;
        }
    }
  return 0;
}




Measured memory_bytes: 640
S = input()
is_easy = True

for i in range(len(S)):
    if i & 1 == 1 and S[i] == 'R':
        is_easy = False
        break
    if i & 1 == 0 and S[i] == 'L':
        is_easy = False
        break

print(['No', 'Yes'][is_easy])

Measured memory_bytes: 9072
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][][] undirectedGraph(int n, int[] v1, int[] v2, int[] cost) {
		int[] cnt = new int[n];
		for (int i : v1) cnt[i]++;
		for (int i : v2) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<v1.length; i++) {
			int s = v1[i];
			int t = v2[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];

			g[t][--cnt[t]][0] = s;
			g[t][cnt[t]][1] = cost[i];
		}

		return g;
	}

	static int prim(int[][][] g, int r) {
		int n = g.length;
		BitSet visited = new BitSet();
		int[] d = new int[n];
		Arrays.fill(d, 1<<30);
		d[r] = 0;

		TreeSet<int[]> ts = new TreeSet<>(new Comparator<int[]>(){
			public int compare(int[] a, int[] b) {
				if (a[2] != b[2]) return a[2] - b[2];
				if (a[1] != b[1]) return a[1] - b[1];
				return a[0] - a[0];
			}
		});

		int res = 0;
		ts.add(new int[]{-1, r, 0});

		while (!ts.isEmpty()) {
			int[] tmp = ts.pollFirst();
			int src = tmp[0], dst = tmp[1], cost = tmp[2];
			if (visited.get(dst)) continue;
			visited.set(dst);
			res += cost;
			for (int[] to : g[dst]) {
				if (!visited.get(to[0])) ts.add(new int[]{dst, to[0], to[1]});
			}
		}

		return res;
	}

	static void solve() {
		int v = in.nextInt();
		int e = in.nextInt();
		int[] s = new int[e];
		int[] t = new int[e];
		int[] c = new int[e];
		for (int i=0; i<e; i++) {
			s[i] = in.nextInt();
			t[i] = in.nextInt();
			c[i] = in.nextInt();
		}
		int[][][] g = undirectedGraph(v, s, t, c);
		out.println(prim(g, 0));
 	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using namespace std;

#define INF 1000000

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

  vector<int> x(n);

  for (int i = 0; i < n; ++i)
    cin >> x.at(i);

  int total = INF;
  for (int i = 0; i <= 100; ++i) {
    int tmp = 0;
    for (int j = 0; j < n; ++j) {
      tmp += (x[j] - i) * (x[j] - i);
    }
    total = min(total, tmp);
  }

  cout << total << endl;

  return 0;
}

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

int main() {
	string o,e; cin >> o >> e;
	string out;
	for (int i=0; i < o.length() + e.length(); i++) {
		if(i%2==0){
			out += o.substr(i/2,1);
		} else {
			out += e.substr((i-1)/2,1);
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int res = 0;
  rep(i,n) {
    rep(j,n) {
      if(i >= j) continue;
      res += a[i] * a[j];
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, A: "List[int]"):
    mm = lambda x: mod(x, M)
    A = [0] + A
    c = Counter(map(mm, accumulate(map(mm, A))))
    return sum([v * (v - 1) // 2 for v in c.values()])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, M, A)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 22800
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, W, v[105], w[105], DP[105][int(1e4 + 5)];

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

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

  int ans = 0;
  for (int j = 0; j <= W; j++) ans = max(ans, DP[N][j]);
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 7016
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
#define all(c) (c).begin(), (c).end()

int main() {
  vector<int> v(5);

  rep(i,5) cin >> v[i];
  sort(all(v), greater<int>());
  rep(i, 4) cout << v[i] << " ";
  cout << v[4] << endl;

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    int cntr = 0;
    int t[q],f[q];
    char c[q];
    rep(i, q) {
        cin >> t[i];
        if (t[i] == 1) cntr++;
        else{
            cin >> f[i];
            cin >> c[i];
        }
    }
    cntr = 0;
    string h, ta;
    rep(i,q){
        if (t[i] == 1) cntr++;
        else{
            if(f[i] == 1){
                if(cntr % 2 == 0){
                    h.push_back(c[i]);
                }else{
                    ta.push_back(c[i]);
                }
            }else{
                if(cntr % 2 == 0){
                    ta.push_back(c[i]);
                }else{
                    h.push_back(c[i]);
                }
            }
        }
    }
    reverse(ALL(h));
    string ans = h + s + ta;
    if (cntr % 2 == 1) reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""

long long mul(long long n){
  if(n==1) return 1;
  return (n*mul(n-1)) % MOD;
}

int main(void)
{
    long long N;cin>>N;
    cout<<mul(N)<<endl;
    return 0;
}


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

long long comb(long long n, long long k) {
    if (k == 0) return 1;

    return n * comb(n - 1, k - 1) / k;
}

int main() {
    int n, p;
    cin >> n >> p;
    vector<int> cnt(2);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        cnt.at(a % 2)++;
    }

    long long x = 1ll << cnt.at(0);
    long long y = 0;
    for (int i = p; i <= cnt.at(1); i += 2) {
        y += comb((long long)cnt.at(1), i);
    }
    cout << x * y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main(){
    int N;
    cin>>N;
    int a[N+1];
    rep(i, N) cin>>a[i];
    int ans = 0;
    rep(i, N){
        if (i%2==0 && a[i]%2==1){
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	REP2(i, 1, 10) {
		REP2(j, 1, 10) {
			cout << i << "x" << j << "=" << i * j <<"\n";
		}
	}

	return 0;
}

Measured memory_bytes: 3024