akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;

    vector<int> X(N);
    vector<int> temp(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
    }
    temp = X;
    sort(temp.begin(), temp.end(), greater<int>());
    int left = temp[N / 2 - 1];
    int right = temp[N / 2];

    int location;
    for (int i = 0; i < N; i++)
    {
        if (X[i] <= right)
        {
            printf("%d\n", left);
        }
        else
        {
            printf("%d\n", right);
        }
    }
    return (0);
}

Measured memory_bytes: 3712
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

h,w,n,*ab = map(int, read().split())

M = iter(ab)
d = {}
for a,b in zip(M,M):
    for i in range(-1,2):
        na = a+i
        if 2 <= na <= h-1:
            for j in range(-1,2):
                nb = b+j
                if 2 <= nb <= w-1:
                    if (na,nb) in d:
                        d[(na,nb)] += 1
                    else:
                        d[(na,nb)] = 1
            
#print(d)
ans = [0]*10
for k,v in d.items():
    ans[v] += 1

ans[0] = (h-2)*(w-2)-sum(ans)
print(*ans,sep="\n")
    
    
    
    

Measured memory_bytes: 155768
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

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

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    int n,i,l;
    scanf("%d\n",&n);
    int A[n];
    for(i=1;i<=n;i++)
    {
        scanf("%d",&l);
        A[l]=i;
    }
    for(i=1;i<=n;i++)
    {
        printf("%d ",A[i]);
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int MX = 25005;
const int MK = 404;
const ll MOD = 1000000007;

template <typename T> void add(T &x, const T &y)
{
	x = (x+y) % MOD;
}

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

ll qpow(ll x, ll t)
{
	ll ret = 1;
	while(t)
	{
		if(t & 1) ret = ret*x % MOD;
		x = x*x % MOD;
		t >>= 1;
	}
	return ret;
}

int n, k, m;
int seq[MX];

void input()
{
	read(n), read(k), read(m);
	for(int i=1; i<=m; i++) read(seq[i]);
}

int pre[MX], lst[MX];
ll lft[MX], rgt[MX], f[2][MK], g[2][MK];

int count_illegal(int *s, ll *tar)
{
	bool flg = 0;
	for(int i=1; i<=k; i++) lst[i] = 0;
	int mx = 0;
	for(int i=1; i<=m; i++)
	{
		cmax(mx, pre[i] = lst[seq[i]]);
		lst[seq[i]] = i;
		if(i-mx == k) flg = 1;
	}
	int cur = 0;
	memset(f[cur], 0, sizeof(f[cur]));
	f[cur][m-mx] = 1;
	tar[0] = 1;
	for(int i=1; i<=n; i++)
	{
		cur ^= 1;
		ll sum = 0;
		for(int j=k-1; j>=1; j--)
		{
			add(sum, f[cur^1][j]);
			f[cur][j] = (sum + f[cur^1][j-1]*(k-j+1)) % MOD;
			add(tar[i], f[cur][j]);
		}
	}
	if(flg) return 1;
	else if(!mx) return -1;
	else return 0;
}

void work()
{
	int flg = count_illegal(seq, rgt);
	reverse(seq+1, seq+m+1);
	count_illegal(seq, lft);
	ll ans = qpow(k, n-m) * (n-m+1) % MOD;
	if(flg == 0) for(int i=0; i<=n-m; i++) add(ans, MOD*MOD - lft[i]*rgt[n-m-i]);
	else if(flg == -1)
	{
		ll con = 0;
		int cur = 0;
		memset(f[cur], 0, sizeof(f[cur]));
		f[cur][1] = k;
		g[cur][1] = (1>=m) * k;
		for(int i=2; i<=n; i++)
		{
			cur ^= 1;
			ll sumf = 0, sumg = 0;
			for(int j=k-1; j>=1; j--)
			{
				add(sumf, f[cur^1][j]);
				add(sumg, g[cur^1][j]);
				f[cur][j] = (sumf + f[cur^1][j-1]*(k-j+1)) % MOD;
				g[cur][j] = (sumg + g[cur^1][j-1]*(k-j+1)) % MOD;
				if(j >= m) add(g[cur][j], f[cur][j]);
			}
		}
		for(int j=1; j<k; j++) add(con, g[cur][j]);
		for(int i=k; i>k-m; i--) con = con * qpow(i, MOD-2) % MOD;
		ans = (ans - con + MOD) % MOD;
	}
	printf("%lld\n", ans);
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 896
h, w = map(int, input().split())
lst = []
alldot = [True] * w
for i in range(h):
  s = input()
  if s.count('#') >= 1:
    lst.append(s)
    for t in range(w):
      alldot[t] = alldot[t] and s[t] == '.'
  else:
    h -= 1
res = [''] * h
for i in range(h):
  for j in range(w):
    if alldot[j]:
      pass
    else:
      res[i] += lst[i][j]
for i in res:
  print(i)

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll k,n;cin>>k>>n;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    ll ans[n];
    for(int i=0;i<n-1;i++){
        ans[i]=arr[i+1]-arr[i];
    }
    ans[n-1]=k-arr[n-1]+arr[0];
    sort(ans,ans+n,greater<int>());
    cout<<k-ans[0]<<"\n";

}


Measured memory_bytes: 3968
#[allow(unused_imports)]
use std::{
    i64,
    f64,
    cmp,
    process,
};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };

    (stream = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };

    ($($r:tt)*) => {
        use std::io::*;
        let mut stream = stdin();
        let stream = &mut stream;
        input_inner!{stream, $($r)*}
    };
}

macro_rules! input_inner {
    ($stream:expr) => {};
    ($stream:expr, ) => {};

    ($stream:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($stream, $t);
        input_inner!{$stream $($r)*}
    };
}

macro_rules! read_value {
    ($stream:expr, ( $($t:tt),* )) => {
        ( $(read_value!($stream, $t)),* )
    };

    ($stream:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($stream, $t)).collect::<Vec<_>>()
    };

    ($stream:expr, chars) => {
        read_value!($stream, String).chars().collect::<Vec<char>>()
    };

    ($stream:expr, usize1) => {
        read_value!($stream, usize) - 1
    };

    ($stream:expr, $t:ty) => {
        $stream.by_ref().bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<$t>()
            .expect("Parse error")
    };
}

fn main() {
    input!{n: usize}
    input!{s: String}
    let mut l: usize = 0;
    let mut r: usize = n / 2 + 1;
    while (l + 1 < r) {
        let m = (l + r) / 2;
        let mut ok = false;
        for i in 0 .. n - 2 * m + 1 {
            if s[i + m ..].contains(&s[i .. i + m]) {
                ok = true;
                break;
            }
        }
        if ok {
            l = m;
        } else {
            r = m;
        }
    }
    println!("{}", l);
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll q, h, s, d, n, ans;

int main()
{
	cin >> q >> h >> s >> d >> n;
	ans=0;
	ans+=(min(q*8,min(h*4,min(s*2,d))))*(n/2);
	if(n%2){
		ans+=min(q*4,min(h*2,s));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define pb push_back
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 60; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------

signed main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
}

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

using namespace std;

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

  int a,b,x; cin>>a>>b>>x;
  auto v = a*a*b;
  if (x*2 <= v) {
    auto ans = atan(double(a*b*b)/(2*x));
    ans = ans * 180 / M_PI;
    cout << fixed << setprecision(10) <<  ans << endl;
  } else {
    auto ans = atan(double(v-x)*2/pow(a,3));
    ans = ans * 180 / M_PI;
    cout << fixed << setprecision(10) <<  ans << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	int ans = inf;
	auto keta = [&](ll a) {
		int res = 0;
		while (a) res++, a /= 10;
		return res;
	};
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			mins(ans, max(keta(i), keta(n / i)));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
N = int(input())
e_list = [[] for i in range(N)]
for i in range(N):
    S = input()
    for j in range(i+1,N):
        if S[j]=="1":
            e_list[i].append(j)
            e_list[j].append(i)

from collections import deque

ans = -1
for vi in range(N):
    flag = True
    Q = deque([vi])
    min_path_list = [10**27]*N #問題によりここを変える
    min_path_list[vi] = 0
    max_path = 0
    while len(Q)>0:
        v = Q.pop()
        for v1 in e_list[v]:
            if min_path_list[v1]==10**27:
                Q.appendleft(v1)
                min_path_list[v1]=min(min_path_list[v1],min_path_list[v]+1) #問題によりここを変える
                max_path = max(max_path,min_path_list[v1])
            elif min_path_list[v1]!=min_path_list[v]+1 and min_path_list[v1]!=min_path_list[v]-1:
                flag=False
                break
    if flag:
        ans = max(max_path,ans)

if ans==-1:
    print(-1)
else:
    print(ans+1)

Measured memory_bytes: 42716
from sys import stdin

input = stdin.readline


def read():
    return map(int, input().split())


def main():
    input()
    *A, = read()
    *B, = read()
    pre = A[0]
    ans = 0
    for a, b in zip(A[1:], B):
        tmp1 = pre if pre < b else b
        b -= tmp1
        tmp2 = a if a < b else b
        ans += tmp1 + tmp2
        pre = a - tmp2
    print(ans)
    return


main()


Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
int N;
const int maxn = 2e5 + 5;
long long f[maxn],g[maxn];
int main() {
    cin>>N;
    for(int i = 1; i <= N; i++){
        int tmp;
        cin>>tmp;
        f[i] = f[i - 1] + tmp;
        g[i] = g[i - 1] ^ tmp;
    }
    int l = 1;
    long long ans = 0;
    for(int r = 1; r <= N; r++){
        while(f[r] - f[l - 1] != (g[r] ^ g[l - 1])) l++;
        ans += r - l + 1;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  long long M,sumC=0,sumN=0;
  cin >> M;
  vector<long long> D(M),C(M);
  for(int i=0;i<M;i++){
    cin >> D[i] >> C[i];
    sumC += C[i];
    sumN += D[i]*C[i];
  }
  
  long long ans = sumN/10;
  long long x = ans + (sumN%10);
  while(x>=10){
    ans += x/10;
    x = (x/10) + (x%10);
  }
  ans += sumC-1;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.pop(0)

if N>1:
    for _ in range(N-1):
        B=list(map(int,input().split()))
        B.pop(0)
        A=[num for num in A if num in B]

print(len(A))

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

//問題文より、[ 島 1 <-> 島 i <-> 島 N ] となる島 i を調べる
//島1から2つの定期便を使用して島Nに向かうので、中継する島は一つだけ
//島 １ - 島 i 間を運行する定期便、島 i - 島 N 間を運行する定期便を調べて重複があるかどうかで判断

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> from_one;//島１ - 島 i 間で運行している定期便
    vector<int> to_N;//島 i - 島N間で運行している定期便
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;//制約:ai < bi
        if(a == 1 && b != N)from_one.push_back(b);//a = 1 のとき
        if(a != 1 && b == N)to_N.push_back(a);//b = N のとき
        //島 1 から島 N へダイレクトに向かう定期便は考えない
    }
    
    set<int> jdg;//二つの配列の重複を調べる
    bool ans = false;//重複があればtrue, なければfalse
    for(int i = 0; i < from_one.size(); i++)jdg.insert(from_one.at(i));//島１から出発する定期便を格納する
    for(int i = 0; i < to_N.size(); i++){
        if(jdg.count(to_N.at(i))){//島Nへ向かう定期便と重複があればtrueにしてfor文を抜ける
            ans = true;
            break;
        }
    }

    if(ans)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 5748
#include <stdio.h>
#include <string.h>

int main()
{
    char s[100];
    int ret_scanf;

    // フォーマットに従って標準入力から入力
    ret_scanf = scanf("%s", &s[0]);
    if (ret_scanf == 0) return 0;
    // printf("number of count = %d \n", n);

    for (int i = 0; i < strlen(s); i++) {
    	if (i % 2 == 0) {
    		if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
    			printf("No");
    			return 0;
    		}
    	} else {
    		if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
    			printf("No");
    			return 0;
    		}
		}
    }
    printf("Yes");
    return 0;
}


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

using namespace std;

typedef complex<long long> point;
#define EPS 1e-11
#define X real()
#define Y imag()
#define angle(v)    (atan2((v).Y, (v).X))

int dcmp(const double &a, const double &b) {
    if (fabs(a - b) < EPS)
        return 0;
    return ((a > b) << 1) - 1;
}

int main() {
#ifndef ONLINE_JUDGE
//	freopen("output.out", "w", stdout);
//	freopen("input.in", "r", stdin);
#endif

    int n;
    scanf("%d", &n);
    vector<point> pts;
    vector<double> angles;
    vector<int> sorted;
    for (int i = 0; i < n; i++) {
        long long x, y;
        scanf("%lld %lld", &x, &y);
        pts.push_back(point(x, y));
        angles.push_back(angle(point(x, y)));
        sorted.push_back(i);
    }


    sort(sorted.begin(), sorted.end(), [&](int a, int b) {
        double a1 = (angles[a]), a2 = (angles[b]);
        int cp = dcmp(a1, a2);
        return cp < 0;
    });

    long long res = 0;
    for (int i = 0; i < n; i++) {
        long long dx = 0, dy = 0;
        for (int j = 0; j < n; j++) {
            dx += pts[sorted[(i + j) % n]].X;
            dy += pts[sorted[(i + j) % n]].Y;
            res = max(res, dx * dx + dy * dy);
        }
    }
    printf("%.20lf\n", sqrt(res));

    return 0;
}


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

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> v;
  int firstN,secondN;
  for(int i=0;i<n;i++){
    cin>>firstN;
    if(firstN==0){
      cin>>secondN;
      v.push_back(secondN);
    }else if(firstN==1){
      cin>>secondN;
      cout<<v[secondN]<<endl;
    }else{
      v.pop_back();
    }
  }
  return 0;
}



Measured memory_bytes: 3860
N,M,C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
    s = 0
    for j in range(M):
        s += A[i][j]*B[j]
    if s + C >0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
dp = [[float("inf") for j in range(H+1)] for i in range(N+1)]
for i in range(N):
    for j in range(H+1):
        if j <= A[i]:
            dp[i+1][j] = min(dp[i][j], B[i])
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i])
print(dp[N][H])

Measured memory_bytes: 300808
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define N 20
#define ll long long
using namespace std;
int d,n=0;
ll e[N],a[N],b[N],m,ans=0;
void dg(ll x,ll y,ll z)
{
	if(x>=m/2)
	{
		if(m%2==1) z*=10;
		if(y==d) ans+=z;
		return;
	}
	ll q=-9;
	while(q<=9&&y+q*(e[m-x-1]-e[x])<=d) q++;
	q--;
	dg(x+1,y+q*(e[m-x-1]-e[x]),z*b[q+10]-(x==0&&q>=0));
	q++;
	if(q>9) return;
	dg(x+1,y+q*(e[m-x-1]-e[x]),z*b[q+10]-(x==0&&q>=0));
}
int main()
{
	e[0]=1;fo(i,1,18) e[i]=e[i-1]*10;
	scanf("%d",&d);
	n=0;
	for(int a=d;a;a/=10) n++;
	fo(i,0,9) fo(j,0,9) b[i-j+10]++;
	for(m=1;m<=18;m++) dg(0,0,1);
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class a{
    public static void Main(){
        string str = Console.ReadLine();
        if(str[str.Length-1] == 's'){
            Console.WriteLine(str + "es");
        }
        else{
            Console.WriteLine(str + "s");
        }
    }
}


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

using namespace std;

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

    // 解説見たやり方（この問題の特性上，XY間を通るか否かで場合分けして最小か比較するのが簡単だった．あとgraphはそもそも不要でループ内で都度カウントしてあげるようにした）
    vector<int> result(N - 1);
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            ++result[min({j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j), abs(Y - 1 - i) + 1 + abs(X - 1 - j)}) - 1];
        }
    }
    for (auto r: result){
        cout << r << endl;
    }

    return 0;
}


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

void print(char c,int n){
	for(int i = 0;i < n;i++)
		cout << c;
}

int main() {
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx;
	int dy = ty - sy;
	
	print('R',dx);
	print('U',dy);
	
	print('R',1);
	print('D',dy+1);
	print('L',dx+1);
	print('U',1);
	
	print('U',dy);
	print('R',dx);
	
	print('U',1);
	print('L',dx+1);
	print('D',dy+1);
	print('R',1);
	
	return 0;
}

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

int main()
{
	long int a, b;
	
	cin >> a >> b;
	
	if ( a > 0 && b > 0 )
	{
		cout << "Positive" << endl;
	}
	else if ( a < 0 && b < 0 )
	{
		if ( (b - a) % 2 != 0 )
		{
			cout << "Positive" << endl;
		}
		else
		{
			cout << "Negative" << endl;
		}
	}
	else
	{
		cout << "Zero" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

const int maxN = 2e5 + 5;

vector<int> adj[maxN];
int vis[maxN];

void dfs(int v, int &c){
    vis[v] = 1;
    c++;
    for(auto u : adj[v]){
        if(vis[u] == 0){
            dfs(u, c);
        }
    }
}

void solve(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        vis[i] = 0;
    }
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int res = 0;
    for(int i = 1; i <= n; i++){
        if(vis[i] == 0){
            int c = 0;
            dfs(i, c);
            res = max(res, c);
        }
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 24712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll n;
    cin>>n;
    ll dp[n]={0};
    dp[0]=2;
    dp[1]=1;
    for(ll i=2;i<=n;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int h,w,cnt[26] = {},one = 0,two = 0;
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		string s;
		cin >> s;
		for(int j = 0;j < w;j++) cnt[s[j] - 'a']++;
	}
	for(int i = 0;i < 26;i++){
		if(cnt[i] % 2) one++;
		if(cnt[i] % 4 >= 2) two++;
	}
	if(h % 2 == 0 && w % 2 == 0){
		if(one || two) No();
		else Yes();
	}else if(h % 2 && w % 2){
		if(one >= 2 || two > h / 2 + w / 2) No();
		else Yes();
	}else{
		if(h % 2) swap(h,w);
		if(one || two > h / 2) No();
		else Yes();
	}
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

ll dp[60][3];
bool p[60];

inline void add(ll &x, ll y)
{
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
	ll N;
	cin >> N;
	rep(i, 60) p[59-i] = (N >> i) & 1;

	dp[0][0] = 1;

	rep(i, 60) {
		rep(j, 3) {
			add(dp[i+1][2], dp[i][2]);
		}

		rep(j, 2) if (dp[i][j] > 0) {
			rep(k, 3) {
				int nj = min(j * 2 + p[i] - k, 2);
				if (nj < 0) continue;
				add(dp[i+1][nj], dp[i][j]);
			}
		}
	}

	cout << (dp[60][0] + dp[60][1] + dp[60][2]) % MOD << endl;

	return 0;
}

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

using namespace std;

int main()
{
	int N,M;
	
	cin >> N;
	
	if(N%2 == 1) M = (N*(N-1)/2) - ((N-1)/2);
	else M = N*(N-1)/2 - N/2;
	cout << M << endl;
	
	if(N%2 == 0){
		for(int i=1;i<N;i++){
			for(int j=i+1;j<N+1;j++){
				if(i+j != N+1) cout << i << ' ' << j << endl;
			}
		}
	}else{
		for(int i=1;i<N;i++){
			for(int j=i+1;j<N+1;j++){
				if(i+j != N) cout << i << ' '<< j << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
vector<vi> edge;
vi value;
void dfs(int u, int p){
    if(p != -1) value[u] += value[p];
    for(auto v : edge[u]){
        if(v == p) continue;
        dfs(v, u);
    }
}
int main(){
    int n, q;
    cin >> n >> q;
    edge.resize(n+1, vi());
    for(int i = 1; i < n ;i++){
        int a, b;
        cin >> a >> b;
        edge[a].pb(b);
        edge[b].pb(a);
    }
    value.resize(n+1, 0);
    while(q--){
        int idx, val;
        cin >> idx >> val;
        value[idx] += val;
    }
    dfs(1, -1);
    for(int i = 1; i <= n; i++) cout << value[i] << " ";
}

Measured memory_bytes: 23424
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

#include <vector>
#include <stack> // s.top()
#include <queue> // s.front()
using namespace std;
typedef long long llong;

#define INFTY 100010

typedef pair<llong, llong> P;

bool pairComp(const P& firstElof, const P& secondElof) {
	return firstElof.second > secondElof.second;
}

int main() {
	int N, M;
	vector<int> X;

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int ipt;
		cin >> ipt;
		X.push_back(ipt);
	}
	sort(X.begin(), X.end());

	vector<int> gapx;
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}
	

	for (int i = 1; i < M; i++) {
		gapx.push_back(X[i] - X[i - 1]);
		
	}

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

	for (int i = 0; i < N; i++) {
		if (i == 0)continue;
		gapx.pop_back();
	}

	llong ans = 0;

	for (int i = 0; i < gapx.size(); i++) {
		ans += gapx[i];
	}

	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 10;

int rui[3][4005];
int rev_rui[3][4005];

int N;
string S;

signed main()
{
	cin>>N>>S;
	S=' '+S;
	for (int i=1;i<=N;++i) {
		rep(j, 3) {
			rui[j][i] = rui[j][i-1];
		}
		if (S[i]=='R')rui[0][i]++;
		if (S[i]=='G')rui[1][i]++;
		if (S[i]=='B')rui[2][i]++;
	}
	for (int i=N;i>=1;--i) {
		rep(j, 3) {
			rev_rui[j][i] = rev_rui[j][i+1];
		}
		if (S[i]=='R')rev_rui[0][i]++;
		if (S[i]=='G')rev_rui[1][i]++;
		if (S[i]=='B')rev_rui[2][i]++;
	}

	int ans = 0;

	for (int i = 2; i <= N - 1; ++i) {
		if (S[i] == 'R') {
			for (int diff = 1; i + diff <= N; ++diff) {
				if (S[i + diff] == 'G') {
					int B = rui[2][i - 1];
					if (i - diff >= 0) B -= rui[2][i - diff];
					if (i - diff - 1 >= 0) B += rui[2][i - diff - 1];
					ans += B;
				}
				if (S[i + diff] == 'B') {
					int G = rui[1][i - 1];
					if (i - diff >= 0) G -= rui[1][i - diff];
					if (i - diff - 1 >= 0) G += rui[1][i - diff - 1];
					ans += G;
				}
			}
		}
		if (S[i] == 'G') {
			for (int diff = 1; i + diff <= N; ++diff) {
				if (S[i + diff] == 'R') {
					int B = rui[2][i - 1];
					if (i - diff >= 0) B -= rui[2][i - diff];
					if (i - diff - 1 >= 0) B += rui[2][i - diff - 1];
					ans += B;
				}
				if (S[i + diff] == 'B') {
					int R = rui[0][i - 1];
					if (i - diff >= 0) R -= rui[0][i - diff];
					if (i - diff - 1 >= 0) R += rui[0][i - diff - 1];
					ans += R;
				}
			}
		}
		if (S[i] == 'B') {
			for (int diff = 1; i + diff <= N; ++diff) {
				if (S[i + diff] == 'R') {
					int G = rui[1][i - 1];
					if (i - diff >= 0) G-= rui[1][i - diff];
					if (i - diff - 1 >= 0) G+= rui[1][i - diff - 1];
					ans += G;
				}
				if (S[i + diff] == 'G') {
					int R = rui[0][i - 1];
					if (i - diff >= 0) R -= rui[0][i - diff];
					if (i - diff - 1 >= 0) R += rui[0][i - diff - 1];
					ans += R;
				}
			}
		}
	}

	cout << ans << endl;
}




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

int main(){
    int N,**A,i,j,tmp,maxim;
    cin >> N;
    A = new int*[2];
    for(i=0;i<2;i++){
        A[i] = new int[N];
    }
    for(j=0;j<N;j++){
        cin >> A[0][j];
    }
    tmp = A[0][0];
    for(j=0;j<N;j++){
        cin >> A[1][j];
        tmp += A[1][j];
    }
    maxim = tmp;
    for(i=1;i<N;i++){
        tmp += A[0][i];
        tmp -= A[1][i-1];
        maxim = max(tmp,maxim);
    }
    cout << maxim << endl;
    return 0;
}

Measured memory_bytes: 384
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"9 4
" => r"Possible",

r"100 100
" => r"Impossible"
}

use std::cmp;
use std::cmp::{max, min};
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i32,
        b: i32,
    }

    if (a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0 {
        "Possible".to_string()
    } else {
        "Impossible".to_string()
    }
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> myds;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define F first
#define S second
#define vec(x) vector<x> 
#define pi(x,y) pair<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repd(i,x,y,k) for(int i=x;i<y;i+=k)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define rev(x) reverse(all(x))
#define uniq(x) x.resize(distance(x.begin(),unique(all(x))))
#define full(x,a) memset(x,a,sizeof(x))
#define lcm(x,y) ((x*y)/__gcd(x,y))
#define mod 1000000007
#define bitcount __builtin_popcountll
#define pb push_back
#define indexof order_of_key
#define valueat find_by_order

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

int gcdextended(int a,int b,int &x,int &y){if(!a){x=0,y=1;return b;}int x1,y1;int ans=gcdextended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return ans;}
int inv(int a){int x,y;int ans=gcdextended(a,mod,x,y);return(x%mod+mod)%mod;}
int nCr(int n,int k){int res=1;k=(k>n-k)?n-k:k;rep(i,0,k){res*=(n-i);res/=(i+1);}return res;}
int POW(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res%mod*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
//void seive(){prime[0]=0;prime[1]=0;rep(i,2,10002)prime[i]=1;for(int i=2;i*i<=10000;i++){if(prime[i]){for(int j=i*i;j<=10000;j+=i)prime[j]=0;}}} 

int x;

void input(){
	cin>>x;
}

void solve(){
	int ans=(x/500)*1000;
	int n=x-(x/500)*500;
	ans+=(n/5)*5;
	cout<<ans<<endl;
}

main(){
	fastio;
	int t=1;
	while(t--){
		input();
		solve();
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
using namespace std;
int N,K,f11[100],f12[100],f13[100],f21[100],f22[100],f23[100],f31[100],f32[100],f33[100];
int d[100]={};
int main()
{
	cin>>N>>K;
	for(int i=0;i<K;i++){
		int a,b;cin>>a>>b;
		d[a]=b;
	}
	f11[2]=f12[2]=f13[2]=f21[2]=f22[2]=f23[2]=f31[2]=f32[2]=f33[2]=0;
	if(d[1]==0){
		if(d[2]==0)f11[2]=f12[2]=f13[2]=f21[2]=f22[2]=f23[2]=f31[2]=f32[2]=f33[2]=1;
		else if(d[2]==1)f11[2]=f21[2]=f31[2]=1;
		else if(d[2]==2)f12[2]=f22[2]=f32[2]=1;
		else if(d[2]==3)f13[2]=f23[2]=f33[2]=1;
	}else if(d[1]=1){
		if(d[2]==0)f11[2]=f12[2]=f13[2]=1;
		else if(d[2]==1)f11[2]=1;
		else if(d[2]==2)f12[2]=1;
		else if(d[2]==3)f13[2]=1;
	}else if(d[1]=2){
		if(d[2]==0)f21[2]=f22[2]=f23[2]=1;
		else if(d[2]==1)f21[2]=1;
		else if(d[2]==2)f22[2]=1;
		else if(d[2]==3)f23[2]=1;
	}else if(d[1]=3){
		if(d[2]==0)f31[2]=f32[2]=f33[2]=1;
		else if(d[2]==1)f31[2]=1;
		else if(d[2]==2)f32[2]=1;
		else if(d[2]==3)f33[2]=1;
	}
	for(int i=3;i<=N;i++){
		f11[i]=(f21[i-1]+f31[i-1])%10000;
		f22[i]=(f12[i-1]+f32[i-1])%10000;
		f33[i]=(f13[i-1]+f23[i-1])%10000;
		f12[i]=(f11[i-1]+f21[i-1]+f31[i-1])%10000;
		f13[i]=(f11[i-1]+f21[i-1]+f31[i-1])%10000;
		f21[i]=(f12[i-1]+f22[i-1]+f32[i-1])%10000;
		f23[i]=(f12[i-1]+f22[i-1]+f32[i-1])%10000;
		f31[i]=(f13[i-1]+f23[i-1]+f33[i-1])%10000;
		f32[i]=(f13[i-1]+f23[i-1]+f33[i-1])%10000;
		if(d[i]==1)f12[i]=f13[i]=f22[i]=f23[i]=f32[i]=f33[i]=0;
		else if(d[i]==2)f11[i]=f13[i]=f21[i]=f23[i]=f31[i]=f33[i]=0;
		else if(d[i]==3)f11[i]=f12[i]=f21[i]=f22[i]=f31[i]=f32[i]=0;
	}
	cout<<(f11[N]+f12[N]+f13[N]+f21[N]+f22[N]+f23[N]+f31[N]+f32[N]+f33[N])%10000<<endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
char grid[55][55];
int n,m;
int main(){
	cin>>n>>m;
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>grid[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(grid[i][j]=='#'){
				bool flag=false;
				for(int k=0;k<4;k++){
					int ax=i+dx[k];
					int ay=j+dy[k];
					if(ax>=0&&ax<n&&ay>=0&&ay<m&&grid[ax][ay]=='#')flag=true;
				}
				if(!flag){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	march := make(map[string]int)
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Scan(&tmp)

		if tmp[0] == 'M' || tmp[0] == 'A' || tmp[0] == 'R' || tmp[0] == 'C' || tmp[0] == 'H' {
			march[string(tmp[0])]++
		}
	}

	var ans int
	ans += march["M"] * march["A"] * march["R"]
	ans += march["M"] * march["A"] * march["C"]
	ans += march["M"] * march["A"] * march["H"]
	ans += march["M"] * march["R"] * march["C"]
	ans += march["M"] * march["R"] * march["H"]
	ans += march["M"] * march["C"] * march["H"]
	ans += march["A"] * march["R"] * march["C"]
	ans += march["A"] * march["R"] * march["H"]
	ans += march["A"] * march["C"] * march["H"]
	ans += march["R"] * march["C"] * march["H"]

	fmt.Println(ans)
}


Measured memory_bytes: 5504
import sys
#input = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
N = int(input())
GA = inpl()
GB = inpl()

typ = [GA[i] <= GB[i] for i in range(3)]

if sum(typ) == 3:
    ans = 0
    for g in range(N//GA[0] + 1):
        D = N - GA[0]*g
        for s in range(D//GA[1] + 1):
            b, D2 = divmod(D - GA[1]*s, GA[2])
            ans = max(ans, D2 + g*GB[0] + s*GB[1] + b*GB[2])

elif sum(typ) == 2:
    ans = 0
    x, y = [i for i in range(3) if typ[i]]
    z = [i for i in range(3) if not typ[i]][0]
    for a in range(N//GA[x] + 1):
        b, D = divmod(N - GA[x]*a, GA[y])
        c, D2 = divmod(D + GB[x]*a + GB[y]*b, GB[z])
        ans = max(ans, D2 + c*GA[z])

elif sum(typ) == 1:
    ans = 0
    x, y = [i for i in range(3) if not typ[i]]
    z = [i for i in range(3) if typ[i]][0]
    c, D = divmod(N, GA[z])
    D += GB[z]*c

    for a in range(D//GB[x] + 1):
        b, D2 = divmod(D-GB[x]*a, GB[y])
        ans = max(ans, D2 + GA[x]*a + GA[y]*b)


else:
    ans = 0
    for g in range(N//GB[0] + 1):
        D = N - GB[0]*g
        for s in range(D//GB[1] + 1):
            b, D2 = divmod(D - GB[1]*s, GB[2])
            ans = max(ans, D2 + g*GA[0] + s*GA[1] + b*GA[2])

print(ans)

Measured memory_bytes: 42204
#include <bits/stdc++.h>
using namespace std;
#define oo 666666666
#define ll long long
#define ld long double

ll H[200001];
ll A[200001];
ll BIT[200001];
int n;

void Add(int c, ll x)
{
    for(c;c<=n;c+=c&-c)
        BIT[c]=max(BIT[c],x);
}

ll Get(int c, ll s=0)
{
    for(;c;c-=c&-c)
        s=max(BIT[c],s);
    return s;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>H[i];
    for(int i=1; i<=n; i++)
        cin>>A[i];

    vector<array<int,2>>S;
    for(int i=1; i<=n; i++)
    S.push_back({H[i],i});

    sort(S.begin(),S.end());
    ll ats = 0;

    for(int i=1; i<=n; i++)
    {
        int idx = S[i-1][1];
        Add(idx,Get(idx-1) + A[idx]);
        ats=max(ats,Get(idx));
    }
    cout<<ats;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    string S;
    cin >> S;

    ll N = S.length();
    string ss="";

    for(ll i= N-1; i>=0; i--){
        ss+=S[i];
        if(ss=="maerd") ss="";
        else if(ss=="remaerd") ss="";
        else if(ss=="esare") ss="";
        else if(ss=="resare") ss="";
    }
    if(ss=="") cout<<"YES"<< endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
N = int(input())
coords = []
status = "Yes"
for i in range(N):
    coords.append(list(map(int, input().split())))

x = 0
y = 0
for coord in coords:
  summy = abs(x-coord[1]) + abs(y - coord[2])
  parity = (coord[1] + coord[2]) % 2
  if summy > coord[0] or parity != coord[0] % 2:
    status = "No"
    break
  else:
    pass
  x = coord[1]
  y = coord[2]
print(status)

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

const int mnx = 1e6 + 9;
const int mod =  1e9 + 7;

ll ans;
string s;
map<char, int> q;

int main(){

cin >> s;

for(int i = 0; i < s.size(); i++){
    ans += i - q[s[i]]; q[s[i]]++;
}

cout << ans + 1 << '\n';



return 0;

}














Measured memory_bytes: 640
from collections import Counter
s = [a for a in str(input())]
ss = dict((Counter(s)))
abc = ["a","b","c"]
check = True
try:
  for i in abc:
    if ss[i] < (len(s) // 3) or ss[i] > (len(s) // 3 + 1):
      check = False
except:
  if max(ss.values()) >= 2:
    check = False
print("YES" if check else "NO")

Measured memory_bytes: 10040
#include<stdio.h>

#define nMIN 2
#define nMAX 200000
#define RtMIN 1
#define RtMAX 1000000000


int main(){
int n[nMAX],Time,i,max=0,sub;

scanf("%d",&Time);
if(nMIN<=Time&&Time<=nMAX){
for(i=0;i<Time;i++){
scanf("%d",&n[i]);
if(RtMIN>n[i]||n[i]>RtMAX)exit(1);
}
max=n[i-1];
sub=n[i-1]-n[i-2];
for(i=Time-2;i>=0;i--){

if(max<n[i]&&i!=0){
max=n[i];
}
if(sub<max-n[i]&&n[i]!=max){
sub=max-n[i];
}
}
}
 else exit(1);

printf("%d\n",sub);
return 0;
}



Measured memory_bytes: 2632
// Aizu Vol-2 0229: Big Hit !
// 2017.8.20 bal4u@uu

#include <stdio.h>

int main()
{
	int b, r, g, c, s, t;
	int ans;

	while (scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t) == 6 && (b|r|g|c|s|t)) {
		ans = 100;
		ans += 15*b+(15-2)*5*b, t -= 5*b;
		ans += 15*r+(15-2)*3*r, t -= 3*r;
		ans += 7*g;
		ans += 2*c;
		t -= s;
		ans -= 3*t;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N,K;cin>>N>>K;
  int num=1;
  for(int i=0;i<N;i++){
    num =min(num*2,num+K);
  }
  cout<<num<<endl;
  
  
}







Measured memory_bytes: 256
/*
AizuOnline A0128
Abacus
*/
#include <stdio.h>
#include <string.h>
#define DEBUG 0

void zero_unsupress(char * x)
{   int i,len;
  while(len=strlen(x),len < 5)
    {
      x[len+1]='\0';
      for(i=len;i>0;i--)
        x[i]=x[i-1];
      x[0]='0';
    }
}

void display_soroban(char * digits)
{
  int i,j;
  
/*LINE 0*/
  for(i=0;i<5;i++)
    {
      printf("%c",(digits[i]<'5')?'*':' ');
    }
      printf("\n");
/*LINE 1*/
  for(i=0;i<5;i++)
        printf("%c",(digits[i]>'4')?'*':' ');
  printf("\n");
  /*LINE 3~7*/
  printf("=====\n");
  for(j=0;j<5;j++)
    {
      for(i=0;i<5;i++)
        printf("%c",(((digits[i]-'0') % 5) ==j)?' ':'*');
      printf("\n");
    }
}

main()
{

char number[6];
int  flag = 0;
  
  while(EOF != scanf("%s",number))
        {
          if(flag)
            printf("\n");
          else
            flag = 1;
        
          zero_unsupress(number);

#if DEBUG
printf("%s\n",number);
#endif
  
          display_soroban(number);
        }

return(0);
}

Measured memory_bytes: 0
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int a, b, k;

void input() {
  cin >> a >> b >> k;
}

void solve() {
  vector<int> K;
  loop(x,1,101) {
    if (a%x==0 and b%x==0) K.push_back(x);
  }
  reverse(K.begin(), K.end());
  cout << K[k-1] << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
using ll = long long;



int main(){
	int n, d, x, c, ans = 0;

	cin >> n;
	cin >> d >> x;

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

	for (int i = 0; i < n; i++) {
		c = (d - 1) / a[i] + 1;
		ans = ans + c;

	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    char c[3][3];
    ccin(i,j,c);
    rep(i,3){
        cout << c[i][i];
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
	int N,T,c[110],t[110],min=1000000;
	cin >> N >> T;
	for(int i=0; i<N; i++){
		cin >> c[i] >> t[i];
		if(t[i] <= T && c[i] < min)	min = c[i];
	}
	if(min == 1000000) cout << "TLE" << endl;
	else cout << min << endl;
	
	return 0;
}


Measured memory_bytes: 256