akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    vector<int> a(N+2, 0), b(N+2, 0);
    
    for (int i = 1; i < N; i++) {
        a[p[i]] += i;
        b[p[i]] += i;
    }
    for (int i = 1; i <= N; i++) {
        a[i] += a[i-1];
    }
    for (int i = N; i >= 1; i--) {
        b[i] += b[i+1];
    }
    for (int i = 1; i <= N; i++) {
        if (i < N) printf("%d ", a[i]+i);
        else printf("%d\n", a[i]+i);
    }
    for (int i = 1; i <= N; i++) {
        if (i < N) printf("%d ", b[i]+N+1-i);
        else printf("%d\n", b[i]+N+1-i);
    }
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//rep(i, v.size()) v[i]=i;
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a < b + c)cout << b + c - a << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet           as S
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  n <- readLn
  ds <- map readInt . BS.lines <$> BS.getContents
  print $ solve n ds

solve :: Int -> [Int] -> Int
solve _ = S.size . S.fromList

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


Measured memory_bytes: 508
# -*- coding: utf-8 -*-
"""
A - Multiple Array
https://atcoder.jp/contests/agc009/tasks/agc009_a

"""
import sys


def solve(N, A, B):
    ans = 0
    for a, b in zip(A[::-1], B[::-1]):
        r = (a+ans) % b
        if r:
            ans += (b-r)
    return ans


def main(args):
    N = int(input())
    A, B = [], []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    ans = solve(N, A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 12628
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;
const ll INF = 1e18;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c && a == c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

bool great(const pair<string, int>& left, const pair<string, int>& right){
	return left.second > right.second;
}

int main(){
	string max = "";
	string s;
	map<string, int> m;
	vector<pair<string, int> >v;
	while (cin >> s){
		if (max.size() < s.size()) max = s;
		if (m.find(s) == m.end()) m[s] = 1;
		else m[s]++;
	}
	map<string, int>::iterator it = m.begin();
	while (it != m.end()){
		v.push_back(make_pair((*it).first, (*it).second));
		it++;
	}
	sort(v.begin(),v.end(),great);
	cout << v[0].first << " " << max << endl;
}

Measured memory_bytes: 1208
#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>;
using Graph = vector<vector<int>>;

int main(){
    int N; cin >> N;
    int x[N];
    rep(i, N) cin >> x[i];

    int ans=999999999;
    int sum;
    rep(p, 101){
        sum = 0;
        rep(i, N){
            // cout << "p: " << p << " x[i]:" << x[i] << endl;
            sum += pow(x[i]-p, 2);
        }
        // cout << "p: " << p << " ans:" << ans << endl;
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def solve():
    S = input()
    lenS = len(S)
    sumS = 0
    N = [0] * (lenS + 1)
    zero = set()
    if S[0] == "<": zero |= {0}
    for i in range(lenS - 1):
        if S[i] == ">" and S[i+1] == "<": zero |= {i+1}
    if S[lenS-1] == ">": zero |= {lenS}

    for start in zero:
        pointer = start
        while pointer <= lenS - 1:
            if S[pointer] == "<":N[pointer + 1] = max(N[pointer] + 1, N[pointer + 1])
            else: break
            pointer += 1
        
        pointer = start - 1
        while pointer >= 0:
            if S[pointer] == ">": N[pointer] = max(N[pointer + 1] + 1, N[pointer])
            else: break
            pointer -= 1

    #print(N)
    print(sum(N))

    return 0

if __name__ == "__main__": solve()

Measured memory_bytes: 23348
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

void print_pat(P a, P b){
  printf("%lld %lld %lld %lld",
         a.first, b.first, b.second, a.first);
  printf(" ");
  printf("%lld %lld %lld %lld",
         a.second, b.second, b.first, a.second);
}

int main(void){
  ll m,k;
  cin >> m >> k;
  if(k >= (1 << m)){
    puts("-1");
    return 0;
  }
  if(k == 0){
    for(int i = 0;i < (1 << m);++i){
      if(i != 0){
        printf(" ");
      }
      printf("%d %d", i, i);
    }
    printf("\n");
    return 0;
  }
  if(m == 1){
    puts("-1");
    return 0;
  }
  set<ll> used;
  vector< P > res;
  for(int i = 0;i < (1 << m);++i){
    if(used.find(i) == used.end()){
      ll p = 0LL;
      for(int j = 0;j < m;++j){
        if((k >> j) & 1){
          p |= !((i >> j) & 1) <<j;
        }else{
          p |= ((i >> j) & 1) << j;
        }
      }
      res.push_back(P(i,p));
      used.insert(i);
      used.insert(p);
      //cout << i << " " << p << endl;
    }
  }
  for(int i = 0;i < (1 << (m-2));++i){
    if(i != 0){
      printf(" ");
    }
    print_pat(res[i*2],res[i*2+1]);
  }
  printf("\n");
  return 0;
}


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

int main() {
	

	int N;
	cin >> N;
	
	long long ans;
	ans = 0;
	for (int i = 1; i < N + 1; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			ans += i;
		}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3628
import sys
A, B = [int(x) for x in input().split()]
S = list(input())
for i in range(A+B+1):
  if(i==A):
    if(S[i]!='-'):
      print('No')
      sys.exit()
  else:
    if(str.isdecimal(S[i])==False):
      print('No')
      sys.exit()
print('Yes')

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LD xs,ys,xt,yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  vector<LD> x(n+2),y(n+2),r(n+2);
  x[0]=xs,y[0]=ys,r[0]=0;
  x[n+1]=xt,y[n+1]=yt,r[n+1]=0;
  for(int i=1;i<=n;i++){
    cin >> x[i] >> y[i] >> r[i];
  }
  vector<vector<LD>> e(n+2,vector<LD>(n+2));
  for(int i=0;i<=n+1;i++){
    for(int j=0;j<=n+1;j++){
      e[i][j]=max((LD)0,sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]);
    }
  }
  vector<LD> dist(n+2,LINF);
  priority_queue<pair<LD,int>,vector<pair<LD,int>>,function<bool(pair<LD,int>,pair<LD,int>)>>
    dijk([](const pair<LD,int> &a, const pair<LD,int> &b){return a>b;});
  dijk.push({0,0});
  pair<LD,int> now;
  while(!dijk.empty()){
    now=dijk.top();
    dijk.pop();
    if(dist[now.second]==LINF){
      dist[now.second]=now.first;
      if(now.second==n+1) break;
      for(int i=1;i<=n+1;i++){
        if(dist[i]==LINF){
          dijk.push({now.first+e[now.second][i],i});
        }
      }
    }
  }
  cout << fixed << setprecision(10) << dist[n+1] << endl;
  return 0;
}

Measured memory_bytes: 34536
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int Next[220000],h[220000],v[220000],tot,sg[220000];
int n;
int add(int x,int y){
	tot++;
	Next[tot]=h[x];
	v[tot]=y;
	h[x]=tot;
}
int dfs(int x,int fa){
	for(int i=h[x];i;i=Next[i]){
		if(v[i]==fa)continue;
		dfs(v[i],x);
		sg[x]^=sg[v[i]];
	}
	if(x!=1)sg[x]++;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
	if(sg[1])printf("Alice\n");
	else printf("Bob\n");
}

Measured memory_bytes: 7296
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
c = tuple(map(int, input().split()))

ans = 0
pre_order = -10
for aa in a:
    ind = aa - 1
    ans += b[ind]
    if ind - pre_order == 1:
        ans += c[pre_order]
    pre_order = ind
print(ans)


Measured memory_bytes: 3060
#include<iostream>

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

	long long n, max = -1, m = 0;
	std::cin >> n;
	for(int i = 0; i < n; i++){
		long long a, b;
		std::cin >> a >> b;
		if(a > max) {
			max = a;
			m = b;
		}
	}
	std::cout << max + m << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    ll N;
    cin >> N ;
    vector<ll> a(N,0);// 
    cin >> a;

    ll ans= -1;
    ll count = 1;
    ll brk=0;
    bool Comp=false;

    for (ll i = 0; i < N; i++){
        if (a[i] == count){
            Comp = true;
            count++;
        }else{
            brk++;
        }
    }

    if (Comp){
        ans = brk;
    }

    cout << ans << endl;

    
    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define _ << ' ' <<
#define in :
#define var auto&&
#define let const auto

signed main ( ) {

    int n, k;
    read n >> k;
    vector<int> h(n);
    for ( var i in h ) read i;

    sort(h.rbegin(), h.rend());
    int ans = 0;
    for ( int i = k; i < n; i++ ) {
        ans += h[i];
    }
    echo ans fin;


    return 0;
}

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

double pi = 3.141592653589793;


int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double x,y;
    x = 30*h + 0.5*m;
    y = m*6;
    double r = abs(x-y);
    double k = min(r,360-r);
    k /= 180;
    double c = cos(pi*k);
    double xx = a*a + b*b - 2*a*b*c;
    double ans = pow(xx,0.5);
    cout << fixed << setprecision(10) << ans << endl; 
}

Measured memory_bytes: 4356
main = do
  [a, b] <- (map read . words) <$> getLine
  putStrLn $ solve a b

solve:: Int -> Int -> String
solve a b
  | mod a 3 == 0 = "Possible"
  | mod b 3 == 0 = "Possible"
  | mod (a + b) 3 == 0 = "Possible"
  | otherwise = "Impossible"

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int N;

int main(void) {

	cin >> N;

	int M = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 2 == 1) { M++; }
	}

	cout << setprecision(15) << fixed << 1.0*M / (1.0*N) << endl;

	return 0;
}

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

typedef long long ll;
const int maxn = 2e3 + 3;

int n, x, y;
ll d[maxn], cnt[maxn];
bool vis[maxn];
std::queue<int> q;
std::vector<int> E[maxn];

void bfs(int s) {
    memset(vis, 0, sizeof(vis[0]) * (n + 1));
    memset(d, 0x7f, sizeof(d[0]) * (n + 1));
    vis[s] = true;
    d[s] = 0;
    q.push(s);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(auto &&v : E[u]) {
            if(!vis[v]) {
                vis[v] = true;
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
    for(int i = s + 1; i <= n; ++i)
        cnt[d[i]] += 1;
}

int main() {
    scanf("%d%d%d", &n, &x, &y);
    for(int i = 1; i < n; ++i)
        E[i].push_back(i + 1), E[i + 1].push_back(i);
    E[x].push_back(y);
    E[y].push_back(x);
    for(int i = 1; i <= n; ++i) {
        bfs(i);
    }
    for(int i = 1; i < n; ++i) {
        printf("%lld\n", cnt[i]);
    }
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 998244353LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

struct Coins { ll a; ll b; ll c; };

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x, y, z;
	cin >> x >> y >> z;
	ll n = x + y + z;
	vector<Coins> co(n);
	REP(i, n) cin >> co[i].a >> co[i].b >> co[i].c;
	sort(ALL(co), [](Coins l, Coins r){return (l.a - l.b) < (r.a - r.b);});
	vector<ll> tmp(n, 0);
	priority_queue<ll, vector<ll>, greater<ll>> pq;
	ll sum1 = 0, sum2 = 0;
	for(ll i = n - 1; i >= 0; i--) {
		sum1 += co[i].c;
		sum2 += co[i].a - co[i].c;
		pq.push(co[i].a - co[i].c);
		while((ll)pq.size() > x) {
			sum2 -= pq.top();
			pq.pop();
		}
		if((ll)pq.size() != x || i < y) continue;
		tmp[i] += sum1 + sum2;
	}
	while(!pq.empty()) pq.pop();
	sum1 = 0; sum2 = 0;
	REP(i, n - 1) {
		sum1 += co[i].c;
		sum2 += co[i].b - co[i].c;
		pq.push(co[i].b - co[i].c);
		while((ll)pq.size() > y) {
			sum2 -= pq.top();
			pq.pop();
		}
		if((ll)pq.size() != y || n - 1 - i < x) continue;
		tmp[i + 1] += sum1 + sum2;
	}
	ll ans = 0;
	REP(i, n - 1) ans = max(ans, tmp[i + 1]);
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    bool up_flg = false;
    bool dn_flg = false;
    int ans = 0;
    rep(i, n-1) {
        if ( a[i] < a[i+1] ) {
            if ( dn_flg ) {
                ++ans;
                dn_flg = false;
                continue;
            }
            up_flg = true;
        }
        else if ( a[i] > a[i+1] ) {
            if ( up_flg ) {
                ++ans;
                up_flg = false;
                continue;
            }
            dn_flg = true;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
#include<cstring>
#define MAX_N 100000
#define F first
#define S second
using namespace std;
typedef pair<long long int, long long int> P;
typedef pair<long long int, P> PP;
long long int INF = 1844674407370955461;

long long int n, m, c, sum = 0, sum2 = 0, ans = INF;
P flag[MAX_N + 1] = {};
vector<P> g[MAX_N + 1];
vector<int> vec;
priority_queue<PP>pq;
int main() {
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++) {
		int a, b, e;
		scanf("%d%d%d", &a, &b, &e);
		g[a].push_back(P(b, e));
		g[b].push_back(P(a, e));
		sum += e;
	}

	for (int i = 0; i < g[1].size(); i++) {
		pq.push(make_pair(-g[1][i].S, make_pair(1, g[1][i].F)));
	}

	while (!pq.empty()) {
		PP a = pq.top();
		pq.pop();
		if (!flag[a.S.S].F) {
			if (a.S.S == 1) {
				flag[a.S.S].S = 1;
				continue;
			}
			flag[a.S.S].F = -a.F;
			flag[a.S.S].S = a.S.S;
			for (int i = 0; i < g[a.S.S].size(); i++) {
				pq.push(make_pair(-flag[a.S.S].F - g[a.S.S][i].S, make_pair(a.S.S, g[a.S.S][i].F)));
			}
		}
	}
	sort(flag + 1, flag + n + 1);
	for (int i = 1; i < n + 1; i++) {
		for (int j = 0; j < g[flag[i].S].size(); j++) {
			if (binary_search(vec.begin(), vec.end(), g[flag[i].S][j].F)) {
				sum2 += g[flag[i].S][j].S;
			}
		}
		vec.insert(upper_bound(vec.begin(), vec.end(), flag[i].S), flag[i].S);
		if (flag[i].F == flag[i + 1].F) {
			continue;
		}
		ans = min(ans, sum + c*flag[i].F - sum2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 23040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (A >= K) cout << K << endl;
    else if (A+B >= K) cout << A << endl;
    else cout << A - (K - A - B) << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

vector <ll> dp(1e5, 1e18);

int main(void){
    ll h; cin >> h;
    ll n; cin >> n;
    vector <ll> as;
    vector <ll> bs;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
        ll b; cin >> b;
        bs.push_back(b);
    }
    dp[0] = 0;
    REP(j, h){
        REP(i, n){
            ll a = as[i];
            ll b = bs[i];
            dp[j+a] = min(dp[j]+b, dp[j+a]);
        }
    }
    ll ans = 1e15;
    REP(i, 1e4+10){
        ans = min(dp[i+h], ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




int main() {
    ll n, ma, mb;
    vector<vector<vector<ll>>> dp(50, vector<vector<ll>>(515, vector<ll>(515, INF)));
    
    cin >> n >> ma >> mb;
    
    vector<ll> a(n), b(n), c(n);
    REP(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }
    
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++){
        for(ll j = 0; j <= 500; j++){
            for(ll k = 0; k <= 500; k++){
                if(dp[i][j][k] == INF) continue;
                dp[i + 1][j][k] = min(dp[i][j][k], dp[i + 1][j][k]);
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    
    ll ans = INF;
    for(ll i = 1; i <= 500; i++){
        for(ll j = 1; j <= 500; j++){
            if(ma * j == mb * i){
                ans = min(ans, dp[n][i][j]);
            }
        }
    }
    cout << ((ans != INF)? ans : -1) << endl;
}


Measured memory_bytes: 106752
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }

    return true;
}
int n;
int main(void){
    cin >> n;
    int a = ketasum(n);
    (n % a == 0 ? puts("Yes") : puts("No"));
    return 0;
}

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

//x^nをmodで計算する関数
ll sisu(ll x,ll n){
    ll mod=1e9+7;
    ll nv=n;
    vector <ll> bi(40,0);
    vector <ll> cal(40,0);
    ll k=0;
    ll ans=1;
    while(nv!=0){
        bi[k]=nv%2;
        nv/=2;
        ++k;
    }
    rep(i,40){
        if(i==0){
            cal[i]=x%mod;
        }
        else{
            cal[i]=(cal[i-1]*cal[i-1])%mod;
        }
        if(bi[i]==1){
            ans*=cal[i];
            ans=ans%mod;
        }
    }

    return ans;
}

int main(){
    ll n,k;
    cin >> n >> k;
    vector <ll> in(k+1,0);
    ll nn;

    vector <vector <ll>> y(k+1);

    rep(i,k){
        in[i+1]=k/(i+1);
        nn=2;
        while(nn*(i+1)<=k){
            y[nn*(i+1)].push_back(i+1);
            ++nn;
        }
    }

    

    vector <ll> mi(k+1,0);
    ll l;
    ll ans=0;
    ll mod=1e9+7;

    //cout << sisu(in[8],n) << endl;
    //cout << sisu(7,8) << endl;
    //cout << sisu(2,5) << endl;


    ll ko,mi2;

    rep(i,k){
        nn=k-i;
        //cout << nn << endl;
        
        l=y[nn].size();
        ko=sisu(in[nn],n);
        mi2=mi[nn];
        rep(j,l){
            mi[y[nn][j]]+=(ko-mi2);
        }
        //cout << in[nn] << " " << n << endl;
       
        //cout << sisu(1,3) << endl;
        ans+=(ko-mi2)*nn;
        //cout << 777 << endl;
        ans=ans%mod;
    }
    while(ans<0){
        ans+=mod;
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 20656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 2003;



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	bool ans = true;
	if(s[0]!='A')ans = false;
	ll c=0,b=0;
	FOR(i,1,s.size()){
		if(s[i]<='z'&&s[i]>='a')c++;
		else{
			b++;
			if(i==1||i==s.size()-1)ans = false;
			if(s[i]!='C')ans = false;
		}
	}
	if(b!=1)ans = false;
	if(c!=s.size()-2)ans = false;
	if(ans)pri("AC");
	else pri("WA");
}

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

char ans4[4][4],ans5[5][5],ans7[7][7],ans[1010][1010];
int la[1010],n;

int main()
{
	memset(la,-1,sizeof(la));
	la[0]=0;
	for (int i=0; i<=1000; i++) if (la[i]!=-1)
	{
		if (i+4<=1000) la[i+4]=i;
		if (i+5<=1000) la[i+5]=i;
		if (i+7<=1000) la[i+7]=i;
	} 
	ans4[0][0]=ans4[1][0]=ans4[0][2]=ans4[0][3]=ans4[3][0]=ans4[3][1]=ans4[2][3]=ans4[3][3]='a';
	for (int i=0; i<4; i++)
		for (int j=0; j<4; j++)
			if (ans4[i][j]!='a') ans4[i][j]='b';
	ans4[0][1]=ans4[1][1]=ans4[2][2]=ans4[3][2]='c';
	ans5[0][0]=ans5[0][1]='a';
	ans5[0][2]=ans5[0][3]='b';
	ans5[0][4]=ans5[1][4]='c';
	ans5[2][4]=ans5[3][4]='d';
	ans5[4][4]=ans5[4][3]='e';
	ans5[4][2]=ans5[4][1]='f';
	ans5[4][0]=ans5[3][0]='g';
	ans5[2][0]=ans5[1][0]='h';
	ans5[1][1]=ans5[1][2]='i';
	ans5[2][3]=ans5[3][3]='j';
	for (int i=0; i<5; i++)
		for (int j=0; j<5; j++) if (ans5[i][j]<'a'||ans5[i][j]>'z') ans5[i][j]='.';
	ans7[0][0]=ans7[0][1]='a';
	ans7[0][3]=ans7[0][4]='a';
	ans7[0][6]=ans7[1][6]='a';
	ans7[3][6]=ans7[4][6]='a';
	ans7[6][6]=ans7[6][5]='a';
	ans7[6][2]=ans7[6][3]='a';
	ans7[6][0]=ans7[5][0]='a';
	ans7[3][0]=ans7[2][0]='a';
	ans7[1][1]=ans7[2][1]='b';
	ans7[1][2]=ans7[2][2]='c';
	ans7[3][1]=ans7[3][2]='d';
	ans7[4][3]=ans7[5][3]='e';
	ans7[4][4]=ans7[4][5]='f';
	ans7[5][4]=ans7[5][5]='g';
	for (int i=0; i<7; i++)
		for (int j=0; j<7; j++) if (ans7[i][j]<'a'||ans7[i][j]>'z') ans7[i][j]='.';
	scanf("%d",&n);
	if (n==2) return puts("-1"),0;
	if (n%3==0)
	{
		for (int i=0; i<n; i+=3)
		{
			ans[i][i]=ans[i][i+1]='a';
			ans[i+1][i+2]=ans[i+2][i+2]='b';
		}
	} else
	{
		int nn=n;
		while (n)
		{
			int nw=n-la[n];
			if (nw==4)
			{
				for (int i=0; i<4; i++)
					for (int j=0; j<4; j++)
						ans[n-1-i][n-1-j]=ans4[i][j];
			} else
			if (nw==5)
			{
				for (int i=0; i<5; i++)
					for (int j=0; j<5; j++)
						ans[n-1-i][n-1-j]=ans5[i][j];
			} else
			{
				for (int i=0; i<7; i++)
					for (int j=0; j<7; j++)
						ans[n-1-i][n-1-j]=ans7[i][j];
			}
			n=la[n];
		}
		n=nn;
	}
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			if (ans[i][j]<'a'||ans[i][j]>'z') ans[i][j]='.';
	for (int i=0; i<n; i++,puts(""))
		for (int j=0; j<n; j++) putchar(ans[i][j]);
	return 0;
}

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

using namespace std;

int n, d1, d2;
vector<pair<int, int> > v[2], a[2];

int main(){
	scanf("%d%d%d", &n, &d1, &d2);
	int x = 0, y;
	while (d1%(1<<(2*(x+1)))==0) x++;
	x=(1<<x);
	y = d1 / (x * x) % 4;
	//x = max(x / 2, 1);
	for(int i = 0;i < n * 2;i++){
		for(int j = 0;j < n * 2;j++){
			int ii = i / x, jj = j / x;
			if(y == 1){
				v[(ii + jj) & 1].push_back({i, j});
			}else if(y == 2){
				v[ii & 1].push_back({i, j});
			}else{
				v[0].push_back({i, j});
			}
		}
	}
	if(v[0].size() < v[1].size()) swap(v[0], v[1]);
	x = 0;
	while (d2%(1<<(2*(x+1)))==0) x++;
	x=(1<<x);
	y = d2 / (x * x) % 4;
	//x = max(x / 2, 1);
	for(int k = 0;k < v[0].size();k++){
		int i = v[0][k].first, j = v[0][k].second;
		int ii = i / x, jj = j / x;
		if(y == 1){
			a[(ii + jj) & 1].push_back({i, j});
		}else if(y == 2){
			a[ii & 1].push_back({i, j});
		}else{
			a[0].push_back({i, j});
		}
	}
	if(a[0].size() < a[1].size()) swap(a[0], a[1]);
	for(int i = 1;i <= n * n;i++) printf("%d %d\n", a[0].back().first, a[0].back().second), a[0].pop_back();
}

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

typedef long long ll;

int n, x;


int main(){
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }

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

    int cnt = 0;
    for (int i = 0; i < n-1; i++){
        if (a[i] <= x){
            x -= a[i];
            cnt++;
        } else {
            break;
        }
    }
    if (x == a[n-1]){
        cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    unordered_map<int, int> m;
    for (int i = 2; i <= N; ++i) {
        int tmp = i;
        for (int j = 2; j * j <= i; ++j) {
            while (!(tmp % j)) {
                tmp /= j;
                m[j]++;
            }
        }
        if (tmp > 1)
            m[tmp]++;
    }

    ll ans = 1;
    for (auto i : m)
        (ans *= (i.second + 1)) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
n = gets.chomp.to_i
s = []
n.times do
    s << gets.chomp.to_i
end
sum = [s.inject(:+)]
n.times do |i|
    sum << sum[0] - s[i]
end
ans = sum.select{|v| v % 10 != 0}
puts ans.empty? ? 0 : ans.max

Measured memory_bytes: 1788
from fractions import gcd
def func(a):
  return abs(int(a)-x)
n,x = map(int,input().split())
xlist = list(map(func,input().split()))
for i in range(1,n):
  xlist[i] = gcd(xlist[i],xlist[i-1])
print(xlist[n-1])

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

vector<int> G[100001];
int n,m;
int h[100001];

bool bfs(int i){
    for(auto j:G[i]){
        if(h[j]>=h[i]) return false;
    }
    return true;
}

int main(){
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> h[i];
    for(int i=0;i<m;i++){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    int ans=0;
    for(int i=1;i<=n;i++){
        if(bfs(i)) ans++;
    }
    
    cout << ans << endl;
}



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

int main() {
  int n;
  cin>>n;
  int v[n];
  int c[n];
  int x=0;
  rep(i,n){
    cin>>v[i];
  }
  rep(i,n){
    cin>>c[i];
  }
  rep(i,n){
    if(v[i]>c[i]){
      x+=v[i]-c[i];
    }
  }
  cout<<x<<endl;
}



Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int H, N;
  cin >> H >> N;
  for (int n = 0; n < N; n++)
  {
    int A;
    cin >> A;
    H -= A;
  }
  cout << (H <= 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define pii pair <int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 100010

using namespace std;

char c[5][5];

int main()
{
	for(int i = 1; i <= 3; i++)
		for(int h = 1; h <= 3; h++)
			cin >> c[i][h];
	
	for(int i = 1; i <= 3; i++)
		cout << c[i][i];
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
r = sorted(list(map(int, input().split())), reverse=True)[:x]
g = sorted(list(map(int, input().split())), reverse=True)[:y]
n = sorted(list(map(int, input().split())), reverse=True)
list = sorted(r+g+n, reverse=True)
ans = 0
for _ in range(x+y):
  ans += list[_]
  
print(ans)

Measured memory_bytes: 22488
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

const ll INF = 1002003004005006007;

int main(){

    int n, m;
    cin >> n >> m;

    vector<vector<ll>> g(n, vector<ll> (n,INF));

    rep(i,m){
        int x, y, t; cin >> x >> y >> t;
        x--; y--;

        g[x][y] = t;
        g[y][x] = t;
    }

    //{距離, 今いる頂点, 速さ, 状態}
    using Q = tuple<ll, ll, ll, ll>;
    priority_queue<Q ,vector<Q>,greater<Q>> que;

    ll dp[505][55][2];
    rep(i,505)rep(j,55)rep(k,2) dp[i][j][k] = INF;

    ll v0; cin >> v0;
    int a, b, c; cin >> a >> b >> c;
    
    //初期push
    que.push(Q(0LL, 0LL, v0, 0LL));

    dp[0][v0][0] = 0;
    //Dijkstra
    while(!que.empty()){

        //まずはヒープの先頭の要素をとる
        auto e = que.top(); que.pop();

        //それぞれのパラメータを取得

        //auto [dist, v, velo, state] = e; // c++17
        ll dist, v, velo, state;
        tie(dist, v, velo, state) = e;

        //状態の遷移
        if (v == n - 1 and state == 0) {
            if (dp[v][velo][1] > dist) {
                dp[v][velo][1] = dist;
                que.push(Q(dist, v, velo, 1));
            }
        }

        // cout << "dist = " << dist << " , node = " << v + 1 << " , velo = " << velo << " state = " << state << endl;

        //次に行く頂点の距離が最小じゃなかったら論の外
        if(dist > dp[v][velo][state]) continue;


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

            if(g[v][j] == INF) continue;

            //costをちゃんと計算しておく
            ll nvelo = (a * velo + b) % c;
            ll cost = g[v][j] * velo;

            //遷移
            if(dist + cost < dp[j][nvelo][state]){
                dp[j][nvelo][state] = dist + cost;
                que.push(Q(dist + cost, j, nvelo , state));
            }

        }
    }

    ll ans = INF;

    rep(i,51){
      ans = min(ans,dp[0][i][1]);
    }

    cout << ans << endl;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int cnt = 0;
  for(int i=0; i<n; i++) {
    if(!(a[i] < (double)sum/(4*m))) cnt++;
  }
  if(cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string S;
int main() {
    cin >> S;
    int N = S.length();
    int red = 0;
    int blue = 0;
    for(int i = 0; i < N; ++i) {
        if(S.at(i) == '0') red++;
        else blue++;
    }

    if(red < blue) {
        cout << red * 2 << endl;
    }else {
        cout << blue * 2 << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<typename T>
struct CumulativeSum2D{
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<T>(H + 1, 0)) {}

    void add(int x, int y, T z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build(){
        for(int i = 1; i < (int)data.size(); ++i){
            for(int j = 1; j < (int)data[i].size(); ++j){
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

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

    int N;
    cin >> N;
    vector<int> pow10(10);
    pow10[0] = 1;
    for(int i = 0; i + 1 < 10; ++i) pow10[i + 1] = pow10[i] * 10;
    vector<ll> A(N);
    vector<P> table;
    CumulativeSum2D<int> S(50, 50);
    for(int i = 0; i < N; ++i){
        string s;
        cin >> s;
        const int n = s.length();
        int idx = n;
        for(int j = 0; j < n; ++j){
            if(s[j] == '.'){
                idx = j;
                break;
            }
        }
        if(idx == n)    A[i] = stoll(s) * pow10[9];
        else{
            A[i] = stoll(s.substr(0, idx)) * pow10[9];
            A[i] += stoll(s.substr(idx + 1, n - idx - 1)) * pow10[9 - (n - idx - 1)];
        }
        int c2 = 0, c5 = 0;
        while(A[i] % 2 == 0){
            ++c2;
            A[i] /= 2;
        }
        while(A[i] % 5 == 0){
            ++c5;
            A[i] /= 5;
        }
        table.emplace_back(c2, c5);
        S.add(c2, c5, 1);
    }
    S.build();
    ll ans = 0;
    int tx = 50, ty = 50;
    for(auto& p : table){
        int sx = max(0, 18 - p.first), sy = max(0, 18 - p.second);
        ans += S.query(sx, sy, tx, ty);
        if(p.first >= sx && p.second >= sy) --ans;
    }
    cout << ans / 2 << endl;
}

Measured memory_bytes: 6916
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define min(a, b) a < b ? a : b
#define max(a, b) a > b ? a : b

int main(void)
{
	int x;
	char *w;

	scanf("%d", &x);

	if (x < 1200) w = "ABC";
	else w = "ARC";

	printf("%s\n", w);

	return (0);
}

Measured memory_bytes: 128
/**
 *    author:  FromDihPout
 *    created: 2020-08-09
**/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()

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(all(a));
    
    int ans = 0;
    for (int i = 1; i < n; i++) {
        for (int j = i - 1; j >= 0; j--) {
            int sum = a[i] + a[j];
            int k = i + 1;
            while (k < n && a[k] < sum) {
                k++;
            }
            ans += k - i - 1;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

int main(){
	int a, b;
	char s[2];
	scanf("%d %s %d", &a, s, &b);
	if (s[0] == '+')
		printf("%d\n", a + b);
	else 
		printf("%d\n", a - b);
	return 0;
}


Measured memory_bytes: 256
a, b, c, x, y = list(map(int, input().split()))

ans1 = a*x + b*y

ans2 = 2*c*min(x, y)
ans2 += a*(x-y) if x > y else b*(y-x)

ans3 = 2*c*max(x, y)
print(min(ans1, ans2, ans3))


Measured memory_bytes: 2940
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean[] to = new boolean[N];
		boolean[] from = new boolean[N];
		for(int i=0; i<M; i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			if(a==0)
				to[b] = true;
			if(b==0)
				to[a] = true;
			if(a==N-1)
				from[b] = true;
			if(b==N-1)
				from[a] = true;
		}
		boolean ok = false;
		for(int i=1; i<N-1; i++)
			ok |= to[i]&&from[i];
		
		System.out.println(ok ? "POSSIBLE" : "IMPOSSIBLE");
				
		sc.close();
	}
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,m,t,a[200010],b[200010],sum=0,ans=0;
vector <LL> v;

int main()
{
	cin>>n>>m>>t;
	rep(i,n) scanf("%lld",&a[i]);
	rep(i,m)
	{
		scanf("%lld",&b[i]);
		sum+=b[i];
		v.pb(sum);
	}
	sum=0;
	rep(i,n+1)
	{
		if(sum>t) break;
		LL pos=upper_bound(v.begin(),v.end(),t-sum)-v.begin();
		ans=max(ans,i+pos);
		if(i==n) break;
		sum+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8308
N=int(input())
D12 = [map(int, input().split()) for _ in range(N)]
D1,D2 = [list(i) for i in zip(*D12)]

flag=0

for i in range(N-2):
    if D1[i]==D2[i] and D1[i+1]==D2[i+1] and D1[i+2]==D2[i+2]:
        flag=1

if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9084
object Main extends App {
     
    val Array(ttlRow, ttlCol) =  io.StdIn.readLine.split(" ").map(_.toInt)
    val Array(row, col) =  io.StdIn.readLine.split(" ").map(_.toInt)
    println(balanceCell(ttlRow, ttlCol, row, col))
    def balanceCell(ttlRow:Int, ttlCol:Int, row:Int, col:Int):Int = {
        val rowBal = ttlRow - row 
        val colBal = ttlCol - col 
        rowBal * colBal 
    }
}

Measured memory_bytes: 25492
x = gets.chomp.to_i

val = if 1800 <= x
        1
      elsif 1600 <= x
        2
      elsif 1400 <= x
        3
      elsif 1200 <= x
        4
      elsif 1000 <= x
        5
      elsif 800 <= x
        6
      elsif 600 <= x
        7
      elsif 400 <= x
        8
      end
puts val

Measured memory_bytes: 14372
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();

    int c = 0;

    for (int i = 0; i <= n-3; i++) {
      String k = s.substring(i,i+3);
      if (k.equals("ABC")) {
        c++;
      }
    }

    System.out.println(c);

  }

}


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


const ll MAX = 1e6*2+5;
const ll MOD = 1000000007;
ll 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;
    }
}

ll COM(ll n, ll 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(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	COMinit();
	ll r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	ll a,b,c,d;
	a = COM(r2+1+c2+1,c2+1);
	b = COM(r1+c2+1,c2+1);
	c = COM(r2+1+c1,c1);
	d = COM(r1+c1,c1);
	ll ans = (a - b - c + d)%MOD;
	if(ans<0) ans += MOD;
	// cout<<a<<b<<c<<d<<"\n";

	cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define pb push_back
#define vi vector<ll>
#define all(_x) _x.begin(), _x.end()
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define lb(_x, _a) (lower_bound(all(_x), _a) - _x.begin())
#define ub(_x, _a) (upper_bound(all(_x), _a) - _x.begin())
ll n,m, tc;
const int mod = (int) 1e9 + 7;
int main()
{
  	// ll is int now
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    long long dp[n][m];
    rep(i,0,n) rep(j,0,m) dp[i][j] = 0;
    char c;
    rep(i,0,n) rep(j,0,m){
        cin>>c;
        if(c=='#') dp[i][j] = -1;
    }
    for(int i=0; i<m; i++) {
        if(dp[0][i]!=-1) dp[0][i] = 1;
        else break;
    }
    for(int i=0; i<n; i++) {
        if(dp[i][0]!=-1) dp[i][0] = 1;
        else break;
    }
    for(int i=1; i<n; i++)
    {
        for(int j=1; j<m; j++)
        {
            if(dp[i][j]==-1) continue;
            dp[i][j] = (dp[i-1][j]==-1 ? 0 : dp[i-1][j]) + (dp[i][j-1]==-1 ? 0 : dp[i][j-1]);
            dp[i][j] %= mod;
        }
    }
    cout<<dp[n-1][m-1]<<"\n";

    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	  cin>>n;
	   string arr;
	    char prev,pre;
	   cin>>prev;
	    arr+=prev;
       for(int i=1;i<n;i++){
       	cin>>pre;
       	 if(pre!=prev){
       	 	prev=pre;
       	 	arr+=pre;
			}
	   }
	   cout<<arr.length();
       return 0;
}

Measured memory_bytes: 512
package main
import (
  "fmt"
  "os"
)
func main() {
  var n,m int // 1 < n < 4667, m = 4
  fmt.Scan(&n)
  m = 4
  for x:=n/m+1;x<=(3*n)/m;x++ {
    var p,q int
    p = x*n
    q = m*x-n
    for y:=p/q+1;y<=(2*p)/q;y++ {
      var a,b int
      a = y*p
      b = q*y-p
      if a%b == 0 {
        fmt.Println(x,y,a/b)
        os.Exit(0)
      }
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<int> p;
vector<int> q;

int main(void){
  int w,h;
  int t;
  ll ans = 0;
  cin >> w >> h;
  rep(i,w){
    cin >> t;
    p.push_back(t);
  }
  rep(i,h){
    cin >> t;
    q.push_back(t);
  }
  sort(all(p));
  sort(all(q));
  vector<int>::iterator it;
  ll pos;
  w++;h++;
  rep(i,p.size()){
    it = upper_bound(all(q), p[i]);
    pos = it - q.begin();
    it = lower_bound(all(q), p[i]);
    if(*it == p[i]){
      //cout << p[i] << endl;
      pos = it - q.begin();
    }
    ans += (h-pos)*p[i];
    //cout << p[i] << ":" << h-pos << endl;
  }
  rep(i,q.size()){
    it = upper_bound(all(p), q[i]);
    pos = it - p.begin();
    ans += (w-pos)*q[i];
    //cout << q[i] << "::" << w-pos << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1528