akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> dp(h + 1);
    vector<int> a(n);   
    vector<int> b(n);
    rep(i, n)
    {
        cin >> a[i];
        cin >> b[i];
    }

    rep(j, h + 1) dp[j] = (1 << 30);
    dp[0] = 0;
    
    rep(j, h)
    {
        if( dp[j] == (1 << 30) ) continue;
        rep(i, n)
        {
            int nh = min(h, j + a[i]);
            dp[nh] = min(dp[nh], dp[j] + b[i]);
        }
    }
    cout << dp[h];
}

Measured memory_bytes: 3684
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
broken_steps = set([int(input()) for _ in range(m)])
#print(broken_steps)

def ptn_num(x): # 'x'stepまでのパターン数
    if x == 1:
        print(1)
    else:
        dp = [0] * (x+1) # DP枠_including step'0'
        cnt = 0
        if 1 in broken_steps: # in case, step'1' broken 
            dp[:2] = 1, 0
        else:
            dp[:2] = 1, 1 # Usually

        for i in range(2, x+1):
            if i in broken_steps: # 階段が壊れている場合...
                cnt += 1
                if cnt == 2:
                    print(0)
                    exit()
            else: # 階段が壊れてない場合...
                dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
                cnt = 0
        
        print(dp[-1])

ptn_num(n)


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


int main(){
    unsigned long long N, A, B;
    cin >> N >> A >> B;

    unsigned long long q = N / (A + B);
    unsigned long long r = N % (A + B);
    
    unsigned long long ans = q*A + min({r, A});

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

Measured memory_bytes: 3640
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		int N = IO.nextInt();
		int[] a = new int[N];
		int b = 0;
		for(int i=0; i<N; i++){
			b += (a[i] = IO.nextInt());
		}
		int[] c = new int[N];
		int min = 0;
		for(int i=0; i<N; i++){
			c[i] = Math.abs(a[i]*N - b);
			if(c[i] < c[min]){
				min = i;
			}
		}
		IO.print(String.valueOf(min));
		IO.flush();
		return;
	}
}

final class IO {
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out, false);
	private static final byte[] buffer = new byte[1024];
	private static int ptr = 0;
	private static int len = 0;
	private static boolean hasNextByte() {
		if (ptr < len)
			return true;
		ptr = 0;
		try {
			len = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return len > 0;
	}
	private static int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	static boolean hasNext() {
		byte c;
		while (hasNextByte() && ((c = buffer[ptr]) < '!' || c > '~'))
			ptr++;
		return hasNextByte();
	}
	static String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (b >= '!' && b <= '~') {
			sb.append((char) b);
			b = readByte();
		}
		return sb.toString();
	}
	static char nextChar() {
		if (!hasNext())
			throw new NoSuchElementException();
		return (char) readByte();
	}
	static long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}
	static int nextInt() {
		if (!hasNext())
			throw new NoSuchElementException();
		int n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}
	static double nextDouble() {
		return Double.parseDouble(next());
	}
	static void print(String val) {
		out.print(val);
	}
	static void flush() {
		out.flush();
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
bool b[100],bo[100];
char c[100][100];
int main(){
	int a,d;
	cin>>a>>d;
	for(int i=0;i<a;i++){
		for(int j=0;j<d;j++){
			cin>>c[i][j];
			if(c[i][j]=='#') {
				b[i]=true;
				bo[j]=true;
			}
		}
	}
	for(int i=0;i<a;i++){
		bool boo=false;
		for(int j=0;j<d;j++){
			if(b[i]&&bo[j]){
				cout<<c[i][j];
				boo=true;
			}
		}
		if(boo)puts("");
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define LL long long
#define maxn 200010
LL k,t;
int n,a[maxn],vis[maxn];
int main(){
	int i,nx,s,b,c;
	scanf("%d%lld",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	nx=1;
	while(1){
		vis[nx]=1,nx=a[nx];
		if(vis[nx]){s=nx;break;}
	}
	nx=s;
	for(i=1;i<=n;i++)vis[i]=0;
	while(1){
		vis[nx]=1,nx=a[nx],t++;
		if(vis[nx])break;
	}
	b=0,nx=1;
	while(1){
		if(nx==s)break;
		nx=a[nx],b++;
	}
	c=0;
	if(k<=b){
		nx=1;
		while(1){
			if(k==c)break;
			nx=a[nx],c++;
		}
		printf("%d\n",nx);
		return 0;
	}
	k-=b;k%=t;
	{
		nx=s;
		c=0;
		while(1){
			if(k==c)break;
			nx=a[nx],c++;
		}
		printf("%d\n",nx);
	}
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  if (N * A > B) {
    cout << B << endl;
  }
  else {
    cout << N * A << endl;
  // ここにプログラムを追記
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
    ll X; cin>>X;
    ll ans=0;
    ll K=X/500;
    ans+=K*1000;
    X%=500;
    K=X/5;
    ans+=K*5;
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && a + b >= c) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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 (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        ll N;
        string A, B, C;
        cin >> N >> A >> B >> C;

        ll ans = 0;
        rep(i, 0, N) {
                char a = A[i];
                char b = B[i];
                char c = C[i];

                if (a == b and b == c and c == a) {
                        ;
                } else if (a == b or a == c or b == c) {
                        ans += 1;
                } else {
                        ans += 2;
                }
        }

        cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<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--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    rep(i, N){cin >> A.at(i);}
    ll ans = 0;
    rep(i, N){rep(j, N){
        if (i >= j){continue;}
        if (A.at(i) > A.at(j)){
            ans = (ans + K * (K + 1) / 2) % MOD;
        } else if (A.at(i) < A.at(j)){
            ans = (ans + K * (K - 1) / 2) % MOD;
        }
    }}
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3580
"""
余裕の小さい人から先に座布団を積ませた方がよい。
余裕の大きさは自分の身長と他人のパワーで決まる。
いまここにAとBがいる。
このとき、Bp > AhならAが先に積んだ方がよい。
Ap > Bh ならBが先に積んだ方がよい。
これは書き換えるとAh - Bp < 0ならAがさき、Bh - Ap < 0ならBが先。
Ah - Bp < Bh - ApならAが先、Ah - Bp > Bh - ApならBが先である。
書き換えると、
Ah + Ap < Bh + Bp ならAが先、Ah + Ap > Bh + Bp ならBが先である。
したがって身長+パワーで昇順に並び替えればよい。
"""
N = int(input())
HP = [list(map(int,input().split())) for _ in range(N)]
HP.sort(key= lambda x:x[0]+x[1])
dp = [float("INF")]*(N+1)
dp[0] = 0
for i in range(N):
    h,p = HP[i]
    for j in range(N,0,-1):
        if dp[j-1] <= h:
            dp[j] = min(dp[j],dp[j-1]+p)

for j in range(N,-1,-1):
    if dp[j] != float("INF"):
        print(j)
        break

Measured memory_bytes: 74952
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  int mi = a[0];
  long long ans = 0;
  for (auto& x : a) {
    if (x <= mi) {
      ans += mi - x;
    } else {
      mi = x;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3968
from math import gcd
k=0
n=int(input())
for a in range(1,n+1):
    for b in range(a,n+1):
        for c in range(b,n+1):
            l=list(set([a,b,c]))
            p=1
            for i in range(len(l)-1):
                p*=3-i
            k+=gcd(gcd(a,b),c)*p
print(k)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	int m, n, nr, x1, x0, y1, y0, sx, sy;
	string s, t;

	cin >> m >> n >> nr;

	cin >> sy >> sx;
	--sx; --sy;
	sy = m - 1 - sy;
	x0 = 0; x1 = n - 1;
	y0 = 0; y1 = m - 1;

	cin >> s >> t;

	for(int i = nr - 1; i >= 0; --i) {
		//cerr << x0 << ' ' << x1 << ' ' << y0 << ' ' << y1 << '\n';
		if(t[i] == 'L' && x1 + 1 < n) ++x1;
		if(t[i] == 'R' && x0 > 0) --x0;
		if(t[i] == 'U' && y0 > 0) --y0;
		if(t[i] == 'D' && y1 + 1 < m) ++y1;

		//cerr << x0 << ' ' << x1 << ' ' << y0 << ' ' << y1 << '\n';
		if((s[i] == 'L' || s[i] == 'R') && x0 == x1) return cout << "NO\n", 0;
		if((s[i] == 'U' || s[i] == 'D') && y0 == y1) return cout << "NO\n", 0;
		if(s[i] == 'L' && x0 < x1) ++x0;
		if(s[i] == 'R' && x0 < x1) --x1;
		if(s[i] == 'U' && y0 < y1) --y1;
		if(s[i] == 'D' && y0 < y1) ++y0;
	}

	cout << (x0 <= sx && sx <= x1 && y0 <= sy && sy <= y1 ? "YES\n" : "NO\n");

	return 0;
}


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  for (auto&& e : p) {
    cin >> e;
  }
  for (auto&& e : q) {
    cin >> e;
  }
  for (auto&& e : r) {
    cin >> e;
  }
  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());
  for (int i = 0; i < x; i++) {
    r.emplace_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    r.emplace_back(q[i]);
  }
  sort(r.begin(), r.end(), greater<int>());
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += r[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5592
package main
import (
  . "fmt"
  "os"
  "bufio"
)

var N,Q int
var a,b int
var p,x int
var ans []int
var g [][]int
var m map[int]int

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}
 
var sc = bufio.NewScanner(os.Stdin)
 
func main() {
  sc.Split(bufio.ScanWords)
  N, Q = ri(), ri()
  g = make([][]int, N)
  for i := range g {
    g[i] = make([]int, 0)
  }
  for i := 0; i < N-1; i++ {
    a, b = ri(), ri()
    a--
    b--
    g[a] = append(g[a], b)
    g[b] = append(g[b], a)
  }
  
  m = make(map[int]int)
  for i := 0; i < Q; i++ {
    p, x = ri(), ri()
    p--
    m[p] += x
  }
  
  ans = make([]int, N)
  dfs(0, -1, 0)  
  
  for i := range ans {
    Printf("%d ", ans[i])
  }
}

func dfs(n, par, cum int) {
  cum += m[n]
  ans[n] = cum
  for i := range g[n] {
    if g[n][i] == par {
      continue
    }
    dfs(g[n][i], n, cum)
  }
}





Measured memory_bytes: 55212
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a;
	int y = d - b;
	rep(i, y) {
		cout << 'U';
	}
	rep(i, x) {
		cout << 'R';
	}
	rep(i, y) {
		cout << 'D';
	}
	rep(i, x) {
		cout << 'L';
	}
	cout << "LU";
	rep(i, y) {
		cout << 'U';
	}
	rep(i, x) {
		cout << 'R';
	}
	cout << "RDRD";
	rep(i, y) {
		cout << 'D';
	}
	rep(i, x) {
		cout << 'L';
	}
	cout << "LU" << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double llf;
#define ft first
#define sd second
const int K=1e5+5;
int a[K];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	ll l=2,r=2;
	for(int i=n;i;--i)
  		if(r-(r%a[i])>=l){
  			l=(l+a[i]-1)/a[i]*a[i];
  			r=r/a[i]*a[i]+a[i]-1;
  		}
  		else{
  			puts("-1");
  			return 0;
  		}
   printf("%lld %lld\n",l,r);
}

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

using namespace std;

int main() {


	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);

	if(abs(a - c) <= d) {
		printf("Yes\n");
	} else {
		if(abs(a-b) <= d && abs(b-c) <= d) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

const int MAX_W = 20000;

struct Block {
    ll w, s, v;    
    Block(ll w=0LL, ll s=0LL, ll v=0LL): w(w), s(s), v(v) {}
    bool operator<(const Block b) const{
        return w+s < b.w+b.s;
    }
};

ll dp[2][MAX_W+1];

int main() {
    int n;
    cin >> n;
    vector<Block> blocks(n);
    for(int i=0;i<n;++i) {
        cin >> blocks[i].w >> blocks[i].s >> blocks[i].v;
    }
    sort(blocks.begin(), blocks.end());

    // 上から置いていく
    dp[0][0] = 0LL;
    for(int i=0;i<n;++i) {
        int i_mlb = i & 1;
        for(int j=0;j<=MAX_W;++j) {
            dp[1-i_mlb][j] = max(dp[1-i_mlb][j], dp[i_mlb][j]);
            if(j+blocks[i].w <= MAX_W && j <= blocks[i].s) {
                dp[1-i_mlb][j+blocks[i].w] = max(dp[1-i_mlb][j+blocks[i].w], dp[i_mlb][j] + blocks[i].v);
            }
        }
    }

    ll ans = *max_element(dp[n&1], dp[n&1]+MAX_W+1);
    cout << ans << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int ll
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; for(int i = 0; i < l; i++) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
int w[105], p[105], dp[100500];
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin>>a>>b;
	for(int i = 0; i < a; i++) cin>>w[i]>>p[i];
	for(int i = 0; i < a; i++)
		for(int j = b; j >= w[i]; j--)
			dp[j] = max(dp[j], dp[j-w[i]]+p[i]);
	cout<<dp[b]<<endl;
	return ~~(0-0);
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	for(unsigned i = 0; i < v.size(); i++) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t,i,j,k,l,n,m;
    cin>>n;
    vector<vector<int>> v(n,vector<int> (3,0));
    for(i=0;i<n;i++)
    cin>>v[i][0]>>v[i][1]>>v[i][2];
    vector<vector<int>> dp(n+1,vector<int> (3,0));
    dp[n-1][0]=v[n-1][0];
    dp[n-1][1]=v[n-1][1];
    dp[n-1][2]=v[n-1][2];
  //  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][1]));
    for(i=n-2;i>=0;i--)
    {
        for(j=0;j<3;j++)
        {
                dp[i][j]=dp[i+1][(j+1)%3]+v[i][j];
                dp[i][j]=max(dp[i][j],v[i][j]+dp[i+1][(j+2)%3]);
        }    
     //   cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
    }
    cout<<max(dp[0][0],max(dp[0][1],dp[0][2]));
}

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

using namespace std;

const int LOOP = 10000; //??????????????°
const double EPS = 1e-6; //??????????????¨(?°??????????????????????)
int L;
int N; //???????????±???????????°

//???????????±????????????????????????????????¨?????¨???????¨????????¨??????????
double Evaluate(int r[12]) {
	double val = r[0] + r[N-1];
	for (int i = 0; i < N - 1; i++)
	{
		int a = abs(r[i] - r[i+1]), c = r[i] + r[i+1];
		val += sqrt(c*c - a*a);
	}
	return val;
}

//?????¨?????????????????°???????????¨??????????????????????§???????????±???????
//(????§?????????????true)
bool Changes(int cnt) {
	return cnt < rand()%LOOP;
}

//?????????????????????????????¢??°
//?????????????°??????????????¨?????????????
//int r[12] : ???????????±?????????0??????N-1???????????????????????????????????????????????????????´???????
double Solve(int r[12]) {
	double score = Evaluate(r); //?????¨?????¶???r[]????¨???????????´????????????°
	double mi = score; //???????????§?????¶???????¨???????????°???????????´????????????°
	for (int cnt = 0; cnt < LOOP; cnt++)
	{
		int a = rand() % N, b = rand() % N;
		swap(r[a], r[b]);
		double tmpev;
		if ((tmpev = Evaluate(r)) < mi) {
			mi = tmpev;
			continue;
		} else if (mi == tmpev) continue;
		if (Changes(cnt)) {
			mi = min(mi, tmpev);
			continue;
		}
		swap(r[a], r[b]);
	}
	return mi; //????°?????????????
}

//??\?????¢????????????????????¢????????£????????§???????????????
int main() {
	while (cin >> L)
	{
		N = 0;
		int r[12];
		string S;
		getline(cin, S);
		stringstream SS(S);
		while (!SS.eof()) SS >> r[N++];

		double ans;
		if (N == 1) ans = r[0]*2;
		else ans = Solve(r);

		if (L - ans + EPS > 0) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
using ll = int64_t;

int main() {
  ll H,W;
  cin >> H >> W;
  ll INF = static_cast<ll>((H+1)*W);
  vector<ll> A(H, 0);
  vector<ll> B(H, 0);
  for(ll i=0; i<H; i++) {
    cin >> A[i] >> B[i];
  }
  map<ll,ll> M;
  multiset<ll> V;
  for(ll i=1; i<=W; i++) {
    M.insert(make_pair(i, 0));
    V.insert(0);
  }
  for(ll i=0; i<H; i++) {
    ll bp1 = INF;
    auto it = M.lower_bound(A[i]);
    while(true) {     
      if(it != M.end() && it->first<=B[i]) {
        bp1 = min(bp1, it->second + (B[i]+1-it->first));
        V.erase(V.find(it->second));
        M.erase(it++);
      } else {
        break;
      }
    }
    if(bp1 < INF && B[i]+1<=W) {
      if((M.count(B[i]+1)==0))
      	M[B[i]+1] = bp1,V.insert(bp1);
      else{
      	if(M[B[i]+1]>bp1)
          V.erase(V.find(M[B[i]+1])),M[B[i]+1]=bp1,V.insert(bp1);
      }
    }
    if(V.empty()) {		
      while(i<H)
		cout<<-1<<"\n",++i;
      return 0;
    } else {
      cout << ((*V.begin())+i+1) << endl;
    }
  }
}


Measured memory_bytes: 28200
x,y = map(int,input().split());
large = x*4;
small = x*2;
flag = False;
for i in range(small,large+1,2):
    if(i==y):
        flag = True;
        break;
if flag :
    print("Yes");
else:
    print("No");


# 5

# 4   2
# 5   0 = 20;
# 4   1 = 18;
# 3   2 = 16;
# 2   3 = 14;
# 1   4 = 12;
# 2   5 = 10;



Measured memory_bytes: 61964
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int n;
    double x1,y1,x2,y2,x3,y3,x4,y4;
    double EPS = 1e-10;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if ( abs((y4-y3)*(x2-x1)-(y2-y1)*(x4-x3))<EPS ) {
            cout<<"YES"<<endl;
        } else {
            cout<<"NO"<<endl;
        }
    }
}


Measured memory_bytes: 3052
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
bool F[50005];
int main(){
	for(int i=3;i<=50002;i+=2){F[i]=true;
		for(int j=3;j*j<=i;j+=2)
			if(i%j==0)F[i]=false;
	}
	F[2]=true;

	int n;
	while(1){
		cin>>n;if(n==0)break;
		int c=0;int P=n/2;

		for(int i=2;i<=P;i++)
		{if(F[i]==true&&F[n-i]==true)c++;}
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    int n,k,a[100],i,j,l,r,q,d,c=0,f=0,fo=0,found=0;
    map<int,int>p;
    vector<int>v;
    vector<int>x;
    cin>>n>>k;q=n;
    for(i=0;i<k;i++){
        cin>>a[i];
        p[a[i]]=1;}
    while(q!=0)
    {
        c++;
        r=q%10;
        v.pb(r);
        q=q/10;
    }j=v.size()-1;d=c;
    while(p[v[j]]==0&&j>=0)
    { x.pb(v[j]);found=1;
    j--;
    }
    if(j>=0){
    for(i=v[j]+1;i<=9;i++)
    {
        if(p[i]==0)
        {
            x.pb(i);f=1;
            break;
        }
    }
    if(f==0)
    {
        if(found==1)
            x.clear();
        for(i=1;i<v[j];i++)
        {
            if(p[i]==0)
            {
            x.pb(i);fo=1;
            break;
            }
        }
    }
    for(i=0;i<=9;i++)
    {
        if(p[i]==0)
        {
            l=i;break;
        }
    }
    for(i=0;i<x.size();i++)
        cout<<x[i];
    if(f==1)
    {
        d=d-x.size();
       while(d--)
            cout<<l;
    }
    if(fo==1)
    {
        while(d--)
            cout<<l;
    }
    }
    if(found==1&&f==0&&fo==0)
    {
        for(i=0;i<x.size();i++)
        cout<<x[i];
    }
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println((b - a - 1) % 2 == 0 ? "Borys" : "Alice");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


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

#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define maxn 3000

using namespace std;

int n;
double A[maxn], F[maxn][maxn];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
    FOR(i, 1, n) cin >> A[i];
    F[0][0] = 1;
    FOR(i, 1, n)
    FOR(j, 0, i) {
        F[i][j] = F[i-1][j] * (1-A[i]);
        if (j-1 >= 0)
            F[i][j] += F[i-1][j-1] * A[i];
    }
    double res = 0;
    FOR(i, (n/2) + (n%2), n)
        res += F[n][i];
    cout << setprecision(11) << res;
	return 0;
}


Measured memory_bytes: 68992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
constexpr int INF = 1e9;
constexpr long long INFLL = 1LL<<60;

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

  string s, t;
  cin >> s >> t;

  vector<vector<int>> pos(26, vector<int>());
  for (int i = 0; i < s.size(); i++) {
    pos[s[i] - 'a'].push_back(i);
  }

  int idx = 0;  // 次の文字を探し始める場所
  ll num = 0;
  ll ans = 0;
  for (char& c : t) {
    auto itr = lower_bound(ALL(pos[c - 'a']), idx);
    if (idx != 0 && itr == pos[c - 'a'].end()) {
      idx = 0;
      num++;
      itr = lower_bound(ALL(pos[c - 'a']), idx);
    }
    if (itr == pos[c - 'a'].end()) {
      cout << -1 << endl;
      return 0;
    }
    ans = s.size() * num + *itr + 1;
    idx = *itr + 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1228
N = int(input())

def dfs(x):
    memo = [0]*(x+1)
    def _dfs(x):
        if x == 0:
            return 2
        elif x == 1:
            return 1
        elif memo[x] != 0:
            return memo[x]
        else:
            memo[x] = _dfs(x-1) + _dfs(x-2)
            return memo[x]
    return _dfs(x)

print(dfs(N))

Measured memory_bytes: 3060
n, k = map(int, input().split())
dl = []
for i in range(n):
  d = i + 1
  dl.append(d)
bnl = []
rnl = []
for i in range(n):
  rn = dl[i]
  bn = 0
  while (True):
    if rn < k:
      rn *= 2
      bn += 1
    else:
      break
  if bn >= 0:
    bnl.append(bn)
    rnl.append(rn)
pl = []
for i in range(n):
  p = (1 / n) * (1 / 2) ** bnl[i]
  pl.append(p)
print(sum(pl))

Measured memory_bytes: 11784
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  VI a(n);
  REP(i, n) cin >> a[i];

	using D = uniform_int_distribution<ll>;
  random_device rd;
  mt19937 gen(rd());

  map<int, int> hash;
  REP(i, n) {
    if(hash.find(a[i]) != hash.end()) continue;
	  hash[a[i]] = D(0,LLINF)(gen);
  }

  int x = 0;
  VI ans;
  REP(i, n) {
    x += hash[a[i]];
    x -= hash[a[n-i-1]];
    if(x == 0) ans.PB(i+1);
  }

  REP(i, ans.size()) {
    cout << ans[i] << (i==ans.size()-1?"\n":" ");
  }

  return 0;
}



Measured memory_bytes: 6876
ABCD = list(map(int,input()))

ansStr = ""

for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            ansNum = ABCD[0]
            if i == "+":
                ansNum += ABCD[1]  
            else:
                ansNum -= ABCD[1]
            if j == "+":
                ansNum += ABCD[2]  
            else:
                ansNum -= ABCD[2]
            if k == "+":
                ansNum += ABCD[3]  
            else:
                ansNum -= ABCD[3]
                
            #print(ansNum)
            if ansNum == 7:
                ansStr = str(ABCD[0]) + i + str(ABCD[1]) + j + str(ABCD[2]) + k + str(ABCD[3]) + "=7"
                break
print(ansStr)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

using namespace std;

int A,B,K;

vector<int>v;

int main()
{
    cin >> A >> B >> K;
    for (int i=1;i<=min(A,B);i++)
    {
        if (A%i==0&&B%i==0)v.pb(i);
    }
    cout << v[v.sz()-K] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define RFOR(i,a,b) for(ll i=b-1;i>=a;i--)
#define rsort(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll mod=1000000007;

signed main(){
 ll n,s,sum,ans=0,ans2=0;
 cin>>n;
 vl a(n);
 rep(i,n)cin>>a[i];

 sum = 0,s=1;
 rep(i,n){
     s*=-1;
     sum += a[i];
     if(sum * s <= 0)ans+=abs(sum-s),sum=s;
 }
 sum = 0,s=-1;
 rep(i,n){
     s*=-1;
     sum += a[i];
     if(sum * s <= 0)ans2+=abs(sum-s),sum=s;
 }
    cout << min(ans, ans2) << endl;
}

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

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

  if (N <= A) {
    cout << "Yes" << endl;
  }
  else if ((N % 500) <= A ) {
    cout << "Yes" << endl;
  }
  else if (!((N % 500) <= A )) {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n;

	long long cnt[100001] = { 0, };

	long long sum = 0;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		long long input;

		scanf("%lld", &input);

		cnt[input]++;

		sum += input;
	}

	int q;

	scanf("%d", &q);

	for (int i = 0; i < q; i++)
	{
		long long b, c;

		scanf("%lld %lld", &b, &c);

		sum += cnt[b] * (c - b);

		cnt[c] += cnt[b];
		cnt[b] = 0;

		printf("%lld\n", sum);
	}

	return 0;
}

Measured memory_bytes: 2516
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int x,y,a,b,c,i,imaze,ir,kotae=0;
  cin>>x>>y>>a>>b>>c;
  int red[a],green[b],mu[c],maze[x+y];
  for(i=0;i<a;i++){
    cin>>red[i];
  }
  sort(red,red+a);
  for(i=0;i<b;i++){
    cin>>green[i];
  }
  sort(green,green+b);  
  for(i=0;i<c;i++){
    cin>>mu[i];
  }
  sort(mu,mu+c);
  for(i=0;i<x;i++){
    maze[i]=red[a-1-i];
  }
  for(i=0;i<y;i++){
    maze[x+i]=green[b-1-i];
  }
  sort(maze,maze+x+y);
  imaze=x+y-1;
  ir=c-1;
  for(i=0;i<x+y;i++){
    if(maze[imaze]>mu[ir]){
      kotae+=maze[imaze];
      imaze--;
    }else{
      kotae+=mu[ir];
      ir--;
    }
  }
  cout<<kotae;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
//#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll N, A, B; cin >> N >> A >> B;
    if(A > B) {
        cout << 0 << endl;
    }else if(A == B || N == 2) {
        cout << 1 << endl;
    }else if(N == 1) {
        cout << 0 << endl;
    }else {
        cout << (N - 2) * (B - A) + 1 << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String temp = s.substring(0, 1);

		int len = s.length();
		int i;
		for(i = 1; i < len; i++) {
			if(temp.equals(s.substring(i, i + 1))){
				System.out.println("Bad");
				return;
			}else {

				temp = s.substring(i, i + 1);
			}
		}
		System.out.println("Good");
	}
}


Measured memory_bytes: 23380
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        boolean[] sunuke = new boolean[n];

        for (int i = 0; i < k; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                int a = sc.nextInt();
                sunuke[a - 1] = true;
            }
        }

        int ans = 0;

        for (boolean b : sunuke) {
            if (!b) {
                ans++;
            }
        }
        
        System.out.println(ans);
    }
}


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

int main()
{
    int n;
    cin >> n;
    unordered_map<string, long> mp;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    long ans = 0;
    for (auto& p : mp) {
        ans += (p.second * (p.second - 1)) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10660
import sys
input = sys.stdin.readline
def main():
    K = int(input())
    A, B = map(int, input().split())
    OK = False
    for i in range(A,B+1):
        if i%K == 0:
            print("OK")
            OK = True
            break
    if OK == False:
        print("NG")

if __name__ == '__main__':
    main()

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

using namespace std;
// (setq-default c-basic-offset 2)

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

  set<string> s;
  for (int i = 0; i < n; ++i) {
    string si;
    cin >> si;
    s.insert(si);
  }
  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 19192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int day;
  cin>>day;
  cout<<"Christmas";
  rep(i,25-day){
    cout<<" Eve";
  }
  cout<<endl;
}
    
  


Measured memory_bytes: 256
#include "iostream"
#include "string"
#include "stdio.h"
#include "ctype.h"
#include "algorithm"
#include "stack"
#include "cmath"
#include "cstring"
#include "iomanip"
using namespace std;
const double PI=acos(-1.0);
int main()
{
    int R;
    scanf("%d",&R);
    cout.unsetf(ios::fixed);
    cout<<fixed<<setprecision(20)<<2*PI*R<<endl;
    return 0;
}


Measured memory_bytes: 3872
while str = gets
  break if str =~ /EOF/
  buf = str.split.sort.collect{|num| num.to_i}
  loop do
    remainder = buf[1] % buf[0]
    if remainder == 0
      puts buf[0]
      break
    end
    buf[1] = buf[0]
    buf[0] = remainder
  end
end

Measured memory_bytes: 6020
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int n;
  cin>>n;
  vi a(n);
  cin>>a;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3==0 or a[i]%5==0 ){

      }else{
        cout<<"DENIED"<<endl;
        return;
      }
    }
  }
        cout<<"APPROVED"<<endl;
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

int main() {
    int N;
    cin >> N;
    int f_N = 0, i = N;
    while (i > 0) {
        f_N += i % 10;
        i /= 10;
    }
    if (N % f_N == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}    

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

using int64 = long long;

int64 Solve(const vector<int64>& a) {
  int64 ret = 0;
  int64 b = -1;
  for (int i = a.size() - 1; i >= 0; --i, --b) {
    if (a[i] < b) {
      return -1;
    } else if (a[i] > b) {
      ret += a[i];
      b = a[i];
    }
  }
  if (b != -1)
    return -1;
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int64> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  cout << Solve(a) << "\n";
  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  string ans;
  if (A + B > C + D)
    ans = "Left";
  else if (A + B < C + D)
    ans = "Right";
  else
    ans = "Balanced";

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


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

using namespace std;

int main()
{
	long long int cost;
	int a,b,n,m,i,rem;
	vector< pair<int, int> > v;

	cin >> n >> m;
	for(i=0; i<n; i++)
	{
		cin >> a >> b;
		v.push_back({a, b});
	}
	sort(v.begin(), v.end());
	rem=m;
	cost=0;
	for(i=0; i<n; i++)
	{
		if(rem == 0)
			break;
		if(v[i].second >= rem)
		{
			cost += (long long)(v[i].first) * rem;
			rem = 0;
		}
		else
		{
			cost += (long long)(v[i].first) * (v[i].second);
			rem -= v[i].second;
		}
	}
	cout << cost << endl;
	return 0;
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
int S, T;
vector<int> f[100100];
int d0[100100];
int d1[100100];
int d2[100100];

void bfs() {
    memset(d0, -1, sizeof(d0));
    memset(d1, -1, sizeof(d1));
    memset(d2, -1, sizeof(d2));
    queue<pii> que;
    que.push(pii(S, 0));
    while (!que.empty()) {
        pii p = que.front();
        que.pop();
        int u = p.first;
        int dist = p.second;
        if (dist % 3 == 2) {
            if (d2[u] != -1)continue;
            d2[u] = dist;
            for (int to:f[u]) {
                que.push(pii(to, dist + 1));
            }
        } else if (dist % 3 == 0) {
            if (d0[u] != -1)continue;
            d0[u] = dist;
            for (int to:f[u]) {
                que.push(pii(to, dist + 1));
            }
        } else {
            if (d1[u] != -1)continue;
            d1[u] = dist;
            for (int to:f[u]) {
                que.push(pii(to, dist + 1));
            }
        }
    }
}

signed main() {
    cin >> N >> M;
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        f[u].push_back(v);
    }
    cin >> S >> T;
    --S, --T;
    bfs();
    if (d0[T] == -1) {
        cout << -1 << endl;
    } else {
        cout << d0[T] / 3 << endl;
    }
    return 0;
}


Measured memory_bytes: 9216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 * Property Distribution
 */
public class Main {

	static char DISTRIBUTED = '\0';
	static Queue<Integer> xs, ys;
	static int count;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {

			int h = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int w = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			// read in.
			char[][] prop = new char[h + 2][w + 2];
			for (int i = 1; i < h + 1; ++i) {
				line = br.readLine();
				for (int j = 1; j < w + 1; ++j) {
					prop[i][j] = line.charAt(j - 1);
				}
			}

			// solve
			xs = new ArrayDeque<Integer>();
			ys = new ArrayDeque<Integer>();
			count = 0;
			for (int i = 1; i < h + 1; ++i) {
				for (int j = 1; j < w + 1; ++j) {
					if (prop[i][j] != DISTRIBUTED) {
						char fruit = prop[i][j];
						xs.add(i);
						ys.add(j);
						while (!xs.isEmpty() && !ys.isEmpty()) {
							distribute(prop, fruit);
						}
						++count;
					}
				}
			}

			// print
			System.out.println(count);
		}
	}

	static void distribute(char[][] prop, char fruit) {

		final int V[] = { 1, -1, 0, 0 };
		final int H[] = { 0, 0, 1, -1 };

		int x, y;
		x = xs.poll();
		y = ys.poll();

		if (prop[x][y] == fruit) {

			prop[x][y] ^= prop[x][y];

			for (int i = 0; i < 4; ++i) {
				int xv, yh;
				xv = x + V[i];
				yh = y + H[i];
				if (prop[xv][yh] == fruit) {
					xs.offer(xv);
					ys.offer(yh);
				}
			}
		}
	}
}

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


Measured memory_bytes: 2120
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int c = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == 'o') c++;
  }
  cout << c*100+700 << endl;
}
  


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    ll ans = 0;
    for (int i = k; i < n; i++) ans += h[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    int N;cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i,N){
        cin >> A[i];
        B[i] = A[i];
    }
    sort(rall(B));
    rep(j,N){
        if(A[j] != B[0]){
            cout << B[0] << endl;
        }
        else{
            cout << B[1] << endl;
        }
    }
}

Measured memory_bytes: 3200