akhauriyash/Code-Regression huggingface dataset:
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
flag = True

for i in range(0,N-1):
  T = L[i+1][0]-L[i][0]
  X = L[i+1][1]-L[i][1]
  Y = L[i+1][2]-L[i][2]
  if (T % 2 != (X+Y) % 2):
    flag = False
    break
  else:
    if (T < X+Y):
      flag = False
      break
if flag:
  if(L[0][0] % 2 != (L[0][1]+L[0][2]) % 2):
    flag = False
  else:
    if (L[0][0] < L[0][1]+L[0][2]):
      flag = False

if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 27324
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int n, x, t;
    cin >> n >> x >> t;
    if(n % x == 0) cout << n / x * t << endl;
    else  cout << (n / x + 1) * t << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N=50005;
ll a[200005],b[200005];
ll t[200005];
int main()
{
    ll n;
    scanf("%lld",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t[i]);
        a[t[i]]++;
    }
    ll sum=0;
    for(int i=0;i<200005;i++)
    {
        if(a[i]>1)b[i]=(a[i]-1)*a[i]/2;
        sum+=b[i];
    }
    for(int i=0;i<n;i++)
    {
        printf("%lld\n",sum-a[t[i]]+1);
    }
    return 0;
}


Measured memory_bytes: 6272
#include <stdio.h>

int main(void)
{
  int n,k,tmp;
  int sum=0;
  int p[10000];
  scanf("%d %d", &n, &k);
  for(int i=1;i<=n;i++){
    scanf("%d", &p[i]);
  }
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      if(p[i]>p[j]){
	tmp = p[i];
	p[i] = p[j];
	p[j] = tmp;
      }
    }
  }
  for(int i=1;i<=k;i++){
    sum += p[i];
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 1692
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int x=sc.nextInt();
		int n=0;
		for (int i=0;i<(a+1);i++){
			for (int j=0;j<(b+1);j++){
				for (int k=0;k<(c+1);k++){
					if (500*i+100*j+50*k==x){
						n+=1;
					}
				}
			}
		}
		System.out.println(n);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
int k,a,b; 
int s=0;
cin>>k>>a>>b;
for(int i=a;i<=b;i++){
    if(i%k==0)s=1;
}
if(s==1)cout<<"OK"<<endl;
else cout<<"NG"<<endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        while (true) {
            C -= B;
            if(C <= 0){
                System.out.println("Yes");
                return;
            }
            A -= D;
            if(A <= 0){
                System.out.println("No");
                return;
            }
        }
    }
}


Measured memory_bytes: 35548
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
using namespace std;





int main() {

	//cout << fixed << setprecision(10);
	int n, c[1000], s[1000], f[1000],t=0;
	cin >> n;
	for (int i = 1; i <= n-1; i++) {
		cin >> c[i] >> s[i] >> f[i];
		
	}
	for (int i = 1; i <= n; i++) {
		t = 0;
		for (int j = i; j <= n-1; j++) {
			if (t < s[j]) {
				t = s[j] + c[j];
				
			}
			else {
				t = (((t-1) / f[j])+1) * (f[j]) + c[j];
			}
			
		}
		cout << t << endl;
	}
}


Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

S = sum(a_list)
from itertools import accumulate
# a_list.index(0, 0)
acc = list(accumulate(a_list))

ans = float("inf")
for i in range(N):
    ans = min(ans, abs((S - acc[i]) - acc[i]))

print(ans)


Measured memory_bytes: 26220
N = int(input())
a = [[] for i in range(N)]
ans = 0
for i in range(N):
    times = int(input())
    for j in range(times):
        a[i].append(tuple(map(int, input().split())))

for i in range(2 ** N):
    flag2 = False
    cnt = 0
    flag = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            flag[j] = 1
    for k in range(N):
        if flag[k] == 1:
            for m in range(len(a[k])):
                x, y = a[k][m]
                if flag[x - 1] != y:
                    flag2 = True
                    break
        if flag2:
            break
        if k == N - 1:
            cnt = flag.count(1)

    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x = max(x, y)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

struct mint {
  ll x;
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MAX = 510000;

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;
    }
}

// 二項係数計算
mint 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;
}


int main()
{
    int s;
    cin >> s;
    int maxlen = s / 3;
    mint ans = 0;
    COMinit();
    for(int i = maxlen; i > 0; --i) {
        int rest = s - 3 * i;
        mint x = COM(rest + i - 1, rest);
        ans += x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15572
N,M=map(int,input().split())
S=input()
T=input()

def gcd(a,b):
  return gcd(b, a%b) if b != 0 else a

def lcm(a,b):
  return a * b // gcd(a,b)

g = gcd(N, M)
i, j = 0, 0
ok = True
while i < N and j < M:
  if S[i] != T[j]:
  	ok = False
  i += N // g
  j += M // g
if ok:
  print(lcm(N,M))
else:
  print(-1)

Measured memory_bytes: 3316
#初期data
input_number = int(input())
input_list = list()

#アルゴリズム
for i in range(input_number):
    input_data = int(input())
    if i == 0:
        difference_mix = input_data
    elif i == 1:
        difference_max = input_data - difference_mix
        if difference_mix > input_data:
            difference_mix = input_data
    else:
        if difference_max < input_data - difference_mix:
            difference_max = input_data - difference_mix
        if difference_mix > input_data:
            difference_mix = input_data

#処理の実行
print(difference_max)



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main()
{

long long a,b,c,d,e,i,j,k=0,l=0;
map<long long,long long>p;
vector<long long>v;

cin>>a>>b;
for(i=1;i<=b;i++)
{
  cin>>c>>d;
if(c==1)v.push_back(d);
if(d==1)v.push_back(c);

if(c==a)p[d]=1;
if(d==a)p[c]=1;

}

for(i=0;i<v.size();i++)
{
//cout<<v[i]<<p[v[i]];

  if(p[v[i]]==1)l=1;
}

if(l==1)cout<<"POSSIBLE\n";
else
cout<<"IMPOSSIBLE\n";
}

Measured memory_bytes: 13556
N = int(input())
nM = 0
nA = 0
nR = 0
nC = 0
nH = 0
for i in range(N):
  S = input()
  if S[0] == "M": nM += 1
  if S[0] == "A": nA += 1
  if S[0] == "R": nR += 1
  if S[0] == "C": nC += 1
  if S[0] == "H": nH += 1
r = 0
r += nM*nA*nR
r += nM*nA*nC
r += nM*nA*nH
r += nM*nR*nC
r += nM*nR*nH
r += nM*nC*nH
r += nA*nR*nC
r += nA*nR*nH
r += nA*nC*nH
r += nR*nC*nH
print(r)


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

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

int main(){
    string a; cin >> a;
    if(a[a.size()-1] == 's') a+= "es";
    else a += "s";
    
    cout << a << endl;
}

Measured memory_bytes: 3620
import sys

n = int(sys.stdin.readline())
m = map(int, sys.stdin.read().split())
ab = list(zip(m, m))

ab.sort(key=lambda x: x[1])
ans = 'Yes'
time = 0
for a, b in ab:
    time += a
    if time > b:
        ans = 'No'
        break
print(ans)


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, T, A;
    double mini = DBL_MAX;
    ll miniIndex;
    cin >> N >> T >> A;
    for(ll i = 0;i < N;i++) {
        double temp;
        double temper;
        double diff;
        cin >> temp;
        temper = T - temp * 0.006;
        diff = abs(A - temper);
        if(diff < mini) {
            mini = diff;
            miniIndex = i;
        }
    }
    cout << miniIndex + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
l = []
sumB = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    l.append(tmp[0] + tmp[1])
    sumB += tmp[1]
l.sort(reverse=True)
A = 0
for i in range(N):
    if i % 2 ==0:
        A += l[i]
print(A - sumB)

Measured memory_bytes: 7504
#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb insert
#define pf push_front
#define fi first
#define se second
#define mod 1000000007
using namespace std;

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

set<ll> graph[200005];
bool vis[200005];
ll cc=0;

ll dfs(ll v){
	vis[v]=1;
	cc++;
	for(auto u:graph[v]){
		if(!vis[u]){
			dfs(u);
		}
	}
	return cc;
}

int main(){
    fast();
    ll t=1;
//    cin>>t;
    while(t--){
    	ll n,m;
    	cin>>n>>m;
    	
    	for(ll i=0;i<m;i++){
    		ll x,y;
    		cin>>x>>y;
    		x--,y--;
    		graph[x].pb(y);
    		graph[y].pb(x);
		}
		ll ans=0;
		for(ll i=0;i<n;i++){
			if(!vis[i]){
				cc=0;
				ans=max(dfs(i),ans);
			}
		}
		cout<<ans;
	}
}

Measured memory_bytes: 38212
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)..., (os << '\n', 0)}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__)
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on



ll n;

auto Run() {
	cin>>n;
	auto s = n*(n+1)/2;
	auto n3 = n/3, n5=n/5, n15 = n/15;
	s -= n3*(n3+1)/2 * 3;
	s -= n5*(n5+1)/2 * 5;
	s += n15*(n15+1)/2 * 15;
	cout << s;	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Run();
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main()
{
    /*string s;
    cin>>s;
    int count=0;
    if(s[0]=='R' ||s[1]=='R' ||s[2]=='R') count++;
    if(s[1]=='R' && s[0]=='R') count++;
    if(s[2]=='R' && s[1]=='R') count++;
    cout<<count<<endl;*/
    int n, count=0;
    cin>>n;
    set<int> s;
    map<int, int> m;
    int a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
        s.insert(a[i]);
        if(m.find(a[i])!=m.end()) m[a[i]]++;
        else m[a[i]]=1;
    }
    //int si=s.size();
    int in=0, jn=0, kn=0; auto ran=s.begin();
    for(auto i=s.begin();i!=s.end();i++, in++)
    {
        ran=i; jn=in+1; auto j=++ran;
        for(j;j!=s.end();j++, jn++)
        {
            ran=j; kn=jn+1; auto k=++ran;
            for(k;k!=s.end();k++, kn++)
            {
                if(*i + *j > *k)
                {
                    count+=(m[*i]*m[*j]*m[*k]);
                    //cout<<*i<<" "<<*j<<" "<<*k<<": "<<m[*i]<<" "<<m[*j]<<" "<<m[*k]<<endl;
                }
            }
        }
    }
    cout<<count<<endl;
} 

Measured memory_bytes: 3636
n = int(input())
sp = [list(input().split())+[i] for i in range(1,n+1)]
for i in range(n):
	sp[i][1] = int(sp[i][1])
sp.sort(key=lambda x:(x[0],x[1]))
# print(sp)
# sp.sort()
ans = []
sp.append(['hoge000'])
for i in range(n):
	if sp[i][0] == sp[i+1][0]:
		ans.append(sp[i])
		continue
	else:
		if len(ans):
			print(sp[i][2])
			for a in ans[::-1]:
				print(a[2])
			ans = []
			continue
		else:
			print(sp[i][2])

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

int main(){
    vector<int> v;
    int n;
    for(int i = 0; i < 3; i++){
        cin >> n;
        v.push_back(n);
    }
    sort(v.begin(), v.end());
    int s, r, sum;
    s = (v[2]-v[1])/2;
    r = (v[2]-v[0])/2;
    sum = s+r;
    if(v[2] == v[1] + s*2){
        if(v[2] != v[0] + r*2) sum = sum+2;
    }
    else{
        if(v[2] != v[0] + r*2) sum = sum+1;
        else sum = sum+2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
/*
  AOJ 0595
  Title:Schedule
  @kankichi573
*/
#include <stdio.h>

int N;
char sekinin[1001];
int memo[10001][2][2][2]; 
char mem[3]="JOI";

int solve(int j,int o,int i,int day)
{
  char sek,next;
  int j_f,o_f,i_f,l,ret;

  ret=memo[day][j][o][i];
  if(ret>0)
    return(ret);
  sek=sekinin[day];

  if(day==N-1)
    if(j+o+i==3)
      return(4);
    else if(j+o+i==2)
      {
	if((j && sek=='J')||(o && sek=='O')||(i && sek=='I'))
	  return(4);
	else
	  return(3);
      }
    else if(j+o+i==1)
      {
	if((j && sek=='J')||(o && sek=='O')||(i && sek=='I'))
	  return(4);
	else
	  return(2);
      }
  next=sekinin[day+1];
  for(l=1,ret=0;l<=7;l++)
    {
      j_f=(l&1);
      o_f=(l&2)>>1;
      i_f=(l&4)>>2;
      if(((j_f && j)||(o_f && o)||(i_f && i)) && 
	 ((j_f && sek=='J')||(o_f && sek=='O')||(i_f && sek=='I')))
	{
	  ret += solve(j_f,o_f,i_f,day+1);
	  ret %= 10007;
	}
    }
  memo[day][j][o][i]=ret;
  return(ret);
}
main()
{
  int ret;

  scanf("%d",&N);
  scanf("%s",&sekinin[0]);
    ret=solve(1,0,0,0);  //'J' first 
  printf("%d\n",ret);
  return(0);
}

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

int main(){
	int n,c = 0,a[5] = {0},b[3] = {0},i;
	while(cin >> n && n){
		a[c] = n;
		b[n-1]++;
		if(c == 4){
			if(b[0] > 0 && b[1] > 0 && b[2] > 0){
				for(i = 0;i<5;i++){
					cout << 3 << endl;
					a[i] = 0;
				}
			}
			else if(b[0] == 5 || b[1] == 5 || b[2] == 5){
				for(i = 0;i < 5;i++){
					cout << 3 << endl;
					a[i] = 0;
				}
			}
			else{
				if(b[0] > 0 && b[1] > 0){
					for(i = 0;i<5;i++){
						if(a[i] == 1) cout << 1 << endl;
						else cout << 2 << endl;
						a[i] = 0;
					}
				}
				else if(b[0] > 0 && b[2] > 0){
					for(i = 0;i<5;i++){
						if(a[i] == 3) cout << 1 << endl;
						else cout << 2 << endl;
						a[i] = 0;
					}
				}
				else{
					for(i = 0;i<5;i++){
						if(a[i] == 2) cout << 1 << endl;
						else cout << 2 << endl;
						a[i] = 0;
					}
				}
			}
			for(i=0;i<3;i++){
				b[i] = 0;
			}
			c = 0;
		}
		else{
			c++;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,res=1;
  cin >> N;
  for(ll i=1;i<=N;i++)
    res = (res*i)%MOD;
  cout << res << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using ll=long long;
using namespace std;

int main(){
    int R,C,K;
    cin>>R>>C>>K;
    vector<vector<int>> item(R+1,vector<int>(C+1,0));
    int r,c,v;
    for(int i=0;i<K;i++){
        cin>>r>>c>>v;
        item[r][c]=v;
    }
    
    vector<vector<vector<ll>>> dp(R+1,vector<vector<ll>>(C+1,vector<ll>(4,0)));
    for(int i=1;i<=R;i++){
        for(int j=1;j<=C;j++){
            for(int k=0;k<4;k++){
                dp[i][j][0]=max(dp[i-1][j][k],dp[i][j][0]);
                dp[i][j][1]=max(dp[i-1][j][k]+item[i][j],dp[i][j][1]);
            }
            dp[i][j][0]=max(dp[i][j][0],dp[i][j-1][0]);
            dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][0]+item[i][j]);
            dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][1]);
            for(int k=2;k<4;k++){
                dp[i][j][k]=max(dp[i][j-1][k-1]+item[i][j],dp[i][j-1][k]);
            }
        }
    }
    ll ans=0;
    for(int i=1;i<4;i++){
        if(ans<dp[R][C][i]){
            ans=dp[R][C][i];
        }
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 671812
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void AGC035A()
{
	int N;
	cin >> N;
	int x = 0;
	for (int i = 0; i < N; ++i)
	{
		int y;
		cin >> y;
		x ^= y;
	}
	cout << (x == 0 ? "Yes" : "No") << endl;
}
int main()
{
	AGC035A();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//using namespace __gnu_pbds;
pll for_eachstring(string str){
	ll diff = 0;
	ll neg = 0;
	loop(i, 0, str.size()){
		if(str[i] == '(')
			diff++;
		else
			diff--;
		neg = max(neg, -1 * diff);
	}
	return {neg, diff};
}

bool comp(pll a,pll b){
	return (a.y - a. x) < (b.y - b.x);
}
int main(){
	IOS;
	ll n;
	cin >> n;
	string str[n + 1];
	loop(i, 1, n + 1)
		cin >> str[i];
	
	vector<pll> data, neg;
	loop(i, 1, n + 1){
		pll temp = for_eachstring(str[i]);
		data.pb(temp);
	}
	
	sort(all(data));
	ll ok = 1, net_gain = 0;
	for(auto & node :data){
		if(net_gain >= node.x && node.y >= 0)
			net_gain += node.y;
		else if(node.y >= 0)
			ok = 0;
		else{
			node.y *= -1;
			neg.pb(node);
		}
	}

	sort(all(neg), comp);
	debug(neg, net_gain);
	for(auto & node : neg){
		if(net_gain >= node.x)
			net_gain -= node.y;
		else
			ok = 0;
	}
	if(net_gain != 0)
		ok = 0;

	cout << (ok == 1 ? "Yes": "No") << endl;
}

Measured memory_bytes: 66144
#include <iostream>
#include <cmath>

using ll = long long;
using namespace std;

/* initialize */
int n;
struct point {double x, y;};
/* main */
void koch(int d, point p1, point p2){
    if (d == 0) return;
    point s{0,0}, t{0,0}, u{0,0};
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
    s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
    t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
    t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
    u.x = (t.x -s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x -s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(d-1,p1 ,s);
    printf("%.8f  %.8f\n", s.x, s.y);
    koch(d-1,s ,u);
    printf("%.8f  %.8f\n", u.x, u.y);
    koch(d-1,u,t);
    printf("%.8f  %.8f\n", t.x, t.y);
    koch(d-1,t,p2);
}
int main() {
    cin >> n;
    point s1{0, 0};
    point s2{100, 0};
    printf("%.8f  %.8f\n", s1.x, s1.y);
    koch(n,s1,s2);
    printf("%.8f  %.8f\n", s2.x, s2.y);
    return 0;
}


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

int main(){
	string s,t;
  cin>>s>>t;
  
  int m=s.size(),n=t.size();
  string temp="";
  if(m==0||n==0){
  	cout<<temp<<"\n";
    return 0;
  }
  int res[m+1][n+1];
  
  for(int i=0;i<=m;i++)
    for(int j=0;j<=n;j++){
    	if(i==0 || j==0){
          res[i][j]=0;
        }
      else
        res[i][j]=(s[i-1]==t[j-1])?1+res[i-1][j-1]:max(res[i-1][j],res[i][j-1]);
    }
  
  int i=m,j=n;
  while(i>0 && j>0){
  	if(s[i-1]==t[j-1]){
    	temp=s[i-1]+temp;
      i--;
      j--;
    }
    else if(res[i-1][j]<res[i][j-1])
      j--;
    else i--;
  }
  
  cout<<temp<<"\n";
  return 0;
}

Measured memory_bytes: 35456
s_d = input()
t = input()
s_d = s_d[::-1]
t = t[::-1]
t_r = ''

for i in range(len(s_d)-len(t)+1):
    for j in range(len(t)):
        if s_d[i+j] == t[j] or s_d[i+j] == '?':
            t_r += s_d[i+j]
            continue
        else:
            t_r = ''
            break
    else:
        s = s_d.replace(t_r, t, 1)
        s = s.replace('?', 'a')
        print(s[::-1])
        break
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
loop do
  t, h, s = gets.split.map(&:to_i)
  break if t == -1 && h == -1 && s == -1
  e = t * 3600 + h * 60 + s
  r = 120 * 60 - e
  puts '%02d:%02d:%02d' % [r / 3600, r / 60 % 60, r % 60]
  r *= 3
  puts '%02d:%02d:%02d' % [r / 3600, r / 60 % 60, r % 60]
end

Measured memory_bytes: 8740
A = list(map(int, input()))
while A[-1] == 0:
  A.pop()
n = len(A)
dp = [[0]*2 for _ in range(n)]
dp[0][1] = 1
for i, a in enumerate(A[:-1]):
  if i < n-1:
    dp[i+1][0] = min(dp[i][0]+a, dp[i][1]+10-a)
    dp[i+1][1] = min(dp[i][0]+a+1, dp[i][1]+9-a)
ans = min(dp[-1][0]+A[-1], dp[-1][1]+10-A[-1])
print(ans)

Measured memory_bytes: 219928
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int A,B;
        A = scan.nextInt();
        B = scan.nextInt();
        double tax8=0.08;
        double tax10=0.10;
        int price=-1;
        for(int i=1;i<=1000;i++){
            if((int)(i*tax8+i)-i==A&&(int)(i*tax10+i)-i==B){
                price = i;
                break;
            }
        }
        System.out.println(price);
    }
}

Measured memory_bytes: 25300
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

int main()
{
    char a[4];
    cin>>a;
    if(a[1]=='B')
        cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
    return 0;
}



Measured memory_bytes: 3588
#include <iostream>
#include<cmath>
#include <iomanip>
using namespace std;

int main() {
	int n;cin>>n;
	int t[n],v[n];
	int time[n];
	for(int i=0;i<n;i++){
		cin>>t[i];
		time[i]=t[i];
		if(i>0)time[i]+=time[i-1];
	}
	for(int i=0;i<n;i++)cin>>v[i];
	int k=2*time[n-1]+1;
	double f[n+2][k];
	for(int i=0;i<n+2;i++){
		int left,right,ve;
		if(i==n){
			left=right=ve=0;
		}else if(i==n+1){
			left=right=time[n-1];;
			ve=0;
		}else{
			if(i==0){
				left=0;
			}else{
				left=time[i-1];
			}
			right=time[i];
			ve=v[i];
		}
		for(int j=0;j<=2*time[n-1];j++){
			if(j<=2*left){
				f[i][j]=ve+left-double(j)/2;
			}else if(j>=2*right){
				f[i][j]=ve+double(j)/2-right;
			}else{
				f[i][j]=ve;
			}
//			cout<<f[i][j]<<' ';
		}
//		cout<<endl;
	}
	double speed[k];
	double ans=0;
	for(int j=0;j<=2*time[n-1];j++){
		speed[j]=f[0][j];
		for(int i=1;i<n+2;i++){
			if(speed[j]>f[i][j]){
				speed[j]=f[i][j];
			}
		}
//		cout<<speed[j]<<' ';
		if(j){
			ans+=(speed[j-1]+speed[j])/2/2;
		}
	}
//	cout<<endl;
	cout<<setprecision(15)<<ans<<endl;

	return 0;
}

Measured memory_bytes: 32384
from collections import deque
import sys, copy, itertools,bisect
input = sys.stdin.readline

def isOK(LIST, index, key):  #key以上で最大のindexを返す
  if LIST[index] <= key:
    return True
  else:
    return False

def meguru_binary_search(LIST, key):
  ng = -1
  ok = len(LIST)
  while abs(ok-ng) > 1:
    mid = (ok + ng) //2 #"//"は切り捨て除算
    if isOK(LIST, mid, key):
      ok = mid
    else:
      ng = mid
  return ok  
  

n = int(input())
A = []
for i in range(n):
  a = int(input())
  A.append(a)
  
#A.reverse()
#print(A)

LDS =[A[-1]] #初期値導入
#LDS=Longest Decreasing Subsequence
 
for i in range(2,n+1):
  x = A[-i]
  index = bisect.bisect_right(LDS,x)
  if index == len(LDS):
    LDS.append(x) #単純に後ろに追加する
  else:
    LDS[index]  = x
    #配列LDSの中で二分探索し、A[i]より小さい最小の位置を求め、その数字を置き換える  

#print(LDS)
print(len(LDS))    

Measured memory_bytes: 80720
n = gets.chomp.to_i
h_arr = gets.chomp.split(" ").map(&:to_i) + [10**9+1]

cur = 0
move = 0
max = 0
h_arr.each do |h|
  if cur >= h then
    move += 1
  else
    max = move if move > max
    move = 0
  end
  cur = h
end

puts max


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

int a[110];

int main() {
    int n;
    scanf("%d", &n);
    bool ok = true;
    for(int i=1; i<=n; i++) {
        scanf("%d", &a[i]);
        if(a[i]&1)
            continue;
        if(a[i]%3==0 || a[i]%5==0)
            continue;
        ok = false;
    }
    if(ok)
        printf("APPROVED\n");
    else
        printf("DENIED\n");
    return 0;
}


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

using namespace std;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   vector<int> a(n);
   for(int i = 0; i < n; i++) {
       cin >> a[i];
   }
   sort(a.rbegin(), a.rend());
   long long ans = 0;
   for(int i = 0; i < n - 1; i++) {
       ans += a[(i + 1) / 2];
   }
   cout << ans << endl;
}

Measured memory_bytes: 3972
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n,x;
	cin>>n;
	int a[110]={0};
	for(int i=1;i<=n;i++){
		cin>>x;
		int nn=0;
		for(int j=1;j<x;j++){
			if(a[j]!=0) nn++;
		}
		if(nn<x-1){
			cout<<-1<<endl;
			return 0;
		}
		for(int j=100;j>=x;j--){
			a[j]=a[j-1];
		}
		a[x]=x;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  char c;
  cin>>c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout<<"vowel";
  }
  else{
    cout<<"consonant";
  }
}

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

int d,e,f;
string a,b,c;

int main(){
	cin>>a>>b>>c;
	d=a.length();
	e=b.length();
	f=c.length();
	a.erase(1,d-1);
	b.erase(1,e-1);
	c.erase(1,f-1);
	a[0]=a[0]-'a'+'A';
	b[0]=b[0]-'a'+'A';
	c[0]=c[0]-'a'+'A';
	cout<<a<<b<<c;
}


Measured memory_bytes: 3612
fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn get_primes(n: usize) -> Vec<usize> {
    let mut spf = vec![None; n+1];
    let mut is_prime = vec![true; n+1];
    let mut primes = Vec::new();

    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n+1 {
        if is_prime[i] {
            primes.push(i);
            spf[i] = Some(i);
        }
        for &prime in primes.iter() {
            if i * prime >= n + 1 || prime > spf[i].unwrap() {
                break;
            }

            is_prime[i * prime] = false;

            spf[i * prime] = Some(prime);
        }
    }
    primes
}

fn main() {
    let x: usize = input_one().unwrap();
    println!("{}", get_primes(100003).into_iter().skip_while(|&a| a < x).next().unwrap());
}


Measured memory_bytes: 3760
//
//  main.cpp
//  tititi
//
//  Created by 大森 亮 on 2014/04/10.
//  Copyright (c) 2014年 大森 亮. All rights reserved.
//

#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)

using namespace std;

bool is_same_number(int a,int b,int c){
    if(a==b&&b==c)
        return 1;
    else return 0;
}

bool is_sequence(int a,int b,int c){
    if((a+1==b)&&(b+1==c))
        return 1;
    else return 0;
}

bool is_good_set(int a,int b,int c){
    return is_same_number(a,b,c) || is_sequence(a,b,c);
}

int T;
int card[16];

int main(int argc, const char * argv[])
{
    cin >> T;
    rep(t,T){
        rep(i,9){
            card[i]=0;
            cin >> card[i];
        }
        string color;
        rep(i,9){
            cin >> color;
            if(color=="G")
                card[i]+=100;
            if(color=="B")
                card[i]+=200;
        }
        sort(card,card+9);
        int flag = 0;
        do{
            if(is_good_set(card[0],card[1],card[2])&&is_good_set(card[3],card[4],card[5])&&is_good_set(card[6],card[7],card[8])){
                flag = 1;
                break;
            }
        }while(next_permutation(card,card+9));
        cout << flag << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N,M;
  cin >> N >> M;
  priority_queue<double> pq;
  REP(i,N){
    double a;
    cin >> a;
    pq.push(a);
  }

  REP(i,M){
    double a = pq.top(); pq.pop();
    a /= 2;
    pq.push(a);
  }
  ll ans=0;
  while(!pq.empty()){
    double a = pq.top(); pq.pop();
    ans += floor(a);
  }
  cout << ans << endl;

}



Measured memory_bytes: 1400
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    int a[11];
    cin >> n;
    int cnt = 1;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i]%2==0)
            cnt *= 2;
    }
    cout << pow(3, n) - cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
#define mo 1000000007
char s[maxn*4],t[maxn*4];
int nex[maxn*4];
void add(char s[],char s1[],int &l,int l1){
	for(int i=0;i<l1;i++)s[i+l]=s1[i];
	l+=l1;
}
void Next(const char a[],int nex[],int l){
	nex[0]=-1;
	for(int i=0,j=-1;i<l;i++){
		while(j!=-1&&a[i]!=a[j])j=nex[j];
		nex[i+1]=++j;
	}
}
int kmp(const char a[],const char b[],int nex[],int l1,int l2){
	int ans=0;
	for(int i=0,j=0;i<l1;i++){
		while(j==l2||(j!=-1&&a[i]!=b[j]))j=nex[j];
		ans=max(ans,++j);
	}
	return ans;
}
int main(){
	scanf("%s%s",s,t);
	int l=strlen(s),l1=strlen(t),l2=l,l3=l1;
	while(l3<l+l1)add(t,t,l3,l1);
	while(l2<l+l1*2)add(s,s,l2,l);
	Next(t,nex,l3);
	int ans=kmp(s,t,nex,l2,l3);
	if(ans>=l+l1)ans=-1;
	else ans/=l1;
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 11520
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N, W;
  cin >> N >> W;
  vl w(N);
  vi v(N);
  rep(i, N) cin >> w[i] >> v[i];

  vl dp(100001, INF);
  dp[0] = 0;

  rep(i, N) {
    irep(j, 100001) {
      if (j + v[i] <= 100000)
        chmin(dp[j + v[i]], dp[j] + w[i]);
    }
  }

  ll ans = 0;
  irep(i, 100001) {
    if (dp[i] <= W) {
      ans = i;
      break;
    }
  }

  out(ans);
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX = (int)1e3;
bool prime[MAX + 1];
int main() {
	fill(prime, prime + MAX + 1, 1);
	prime[1] = prime[0] = 0;
	for (int i = 2; i <= MAX; i++) {
		if (prime[i]) {
			for (int j = 2; i*j <= MAX; j++) {
				prime[i*j] = 0;
			}
		}
	}
	int cnt[MAX + 1];
	fill(cnt, cnt + MAX + 1, 0);
	int e = 0;
	int n;
	cin >> n;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		for (int j = 2; j <= a; j++) {
			if (prime[j]) {
				e = 0;
				while (a%j == 0) {
					e++;
					a /= j;
				}
				if (cnt[j] < e) {
					cnt[j] = e;
				}
			}
		}
	}
	int ans = 1;
	for (int i = 0; i <= MAX; i++) {
		if (prime[i]) {
			for (int j = 1; j <= cnt[i]; j++) {
				ans *= i;
			}
		}
	}
	cout << ans << endl;
}

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

const int MAX = 510000;
const int MOD = 998244353;

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;
}

int main() {
    // 前処理
    COMinit();

    int n,m,k;cin>>n>>m>>k;
    vector<long long>a(n);
    a[0]=1;
    for(int i=1;i<n;++i){
        a[i]=a[i-1]*(m-1)%MOD;
    }
    long long ans=0;
    for(int i=0;i<=k;++i){
        ans+=COM(n-1,i)*m%MOD*a[n-i-1]%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> pixel(H,vector<char>(W,0));
  vector<char> bar(W+2,'#');
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> pixel.at(i).at(j);
    }
  }
  
  for(int i=0;i<bar.size();i++){
    cout << bar.at(i);
  }
  cout << endl;
  
  for(int i=0;i<H;i++){
    cout << '#';
    for(int j=0;j<W;j++){
      cout << pixel.at(i).at(j);
    }
    cout << '#' << endl;
  } 
    for(int i=0;i<bar.size();i++){
    cout << bar.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
void show(VEC<VEC<int>>M){
  REP(i,0,M.size()){
    DUMP(M[i]);
  }
}

int main() {
  int H,W;
  cin>>H>>W;
  VEC<string>S(H);
  REP(i,0,H)cin>>S[i];
  auto WMAT = MATINIT(int, H, W, 0);
  auto HMAT = MATINIT(int, H, W, 0);
  REP(h,0,H){
    int num = 0;
    REP(w,0,W){
      if(S[h][w]=='#'){
        num=0;
        continue;
      }
      num++;
      WMAT[h][w]=num;
    }
    for(int w=W-2;w>=0;w--){
      if(WMAT[h][w]!=0)WMAT[h][w]=max(WMAT[h][w], WMAT[h][w+1]);
    }
  }
  // show(WMAT);
  // DUMP();

  REP(w,0,W){
    int num = 0;
    REP(h,0,H){
      if(S[h][w]=='#'){
        num=0;
        continue;
      }
      num++;
      HMAT[h][w]=num;
    }
    for(int h=H-2;h>=0;h--){
      if(HMAT[h][w]!=0)HMAT[h][w]=max(HMAT[h][w], HMAT[h+1][w]);
    }
  }
  // show(HMAT);
  int ma = 0;

  REP(h,0,H){
    REP(w,0,W){
      ma=max(ma, HMAT[h][w]+WMAT[h][w]);
    }
  }
  cout<<ma-1<<endl;


  return 0;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long n,m,ans;
  cin >> n >> m;
  ans=(n-2)*(m-2);
  if (n==1 || m==1) ans=n*m-2;
  if (n==1 && m==1) ans=1;
  cout << ans << endl;
  return 0;
}

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

using namespace std;


typedef long long int ll;

vector<ll> adj[1000001]; 

ll i,tc;
#define mod 1000000007
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" "
#define prt2(a,b) cout<<a<<" "<<b<<" "
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" "
#define rep(i,st,end) for( i=st;i<end;i++)
#define repv(i,st,end) for( i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define TEST cin>>tc;while(tc--)




int main()
{
  ll n,x,y;
  cin>>n>>x>>y;
  x--;
  y--;

  vector<ll>adj[2001];

  for(int i=0;i<n-1;i++)
{
  adj[i].pb(i+1);
  adj[i+1].pb(i);
}
adj[x].pb(y);
adj[y].pb(x);
  
  ll dist[2001][2001];
  memset(dist,0,sizeof(dist));
    
    // for(int i=0;i<n;i++)
    // {
    //     for(auto j:adj[i])
    //     cout<<j<<" ";
    //     endl;
    // }
  for(int i=0;i<n;i++)
  {
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    dist[i][i]=0;
    q.push(i);
    visited[i]=true;
    while(!q.empty())
    {
      ll top=q.front();
      q.pop();
      for(auto it:adj[top])
      {
        if(!visited[it])
        {
          dist[i][it]=dist[i][top]+1;
          visited[it]=true;
          q.push(it);
        }
      }
      dist[i][i]=0;
    }

  }
//   for(int i=0;i<n;i++)
//   {
//       for(int j=0;j<n;j++)
//       cout<<dist[i][j]<<" ";
//       endl;
//   }
  map<ll,ll>mp;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
      mp[dist[i][j]]++;
  }
  for(int i=1;i<=n-1;i++)
  cout<<mp[i]<<"\n";

}

Measured memory_bytes: 55296
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b,c,d,e,f = i_map()
    W = set()
    for i in range(0,f+1,a*100):
        for j in range(0,f+1, b*100):
            W.add(i+j)

    S = set()
    for i in range(0,f+1, c):
        for j in range(0, f+1, d):
            S.add(i+j)

    rate = -1

    for w in W:
        for s in S:
            if 0 < w+s <= f and s <= w*e//100:
                if s/(w+s) > rate:
                    rate = s/(w+s)
                    ans = (w+s,s)
    print(ans[0], ans[1])





if __name__=="__main__":
    main()


Measured memory_bytes: 74164
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <utility>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int K, len;
    std::string S, res="";

    std::cin >> K;
    std::cin >> S;

    len = S.length();

    if(len <= K)
    {
        print(S);
    }

    else
    {
        print(S.substr(0, K) + "...");
    }

    return 0;
}

Measured memory_bytes: 3628
#A
"""
a, b, c = map(int, input().split())
print(min(b//a, c))
"""
#B
"""
a, b, k = map(int, input().split())
for i in range(max(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
             print(i)
"""

#C
s = list(input())
an0 = 0
an1 = 0
for i in s:
    if i == "1":
        an1 += 1
    if i == "0":
        an0 += 1
print(min(an0, an1)*2)

Measured memory_bytes: 3956