akhauriyash/Code-Regression huggingface dataset:
N, A, B, C = map(int, input().split())

mod = 10 ** 9 + 7
table = [1] * (2 * N + 1)
for i in range(2*N):
    table[i+1] = table[i] * (i+1) % mod


def invmod(a, mod=mod):
    # mod が素数の時に成立する
    return pow(a, mod - 2, mod)


def cmb(n, r):
    return (table[n] * invmod(table[r]) * invmod(table[n - r])) % mod


def solve(a, b):
    res = 0
    for i in range(N):
        res += ((i + N) * cmbs[i] * pow(b, i, mod)) % mod
        res %= mod
    return (pow(a, N, mod) * res) % mod


a = A * invmod(A + B, mod)
b = B * invmod(A + B, mod)
c = C * invmod(100, mod)
cmbs = [cmb(i + N - 1, i) for i in range(N)]

Ea = solve(a, b)
Eb = solve(b, a)
ans = ((Ea + Eb) * invmod(1 - c, mod)) % mod
print(ans)

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

int rec[2010];
int N, X, Y;
int dist(int i, int j)
{
    if(i <= X)
    {
        if(j <= X) return j - i;
        else if(Y <= j) return j - i - (Y - X) + 1;
        else return X - i + min(j - X,  1 - (j - X - (Y - X)));
    }
    else if(Y <= i)
    {
        return j - i;
    }
    else
    {
        if(j < Y) return min(j - i, 1 - (j - i - (Y - X)));
        else return j - Y + min(Y - i, 1 -(Y - i - (Y - X)));
    }
}

int main ()
{
    cin >> N >> X >> Y;

    memset(rec, 0, sizeof(rec));

    for(int i = 1; i < N; i++)
    for(int j = i + 1; j <= N; j++)
    {
        rec[dist(i, j)]++;
    }

    for(int i = 1; i < N; i++) cout << rec[i] << endl;
}

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

int main ()
{
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	
//	freopen ("//specify file name","r",stdin);
//	freopen ("output.txt","w",stdout);
	
	int n;
	cin>>n;
	
	int array[n];
	
	for (int i=0;i<n;i++) cin>>array[i];
	
	int dp[n];
	
	dp[0]=0;
	dp[1]= min (abs(array[0]-array[1]) , abs (array[0] - array[2]) );
	
	for (int i=2;i<n;i++)
	{
	  dp[i]= min ( (abs(array[i-2]-array[i]) + dp [i-2]), abs (array[i-1] - array[i])+ dp[i-1]  );
		
	}
	cout<<dp[n-1];
	
	return 0;
	
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
int a,b,c,k;
scanf("%d %d %d",&a,&b,&c);

while(a>b || b>c){
 if(a>b){
 k=a;
 a=b;
 b=k;
 }
 if(b>c){
 k=b;
 b=c;
 c=k;
 }
}

printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;

const int N = 110000;

int main()
{
    ios_base::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min (a, b) << " " << max (0, a + b - n) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()) - 1);
        sc.close();

        // 主処理
        boolean[] used = new boolean[n];
        List<Integer> loopNum = new ArrayList<>();
        int now = 0;

        while (!used[now]) {
            used[now] = true;
            loopNum.add(now);
            now = a[now];
        }

        int size = loopNum.size(); // ループによる重複をなくした移動回数
        int primalyCount = loopNum.indexOf(now); // ループ外の部分の移動回数
        int loopCount = size - primalyCount; // ループ部分の移動回数

        long num = k; // 移動回数
        if (primalyCount < num) {
            num = ((num - primalyCount) % loopCount) + primalyCount;
        }

        int result = loopNum.get((int) num) + 1;

        // 出力
        System.out.println(result);
    }
}


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

int main(){
  long a,b;
  while(1){
    cin>>a>>b;
    if(!a && !b)break;
    long rest=b-a;
    int sand,five,hand;
    sand=rest/1000;
    five=(rest-sand*1000)/500;
    hand=(rest-sand*1000-five*500)/100;
    cout<<hand<<" "<<five<<" "<<sand<<endl;
  }
  return 0;
}

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

inline bool isOK(int P, int n, int k, int w[]){
	int wt=0, cnt=1;
	
	for(int i=0; i<n; i++){
		if( wt + w[i] <= P && cnt <= k){
			wt += w[i];
		} else if (w[i] <= P && cnt <= k-1){
			wt = w[i];
			cnt++;
		} else{
			return false;
		}
	}
	return true;
}



int main(){
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	int w[n];
	
	for(int i=0; i<n; i++){
		cin >> w[i];
	}
	
	int left=0, right=1e9;
	while(left < right){
		int mid = (left + right)/2;
		if(isOK(mid, n, k, w)){
			right = mid;
		} else{
			left = mid + 1;
		}
	}
	cout << left << "\n";
}

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

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

	for(int i = 1; i <= n; i++){
		if(i % 3 == 0) cout << " " << i;
		else if(i % 10 == 3) cout << " " << i;
		else if(i/10 % 10 == 3) cout << " " << i;
		else if(i/100 % 10 == 3) cout << " " << i;
		else if(i/1000 % 10 == 3) cout << " " << i;
	}
	cout << endl;

	return 0;

}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int A[50];

int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) scanf("%d", &A[i]);
  int cnt = 0;
  rep(i, n) {
    if (A[i] != i + 1) cnt++;
    if (cnt >= 3) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
typedef unsigned long long u64;
using namespace std;

#define MAX_N 100
#define MAX_W 100000

int N, weight_limit;
int weight[MAX_N + 10];
int value[MAX_N + 10];
i64 dp[MAX_N + 10][MAX_W + 10] = {};

void Solve()
#define next_item (item + 1)
{
	for (int item = 0; item < N; ++item){
		for (int test_weight = 0; test_weight <= weight_limit; ++test_weight){
			if (test_weight >= weight[item])
				dp[next_item][test_weight] = max(dp[item][test_weight - weight[item]] + value[item], dp[item][test_weight]);
			else
				dp[next_item][test_weight] = dp[item][test_weight];
		}
	}
	cout << dp[N][weight_limit] << endl;
}

void Init()
{
	cin >> N >> weight_limit;
	for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];
}

int main()
{
	Init();
	Solve();
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> A(N + 1,vector<int>());
  rep(i, 0, M) {
    cin >> P[i] >> Y[i];
    A[P[i]].push_back(Y[i]);
  }
  rep(i, 1, N + 1) sort(A[i].begin(), A[i].end());
  rep(i, 0, M) {
    int n = lower_bound(A[P[i]].begin(), A[P[i]].end(), Y[i]) - A[P[i]].begin();
    printf("%06d%06d\n", P[i], n + 1);
  }
  return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long Long;
 
int main(){
   Long n;
  cin >> n;
  	Long arr[n+1];
  memset( arr, 0, (n+1) * sizeof(Long) );
  for(Long i = 0 ; i<n-1 ; ++i){
    Long x;
    cin >> x;
    arr[x]++;
  }
  
  for(Long i=1 ; i<=n ; ++i) cout << arr[i] <<'\n';
  return 0;
  
}

Measured memory_bytes: 5168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, k, t, u, v, l;
bool pos[100100];
double dv[100100];

int main() {
	cin >> n >> k >> t >> u >> v >> l;
	rep(i, n) {
		int num;
		cin >> num;
		pos[num] = 1;
	}
	int w = 0;
	int cnt = 0;
	bool f = 0;
	rep(i, l) {
		if (!f) {
			if (pos[i]) {
				f = 1;
				w = t*v - 1;
			}
		}
		else {
			if (pos[i]) {
				if (cnt < k)cnt++;
				else w = t*v;
			}
			if (w > 0)w--;
			else {
				if (cnt > 0) {
					cnt--;
					w = t*v - 1;
				}
				else f = 0;
			}
		}
		if (f)dv[i] = v;
		else dv[i] = u;
	}
	double ans = 0;
	rep(i, l) {
		//cout << i << " " << dv[i] << endl;
		ans += (1.0 / dv[i]);
	}
	printf("%.10lf\n", ans);
}

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

#define pb push_back
#define mp make_pair
typedef long long int ll;
#define mod 1000000007


void solve()
{
	string str;
	cin >> str;

	stack<int> s;
	for (int i = 0; i < str.length(); i++)
	{
		if (str[i] == '0')
			s.push(0);
		else if (str[i] == '1' )
			s.push(1);
		else
		{
			if (s.empty() == false)
				s.pop();
		}
	}

	stack<int> temp;
	while (s.empty() == false)
	{
		temp.push(s.top());
		s.pop();
	}

	while (temp.empty() == false)
	{
		cout << temp.top() ;
		temp.pop();
	}


}



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

#ifndef ONLINE_JUDGE
	freopen("1input.txt", "r", stdin);
	freopen("1output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 3664
from collections import deque

k = int(input())

d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

if k <= 9:
    print(k)
    exit()

cnt = 9

while cnt <= 10**5:
    a = d.popleft()
    if a%10 != 0:
        num = 10*a + a%10 - 1
        d.append(num)
        cnt += 1
        if cnt == k:
            print(num)
            exit()

    num = 10*a + a%10
    d.append(num)
    cnt += 1
    if cnt == k:
        print(num)
        exit()
    
    if a%10 != 9:
        num = 10*a + a%10 +1
        d.append(num)
        cnt += 1
        if cnt == k:
            print(num)
            exit()

Measured memory_bytes: 6072
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,l = 0,r = 0,c = 0,sum = 0;
    cin >> n;
    vector<ll> a(n);
    rep0(i, n){
        cin >> a[i];
        sum += a[i];
    }
    rep0(i, n){
        l += a[i];
        if(l > sum / 2){
            l -= a[i];
            c = i;
            break;
        }
    }
    r = sum - l - a[c];
    cout << min(abs(l - (r + a[c])),abs(r - (l + a[c]))) << endl;
    return 0;
}


Measured memory_bytes: 1792
while True:
	s = input()
	if s == '.':
		break
	flag = False
	stack = []
	for c in s:
		if c in '[(':
			stack.append(c)
		elif c in '])':
			if c == ']' and len(stack)>0 and stack[-1] == '[':
				stack.pop()
			elif c == ')' and len(stack)>0 and stack[-1] == '(':
				stack.pop()
			else:
				flag = True
				break
	if stack or flag:
		print('no')
	else:
		print('yes')

Measured memory_bytes: 7356
#include "bits/stdc++.h"
using namespace std;
const long long int inf=1e18L+7;
int main(){
    int n;
    cin>>n;
    long long int W;
    cin>>W;
    vector<long long int> wt(n);
    vector<int>val(n);
    int sum_value=0;
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
        sum_value+=val[i];
    }
    vector<long long int>dp(sum_value+1,inf);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int v=sum_value-val[i];v>=0;v--) {
            dp[v+val[i]]=min(dp[v+val[i]],dp[v]+wt[i]);
        }
    }
    long long int ans=0;
    for(int i=0;i<=sum_value;i++){
        if(dp[i]<=W){
            ans=max(ans,(long long)i);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

//UnionFind
class UnionFind {
    vector<int>par, sz;
public:
    UnionFind() {}
    UnionFind(int n) {
        par = sz = vector<int>(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void merge(int x, int y) {
        x = find(x); y = find(y);
        if (x == y)return;
        if (sz[x] > sz[y]) {
            par[y] = x;
            sz[x] += sz[y];
        }
        else {
            par[x] = y;
            sz[y] += sz[x];
        }
    }
    bool issame(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sz[find(x)];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    P a[m];
    rep(i, m) cin >> a[i].first >> a[i].second;
    UnionFind uf(n);
    ll ans[m + 1];
    memset(ans, 0, sizeof(ans));
    ans[m] =(ll) n * (n - 1) / 2;
    ll ans_1 = ans[m];
    for(int i = m - 1; i >= 0; i --){
        ans[i] = ans_1;
        if(uf.issame(a[i].first - 1, a[i].second - 1)) continue;
        ans_1 -=(ll) uf.size(a[i].first - 1) *(ll) uf.size(a[i].second - 1);
        uf.merge(a[i].first - 1, a[i].second - 1);

    }
    for(int i = 0; i < m; i ++) cout << ans[i] <<endl;

}

Measured memory_bytes: 3712
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int64_t f(int left, int right)
{
    int64_t res = 0;
    int tmp = right - left;
    for (int i = 0; i <= tmp; i++)
    {
        res += i;
    }
    return res;
}

int main()
{
    int N;
    cin >> N;
    vector<int64_t> A(N);
    rep(i, N) cin >> A[i];

    int left = 0, right = 0;
    int64_t sum = 0;
    int64_t cnt = 0;
    bitset<21> bt(0);

    for (; right < N; right++)
    {
        bitset<21> bt_now(A[right]);
        bt ^= bt_now;
        // cout << bt << endl;
        sum += A[right];
        while (bt.to_ullong() != sum)
        {
            // cout << "left:" << left << "/right:" << right << endl;
            cnt += right - left;
            bitset<21> tp(A[left]);
            bt ^= tp;
            sum -= A[left];
            left++;
        }
    }
    // cout << "left:" << left << "/right:" << right << endl;
    cnt += f(left, right);
    cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

struct UF{
  vector<int> parent, size_;
  UF(int n){
    rep(i, n){
      parent.push_back(i);
      size_.push_back(1);
    }
  }
  int root(int x){
    if(parent[x] == x) return x;
    return parent[x] = root(parent[x]);
  }
  void unite(int x, int y){
    if(root(x) == root(y)) return;
    else if(root(x) > root(y)){
      size_[root(y)] += size_[root(x)];
      parent[root(x)] = root(y);
      return;
    }
    else{
      size_[root(x)] += size_[root(y)];      
      parent[root(y)] = root(x);
      return;
    }
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  int size(int x){
    return size_[root(x)];
  }
};

int main() {
  int n, m, s = 0; scanf("%d %d", &n, &m);
  vector<pii> v(m); rep(i, m) scanf("%d %d", &v[i].fi, &v[i].se);
  rep(i, m){
    UF t(n); bool b = 0;
    rep(j, m) if(i != j) t.unite(v[j].fi-1, v[j].se-1);
    rep(i, n){
      if(t.root(i) != 0){
        b = 1;
        break;
      }
    }
    if(b) ++s;
  }
  printf("%d\n", s);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b;
        n--;
        
        while (n-- > 0) {
            b = sc.nextLong();
            a = lcm(a, b);
        }
        
        System.out.println(a);
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) return a;
        
        return gcd(b, a % b);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, pair<int,int>> shop;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


vector<shop> x;


bool comp(shop x, shop y) {
	if (x.first < y.first) {
		return true;
	}
	else if (x.first > y.first) {
		return false;
	}
	else {
		if (x.second.first > y.second.first)return true;
		else return false;
	}
}

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		shop s;
		cin >> s.first >> s.second.first;
		s.second.second = i + 1;

		x.push_back(s);
	}
	sort(x.begin(), x.end(), comp);
	for (int i = 0; i < N; i++) {
		print(x[i].second.second);
	}









	return 0;
}

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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<int,int> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){
	stringstream ss;
	ss << a;
	string str = ss.str();
	return str;
}


string conv(char a){
	stringstream ss;
	ss << a;
	string str = ss.str();
	return str;
}

int conv(string a){
    stringstream geek(a); 
    int x = 0; 
    geek >> x;   
	return x;
}


int main(){
	int n; cin>> n;
	double total = 0;
	double y;
	string s;
	rep(i,1,n){
		cin>> y >> s;
		if(!s.compare("JPY"))
			total += y;
		else
			total += 380000ll*y;
	}
	cout<< total;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3+5 , M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const double Pii = 3.14159265359;
ll n, m;
ll mem[N][N];
ll a[N];
ll solve(int idx, int su)
{
    if(idx == n)
    {
        if(su == m) return 1;
        return 0;
    }
    if(mem[idx][su]!=-1) return mem[idx][su];
    ll op1 = 0, op2 = 0;
    if(su + a[idx] <= m) op1 = solve(idx+1, su+a[idx]);
    op2 = (solve(idx+1, su)*2);
    return mem[idx][su] = (op1 + (op2%M))%M;
}

int main()
{
    FIO
    cin >> n >> m;
    for(int i=0; i<n; ++i) cin >> a[i];
    memset(mem, -1, sizeof mem);
    ll ans = solve(0, 0);
    cout << ans << endl;
    return 0;
}



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


int main() {
	int N;
	int d[110];
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> d[i];
	set<int> values;
	for (int i = 0; i < N; ++i) {
		values.insert(d[i]);
	}

	cout << values.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10000];
int b[10000];
int c[10000];
int main(){
  string s;
  int n,ans=0;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  for(int i=0;i<n-1;i++) cin>>c[i];
  for(int i=0;i<n;i++){
    ans+=b[a[i]-1];
    if(i>0){
      if(a[i-1]==a[i]-1) ans+=c[a[i]-2];
    }
  }
  cout<<ans<<"\n";
  return(0);
}

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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

void solve() {
	int x, y;
	char op;
	cin >> x >> op >> y;
	if (op == '+') cout << x + y << endl;
	else cout << x - y << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 10005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, k = 0,   y = 2, h,s , ans =0, mx, mn, mx1, x;
ll m;
ll a[MAXX][MAXX], b[MAXX], c[MAXX];
vector<ll> adj[MAXX];
bool used[MAXX];


signed main()
{
	FAST;
	string str, str1 ;
	str[0] = 'P';
	cin >> str;
	for(ll i = 0; i < str.size(); i++){
		if(str[i] == '?'){
			cout << "D";
		}
		else{
			cout << str[i];
		}
	}
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    ll ma = sqrt(n);
    for (ll i = 2; i <= ma; i++)
    {
        ll j = i;
        while (n % j == 0)
        {
            ans++;
            n /= j;
            j *= i;
        }
        while (n % i == 0)
            n /= i;
    }
    cout << ans + (ma < n ? 1 : 0) << endl;
}

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

int main() {
    ll N, M; cin >> N >> M;
    if(M <= N*2){
        ll ans = M/2;
        cout << ans << endl;
    } else {
        ll ans = N + ((M - N*2) / 4);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
#define maxn 200010
using namespace std;
LL ans;
int a[maxn];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ans+=a[1];
    for(i=3; i<=n; i++)
        ans+=a[(i+1)/2];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2520
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

int main(){
  int i, q;

  scanf("%d", &n);
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
  }

  q = partition(0, n-1);

  for( i = 0 ; i < n ; i++ ){
    if( i ) printf(" ");
    if( i == q ) printf("[");
    printf("%d", A[i]);
    if( i == q ) printf("]");
  }
  printf("\n");

  return 0;
}



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

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front()){
		cout << "YES"<< endl;	
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

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

    long long x;
    cin >> x;
    
    long long sol = x / 11 * 2;
    
    if (x % 11 > 6)
        sol += 2;
    else if (x % 11 > 0)
        ++sol;
    
    cout << sol;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  long long a[100], max, min;
  int n, i;

  scanf("%lld", &n);

  for (i = 0; i < n; ++i)
  {
    scanf("%lld", &(a[i]));
  }

  min = a[0];
  max = a[0];

  for (i = 1; i < n; ++i) {
    if (min > a[i])
    {
      min = a[i];
    }
    if (max < a[i])
    {
      max = a[i];
    }
  }

  printf("%lld", max - min);

  return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author GYSHGX868
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int a = in.nextInt();
      int b = in.nextInt();
      int c = in.nextInt();
      if (a == b && a == c) {
        out.printLine(1);
      } else if (a == b || b == c || a == c) {
        out.printLine(2);
      } else {
        out.printLine(3);
      }
    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void close() {
      writer.close();
    }

    public void printLine(int i) {
      writer.println(i);
    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      boolean isSpaceChar(int ch);

    }

  }
}



Measured memory_bytes: 21588
program AGC009A
    implicit none
    integer(8)::i,N,ans
    integer(8),allocatable,dimension(:)::A,B
    read(5,*)N
    allocate(A(N))
    allocate(B(N))
    !末尾から挿入
    read(5,*)(A(N-i),B(N-i),i=0,N-1)
    ans=0

    do i=1,N
        if(i==1)then
            ans=mod(B(i)-mod(A(i),B(i)),B(i))
        else
            A(i)=A(i)+ans
            ans=ans+mod(B(i)-mod(A(i),B(i)),B(i))
        end if
    end do

    print'(i0)',ans
end program AGC009A

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

void DBG() { cerr << endl; }
template<typename Head, typename... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#ifdef NAIM
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)
#else 
#define dbg(...)
#endif

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ll long long
#define ints(a...) int a; read(a)
#define IN(a) for (auto &it : a) cin >> it

void solve() {
    ints(n, m);
    vector<int> h(n + 1);
    for (int i = 1; i <= n; i++) read(h[i]);

    unordered_set<int> e[n + 1];
    for (int i = 0; i < m; i++) {
        ints(a, b);
        e[a].insert(b);
        e[b].insert(a);
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        bool yes = 1;
        for (auto it : e[i]) {
            if (h[it] >= h[i]) {
                yes = 0;
                break;
            }
        }
        cnt += yes;
    }

    show(cnt);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 18636
from collections import deque
a = deque(input())
a.append("a")
b = deque(input())
b.append("b")
c = deque(input())
c.append("c")

start = a.popleft()
while a and b and c:
    if start == "a":
        start = a.popleft()
    elif start == "b":
        start = b.popleft()
    else:
        start = c.popleft()

print(str(start).upper())

Measured memory_bytes: 83256
n = int(input())
h = []
for _ in range(n):
    h.append(list(map(int, input().split())))

res = h[0]
for i in range(1, n):
    tmp = res[:]
    for j in range(3):
        res[j] = h[i][j] + max(tmp[(j + 1) % 3], tmp[j - 1])
print(max(res))

Measured memory_bytes: 61528
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N,M,Q=mis()
    R = [lmis() for _ in range(Q)]
    ans = 0
    def rec(s):
        if len(s)==N:
            nonlocal ans
            ans = max(ans, sum(d for a,b,c,d in R if s[b-1]-s[a-1]==c))
        else:
            for i in range(s[-1], M+1):
                s.append(i)
                rec(s)
                s.pop()
    for i in range(1, M+1):
        rec([i])
    print(ans)



main()



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

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

    int n,k,s;cin>>n>>k>>s;

    for(int i=0;i<n;i++)
    {
        if(i<k)cout<<s<<" ";
        else if(s==1e9) cout<<1<<" ";
        else cout<<s+1<<" ";
    }

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int h, w, n;
  cin >> h >> w >> n;

  int ans = n / (max(h, w));
  if (n % max(h, w) != 0) ans++;
  cout << ans << endl;


  
  return 0;
}

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

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

int main() {
    int a, b, c, k; cin >> a >> b >> c >> k;
    int cnt = 0;
    while(a >= b) {
        b *= 2;
        ++cnt;
    }
    while(b >= c) {
        c *= 2;
        ++cnt;
    }
    cout << ((cnt > k) ? "No" : "Yes") << endl;
}


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

const int N = 200005;

int n, K, L;
int par[N];
int a[N];
vector < pair<int,int> > G[N];
int ans[N];

int find(int p) { return p == par[p] ? p : par[p] = find(par[p]); }
void join(int p, int q) { par[find(p)] = find(q); }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> K >> L;

	for (int i = 1; i <= n; ++i) par[i] = i;
	while(K--) {
		int u, v; cin >> u >> v;
		if (find(u) != find(v)) join(u, v);
	}
	for (int i = 1; i <= n; ++i) a[i] = find(i);

	for (int i = 1; i <= n; ++i) par[i] = i;
	while(L--) {
		int u, v; cin >> u >> v;
		if (find(u) != find(v)) join(u, v);
	}
	for (int i = 1; i <= n; ++i) G[find(i)].push_back(make_pair(a[i], i));

	for (int i = 1; i <= n; ++i) {
		sort(G[i].begin(), G[i].end());
		for (int j = 0; j < G[i].size(); ) {
			int k = j, val = G[i][j].first;
			while(j < G[i].size() && G[i][j].first == val) ++j;
			for (int l = k; l < j; ++l) {
				ans[G[i][l].second] = j - k;
			}
		}
	}

	for (int i = 1; i <= n; ++i) printf("%d ", ans[i]); printf("\n");
}

Measured memory_bytes: 13312
-module('Main').
-export([main/1]).

main(_) ->
    {ok, [N]} = io:fread("", "~d"),
    Edge = find_edge(N),
    Rest = N - find_n(Edge - 1),
    S = alpha(Rest, Edge),
    io:format("~s~n", [S]),
    halt().

find_edge(N) ->
    find_edge(0, N).
find_edge(E, N) ->
    case find_n(E) > N of
        true ->
            E;
        false ->
            find_edge(E + 1, N)
    end.

find_n(0) ->
    1;
find_n(N) ->
    floor(math:pow(26, N)) + find_n(N - 1).

alpha(N, X) ->
    alpha(N, X, []).
alpha(_, 0, Acc) ->
    Acc;
alpha(N, X, Acc) ->
    Char = (N rem 26) + $a,
    NewN = N div 26,
    alpha(NewN, X - 1, [Char|Acc]).


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

int main(void){

	int n;
	cin >> n;
	for (int i = 0; i < n; i++){

		int x, y, b, p;
		cin >> x >> y >> b >> p;
		
		cout << (int)min((double)x*b + y*p, (double)((x*max(b, 5) + y*max(p, 2)) * 0.8)) << endl;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    int n,k;cin >> n >> k;
    string s;cin >> s;
    int cnt=0;
    int now=1;
    vector<int> nums;
    for(int i=0;i<n;i++){
        if(s[i]==(char)('0'+now)) cnt++;
        else{
            nums.push_back(cnt);
            cnt=1;
            now=1-now;
        }
    }
    if(cnt!=0) nums.push_back(cnt);
    if(nums.size()%2==0) nums.push_back(0);
    int right=0;
    int add=2*k+1;
    int ans=0,tmp=0;
    for(int left=0;left<nums.size();left+=2){
        int end=min(left+add,(int)nums.size());
        while(right<end){
            tmp+=nums[right];
            right++;
        }
        ans=max(ans,tmp);
        tmp-=nums[left]+nums[left+1];
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib> //abs(int)
using namespace std;
int main(void){
  int N, A; 
  cin >> N >> A;
  if(N % 500 <= A){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	
	a,z := len(s),0
	for i,v :=range s {
		if v == 'A' && i < a {
			a = i
		}
		if v == 'Z' && i > z {
			z = i
		}
	}
	fmt.Println(z - a + 1)
}

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

int main(void){
    int n,candy_max,get_candy,i,j;
    candy_max = 0;
    get_candy = 0;

    cin >> n;
    vector<vector<int>>  a(3,vector<int>(n+1));

    for(i=1; i<=n; i++){
        cin >> a.at(1).at(i);
    }
    for(i=1; i<=n; i++){
        cin >> a.at(2).at(i);
    }


//case1
    for(i=1; i<=n; i++){
        get_candy += a.at(1).at(i);
    }
    get_candy += a.at(2).at(n);
    candy_max = get_candy;
    get_candy = 0;


//case2
/*
    for(i=1; i<=n-1; i++){
        get_candy += a.at(1).at(i);
    }
    for(i=n-1; i<=n; i++){
        get_candy += a.at(2).at(i);
    }
    candy_max = max(candy_max, get_candy);
    get_candy = 0;
*/

//casex

    for(j=n-1; j>=1; j--){
        for(i=1; i<=j; i++){
        get_candy += a.at(1).at(i);
        }
        for(i=j; i<=n; i++){
            get_candy += a.at(2).at(i);
        }
        candy_max = max(candy_max, get_candy);
        get_candy = 0;
    }


    cout << candy_max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define ll long long
#define fo(i, x, y) for(int i = x; i <= y; i ++)
#define fd(i, x, y) for(int i = x; i >= y; i --)
using namespace std;

const int mo = 1e9 + 7;

const int N = 1e5 + 5;

char s[N]; int n;
int f[N];
ll ni3, ans;

ll ksm(ll x, ll y) {
	ll s = 1;
	for( ; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

int main() {
//	freopen("d.in", "r", stdin);
	ni3 = ksm(3, mo - 2);
	scanf("%s", s + 1); n = strlen(s + 1);
	ll o = 0; fo(i, 1, n) o += s[i] == '?'; o = ksm(3, o);
	ll p = 0;
	fd(i, n, 1) {
		if(s[i] == 'C') {
			p = (p + o) % mo;	
		} else
		if(s[i] == 'B') {
			f[i] = p;
		} else
		if(s[i] == '?') {
			f[i] = p * ni3 % mo;
			p = (p + o * ni3) % mo;
		}
	}
	p = 0;
	fd(i, n, 1) {
		if(s[i] == 'A')
			ans = (ans + p) % mo; else
		if(s[i] == '?')
			ans = (ans + p * ni3) % mo;
		p = (p + f[i]) % mo;
	}
	printf("%lld", ans);
}

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

int main() {
  int n,m; cin>>n>>m;
  int a,b;
  vector<int> v1;
  vector<int> vn;
  set<int> s;
  
  rep(i,m){
    cin>>a>>b;
    if(a==1){v1.push_back(b);s.insert(b);}
    if(b==1){v1.push_back(a);s.insert(b);}
    if(a==n){vn.push_back(b);s.insert(a);}
    if(b==n){vn.push_back(a);s.insert(a);}
  }
  if(s.size()<v1.size()+vn.size()){cout<<"POSSIBLE";}
  else{cout<<"IMPOSSIBLE";}
}

Measured memory_bytes: 10480
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 998244353;

int N;
ll dp[200][200], ans = 0;
vector<pii> p, tmp;

int area (pii a, pii b, pii c) {
    b.s -= a.s, b.f -= a.f;
    c.s -= a.s, c.f -= a.f;
    return b.s*c.f-b.f*c.s;
}

double angle (pii a, pii b) {
    b.f -= a.f, b.s -= a.s;
    if (b.f == 0) return MOD;
    return atan((double)b.s/b.f);
}

bool comp (pii a, pii b) {
    double a1 = angle(tmp[0],a), b1 = angle(tmp[0],b);
    if (a1 != b1) return a1 > b1;
    return a < b;
}

bool cw(pii a, pii b, pii c) {
    if (a == b) return 1;
    return area(a,b,c) > 0;
}

bool in (pii a, pii b, pii c, pii o) {
    if (o == a || o == b || o == c) return 0;
    if (area(a,b,o) == 0 && o > min(a,b) && o < max(a,b)) return 0;
    if (abs(area(a,b,o))+abs(area(b,c,o))+abs(area(a,c,o)) != abs(area(a,b,c))) return 0;
    if (a == b) return o < c;
    return 1;
}

void solve(int x) {
    dp[0][0] = 1;
    tmp.clear();
    FOR(i,x,p.size()) tmp.pb(p[i]);
    sort(tmp.begin()+1,tmp.end(),comp);
    
    FOR(i,1,tmp.size()) F0R(j,i) {
        dp[j][i] = 0; ll num = 1;
        
        FOR(k,j+1,i) if (in(tmp[0],tmp[j],tmp[i],tmp[k])) num = 2*num % MOD;
        F0R(k,j+1) if (cw(tmp[k],tmp[j],tmp[i])) 
            dp[j][i] = (dp[j][i]+num*dp[k][j]) % MOD;
            
        if (j != 0)  ans = (ans+dp[j][i]) % MOD;
    }
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N; p.resize(N);
	F0R(i,N) cin >> p[i].f >> p[i].s;
	sort(p.begin(),p.end());
	F0R(i,p.size()) solve(i);
	cout << ans;
}

// read!
// ll vs. int!

Measured memory_bytes: 640
A,B,C,X,Y = (int(i) for i in input().split())  
ans = 0
if C*2 <= A+B:
	for i in range(min(X,Y)):
		ans += C*2
		X-=1
		Y-=1
	ans += min(C*2, A)*X
	ans += min(C*2, B)*Y
else:
	ans += A*X
	ans += B*Y
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<cstring>
#include<iterator>
#include <map>
using namespace std;

bool cmp(pair<long long, long long> a, pair<long long, long long> b){
    return a.second < b.second;
}

int main()
{
    long long t, i, j, k, n, ch, ch1, count, prev_left, prev_right, m;
    cin >> n;
    if (n % 1000 != 0)
        cout << 1000 - n % 1000;
    else
        cout << 0;
    return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

int wie,kol;
int t[505][505];
pair<int,int>wcz;
int wyn;
bool wziete;
vector<pair<pair<int,int>,pair<int,int> > >w;
vector<pair<int,int> >w1;
int main()
{
    ios::sync_with_stdio(0);
    cin>>wie>>kol;
    for(int i=1;i<=wie;++i)
    {
        for(int j=1;j<=kol;++j)cin>>t[i][j];
    }
    for(int i=1;i<=wie;++i)
    {
        if(i%2==1)
        {
            for(int j=1;j<=kol;++j)
            {
                if(wziete==1)
                {
                    ++wyn;
                    w.push_back(make_pair(make_pair(wcz.ff,wcz.ss),make_pair(i,j)));
                    if(t[i][j]%2==1)wziete=0;
                }
                else if(t[i][j]%2==1)wziete=1;
                wcz.ff=i;
                wcz.ss=j;
            }
        }
        else
        {
            for(int j=kol;j>=1;--j)
            {
                if(wziete==1)
                {
                    ++wyn;
                    w.push_back(make_pair(make_pair(wcz.ff,wcz.ss),make_pair(i,j)));
                    if(t[i][j]%2==1)wziete=0;
                }
                else if(t[i][j]%2==1)wziete=1;
                wcz.ff=i;
                wcz.ss=j;
            }
        }
    }
    cout<<wyn<<endl;
    for(int i=0;i<w.size();++i)cout<<w[i].ff.ff<<" "<<w[i].ff.ss<<" "<<w[i].ss.ff<<" "<<w[i].ss.ss<<endl;
}


Measured memory_bytes: 5232
#include <stdio.h>
#define MAX 100000

int parent(int i){ return i / 2; }
int left(int i){ return 2 * i; }
int right(int i){ return 2 * i + 1; }

int main(){
  int H, i, A[MAX+1];

  scanf("%d", &H);
  for(i=1; i<=H; i++) scanf("%d", &A[i]);

  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= H) printf("left key = %d, ",A[left(i)]);
    if(right(i) <= H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2108
#include<iostream>

int main(){
  int a, b, c;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;

  if(a < b && b < c){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
    
  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <stack>
#include <string>
#include <functional>
using namespace std;

int main()
{
	stack<int> s;
	string t;

	auto g = [&]() {int u = s.top(); s.pop(); return u;};
	auto f = [&](auto op) {int b = g(), a = g(); s.push(op(a, b));};

	while (cin >> t) {
		switch (t[0]) {
		case '+': f(plus<int>()); break;
		case '-': f(minus<int>()); break;
		case '*': f(multiplies<int>()); break;
		default: s.push(stoi(t));
		}
	}
	cout << s.top() << endl;
}


Measured memory_bytes: 3180