akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;

int main(void) {
	LL N, M;
	cin >> N >> M;

	vector<bool> can_move(100100,true);
	rep(i, M) {
		LL b_stair;
		cin >> b_stair;
		can_move[b_stair] = false;
	}

	vector<LL> dp(100100);
	dp[0] = 1;
	dp[1] = can_move[1] ? 1 : 0;
	for (LL i = 2; i <= N; i++) {
		if (can_move[i]) {
			dp[i] += dp[i - 1] + dp[i - 2];
			dp[i] %= MOD;
		}
	}

	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define max 500000
#define sentinel 2000000000

int L[max/2 + 2];
int R[max/2 + 2];
int count;



int merge(int A[], int n, int left, int mid, int right)  {
  int i, j, k, n1, n2;
  n1 = mid - left;
  n2 = right - mid;
  
  for (i = 0; i < n1; i++)
    L[i] = A[left+i];
  for (i = 0; i < n2; i++)
    R[i] = A[mid+i];
  
  L[n1] = R[n2] = sentinel;
  
  i = j = 0;
  for ( k = left; k < right; k++)  {
    count++;
    if ( L[i] <= R[j])  
      A[k] = L[i++];
    else 
      A[k] = R[j++];
  }
}

void mergeSort(int A[], int n, int left, int right)  {
  int mid;
  if (left + 1 < right)  {
    mid = (left+right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main(void)  {
  int A[max], n, i;
  count = 0;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++) 
    scanf("%d", &A[i]);
  
  mergeSort(A, n, 0, n);

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


 
  
  

Measured memory_bytes: 5696
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N  = sc.nextInt();
    int A  = sc.nextInt();
    int B  = sc.nextInt();
    int sum = 0;

    for (int i = 1; i <= N; i++) {
      int tmpSum = sum(i);
      sum = (A <= tmpSum && tmpSum <= B) ? sum + i : sum;
    }
    
    System.out.println(sum);
  }

  static int sum(int tmp) {
    int ret = 0;
    while (tmp > 0) {
      ret += tmp % 10;
      tmp = tmp / 10;
    }
    return ret;
  }
}


Measured memory_bytes: 21844
N = gets.to_i

if N == 0
  puts 0
else
  n = N
  ans = ''
  k = 0
  while n != 0
    if n.odd?
      ans += '1'
      n -= k.even? ? 1 : -1
    else
      ans += '0'
    end
    n /= 2
    k += 1
  end
  puts ans.reverse
end


Measured memory_bytes: 3836
/*{{{*/
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long ll;
typedef std::pair<int, int> pii;

std::string Name = __FILE__;
std::string iput = Name.substr(0, Name.length() - 4) + ".in";
std::string oput = Name.substr(0, Name.length() - 4) + ".out";

template <class T> inline bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template <class T> inline bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }

template <class T> inline T &read(T &x)
{
    static int f;
    static char c; 
    for (f = 1; !isdigit(c = getchar()); ) {
        if (c == '-')
            f = -1;
    }
    for (x = 0; isdigit(c); c = getchar()) {
        x = x * 10 + c - 48;
    }
    return x *= f;
}
 
template <class T> inline void write(T x, const char p = '\n')
{
    static int top;
    static int s[30];
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    do s[++ top] = x % 10 + 48;
    while (x /= 10);
    while (top)
        putchar(s[top --]);
    putchar(p);
}
/*}}}*/
 
const int maxn = 1e5 + 5;
 
int n;
int c;
int k;
int ans;
int a[maxn];


void exec()
{
    read(n), read(c), read(k);
    for (int i = 1; i <= n; ++ i) read(a[i]);
    std::sort(a + 1, a + n + 1);
    int p = 1;
    while (p <= n) {
        ++ ans;
        int tot = 1, pos = a[p] + k;
        ++ p;
        while (tot < c && p <= n && a[p] <= pos) ++ p, ++ tot;
    }
    write(ans);
}

/*{{{*/
int main() 
{
    if (fopen(iput.c_str(), "r") != NULL) {
        freopen(iput.c_str(), "r", stdin);
        freopen(oput.c_str(), "w", stdout);
    }

    exec();

    fclose(stdin);
    fclose(stdout);

    return 0;
}
/*}}}*/




Measured memory_bytes: 640
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B;
    cin >> A >> B;

    int res = 1;
    int counter = 0;
    while(res< B){
        res+=A-1;
        counter ++;
    }

    cout << counter << endl;

    return 0;
}


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

struct edge{
    int from, to, cost;
};

int main(){
    int n, m, p;
    cin >> n >> m >> p;
    vector<edge> v;
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        v.push_back(edge({--a, --b, -(c-p)}));
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = 0; j < m; j++){
            int from = v[j].from, to = v[j].to;
            if(dp[from] != INT_MAX && dp[from]+v[j].cost < dp[to]){
                dp[to] = dp[from]+v[j].cost;
            }
        }
    }
    bool valid = true;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int from = v[j].from, to = v[j].to;
            if(dp[from] != INT_MAX && dp[from]+v[j].cost < dp[to]){
                dp[to] = dp[from]+v[j].cost;
                if(to == n-1)   valid = false;
            }
        }
    }

    if(valid){
        cout << max(0, -dp[n-1]) << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

#約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
n=I()
ans=inf
for i in make_divisors(n):
    u=n//i
    val=max(len(str(u)),len(str(i)))
    ans=min(ans,val)
print(ans)

        
        
    
    
    
    
    
        


Measured memory_bytes: 3568
def gcd(x,y):
    p=max([x,y])
    q=min([x,y])
    if p%q==0:
        return q
    else:
        return gcd(q,p%q)

A, B, C = map(int, input().split())
if C%gcd(A,B)==0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
    int n, k, x, y, ans=0;
    scanf("%d %d %d %d", &n, &k, &x, &y);
    if(k>=n) ans+=n*x;
    else ans+=k*x+(n-k)*y;
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
/*  I'm a mess, I'm a loser                  */
/*  I'm a hater, I'm a user                  */
/*  I'm a mess for your love, it ain't new   */
/*  I'm obsessed, I'm embarrassed            */
/*  I don't trust no one around us           */
/*  I'm a mess for your love, it ain't new   */

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll mod=1000000007;

int divisors[10000009];
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);

for (ll i = 1; i <= 10000009; ++i)
 for (ll j = i; j <= 10000009; j += i)
  ++divisors[j];


ll t=1;
//cin>>t;
while(t--)
{

ll n;
cin>>n;
ll ans=0;
for(ll i=1;i<=n;i++)
ans+=(divisors[i]*i);

cout<<ans<<endl;

}
return 0;
}















Measured memory_bytes: 42700
import itertools
S = input()

p1 = itertools.cycle('01')
p2 = itertools.cycle('10')

ans1=0
ans2=0
for s,P1,P2 in zip(S,p1,p2):
  if s == P1:
    ans1 += 1
  if s == P2:
    ans2 += 1
print(min(ans1,ans2))
  

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string a,b,c;
	cin >> a >> b >> c;
	printf("%c%c%c\n", toupper(a[0]), toupper(b[0]), toupper(c[0]));
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 2500

signed main() {
    int n, m, s;
    cin >> n >> m >> s;
    using T = tuple <ll, ll, ll>;
    vector<T> G[n];
    int u, v, a, b;
    rep(i, m) {
        cin >> u >> v >> a >> b;
        u--;
        v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }
    ll c[n], d[n];
    rep(i, n) {
        cin >> c[i] >> d[i];
    }
    ll dist[n][MAX + 1];
    fill(dist[0], dist[n], LINF);
    priority_queue<T, vector<T>, greater<T>> que;
    for (int j = 0;; j++) {
        int nxt = min(s + c[0] * j, (ll)MAX);
        dist[0][nxt] = d[0] * j;
        que.emplace(dist[0][nxt], nxt, 0);
        if (s + c[0] * j > MAX) break;
    }
    while (!que.empty()) {
        T t = que.top();
        que.pop();
        int cnt = get<1>(t), v = get<2>(t);
        if (dist[v][cnt] < get<0>(t)) continue;
        for (int i = 0; i < G[v].size(); i++) {
            int to = get<0>(G[v][i]), need = get<1>(G[v][i]);
            ll cost = get<2>(G[v][i]);
            if (cnt - need < 0) continue;
            for (int j = 0;; j++) {
                int nxt = min(cnt - need + c[to] * j, (ll)MAX);
                if (dist[to][nxt] > dist[v][cnt] + cost + d[to] * j) {
                    dist[to][nxt] = dist[v][cnt] + cost + d[to] * j;
                    que.emplace(dist[to][nxt], nxt, to);
                }
                if (cnt - need + c[to] * j > MAX) break;
            }
        }
    }
    for (int v = 1; v < n; v++){
        ll ans = LINF;
        for (int j = 0; j <= MAX; j++) {
            ans = min(ans, dist[v][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    string a,b;
    cin>>a>>b;
    cout<<(a.size()>b.size()?"GREATER":a.size()<b.size()?"LESS":a>b?"GREATER":a<b?"LESS":"EQUAL")<<endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
ans=a*x+b*y
if x==y:
    ans=min(ans,2*x*c)
elif x>y:
    ans=min(ans,a*(x-y)+2*y*c)
    ans=min(ans,2*x*c)
else:
    ans=min(ans,b*(y-x)+2*x*c)
    ans=min(ans,2*y*c)
print(ans)

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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int flag = 334;
	if (n != 1) {
		for (int i = 1;i < n;i++) {
			if (s[i] != '9') {
				flag = 0;
				break;
			}
		}
	}
	if (n == 1)cout << s << endl;
	else if (flag)cout << s[0] - '0' + (n - 1) * 9 << endl;
	else cout << (n - 1) * 9 + s[0] - '1' << endl;
}

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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

bool IsPrime(ll num) {
  if (num==1) return false;
  if (num==2) return true;
  if (num%2==0) return false;
  int i=3;
  while (i<=sqrt(num)) {
    if (num%i==0) return false;
    i+=2;
  }
  return true;
}

int main() {
  int X; cin >>X;
  rep(i,X,pow(10,6)) {
    if (IsPrime(i)) {
      cout <<i <<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3676
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase
#include <ctime>    // clock

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    long long distance = abs(a-b);
    if(distance <= (v-w)*t) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    string s, t, ans="";
    cin >> n >> s >> t;
    rep(i, n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)

S_1 = S[0:int((N-1)/2)]
S_2 = S[int((N+3)/2-1):N+1]

print('Yes' if S[::-1] == S and S_1[::-1] == S_1 and S_2[::-1] == S_2 else 'No')



Measured memory_bytes: 9040
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int main() {
	llong x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	llong p[100005];
	llong q[100005];
	llong r[100005];
	rep( i, a )
		cin >> p[i];
	rep( i, b )
		cin >> q[i];
	rep( i, c )
		cin >> r[i];

	std::sort( p, p + a, std::greater<llong>() );
	std::sort( q, q + b, std::greater<llong>() );
	std::sort( r, r + c );

	llong it_a = x-1;
	llong it_b = y-1;
	llong it_c = c-1;

	while( 1 )
	{
		if( c == -1 )
			break;
		if( it_a == -1 && it_b == -1 )
			break;
		if( it_a == -1 )
			it_a++;
		if( it_b == -1 )
			it_b++;

		llong& _a = p[it_a];
		llong& _b = q[it_b];
		llong& _c = r[it_c];

		if( _c <= _b && _c <= _a )
		{
			break;
		}
		if( _c <= _b )
		{
			_a = _c;
			it_a--;
			it_c--;
			continue;
		}
		if( _c <= _a )
		{
			_b = _c;
			it_b--;
			it_c--;
			continue;
		}
		if( _b < _a )
		{
			_b = _c;
			it_b--;
			it_c--;
			continue;
		}
		if( _b >= _a )
		{
			_a = _c;
			it_a--;
			it_c--;
			continue;
		}
	}

	llong ans = 0;
	for( llong i = 0; i < x; ++i )
		ans += p[i];
	for( llong i = 0; i < y; ++i )
		ans += q[i];

	cout << ans;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
	int a, b, d, r;
	double f;

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

	d = a / b;
	r = a%b;
	f = (double)a / b;

	printf("%d %d %f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 636
use std::io::stdin;

fn main() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut array = String::new();
    stdin().read_line(&mut array).unwrap();
    let array: Vec<u8> = array.split_whitespace().flat_map(str::parse).collect();
    let mut boxes = [0; 200002];

    let mut result = vec![];
    for (i, &a) in array.iter().enumerate().rev() {
        let mut total = 0;
        let mut j = i + 1;
        while j <= n {
            total += boxes[j];
            j += i + 1;
        }
        if total % 2 != a {
            boxes[i + 1] += 1;
            result.push(format!("{}", i + 1));
        }
    }

    println!("{}", result.len());
    println!("{}", result.join(" "));
}


Measured memory_bytes: 11384
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define Sort(a) sort((a).begin(),(a).end())
#define Reverse(a) reverse((a).begin(),(a).end())
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;
void Debug(auto a);

signed main(){
    int n,k;
    cin >> n >> k;
    n--;
    k--;
    if(n%k==0){
        cout << n/k << endl;
    }
    else{
        cout << (n/k)+1 << endl;
    }

    return 0;
}
void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i % 2 == 0 && a[i] % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除)
using A = vector<vector<long long>>;
using Q = priority_queue<long long>; //erase  (でキーごと削除)
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define inf 1000000000000000000+10

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}


class itertools{
public:

    vector<vector<long long>> ary;
    vector<long long> lis;
    vector<long long> tmp;

    void repeating (vector<long long> nums ,vector<long long> lis ,long long repeat){
        if (lis.size()==repeat){
            ary.push_back(lis);
        }else{
            tmp=lis;
            for (auto item:nums){
                tmp.push_back(item);
                repeating(nums,tmp,repeat);
                tmp=lis;
            }
        }
    }

    vector<vector<long long>> product(vector<long long> nums,long long repeat){
        repeating(nums,lis,repeat);
        return ary;
    };
};

int main(){
    long long n,a,b,c;
    cin>>n>>a>>b>>c;
    vector<long long> obj={a,b,c};
    vector<long long> l(n,0);
    for(long long i=0  ;i<n  ;i++){
        cin>>l[i];
    }
    itertools i;
    A out=i.product(L {0,1,2,3},n);
//    print(out); //3を捨てる
    
    long long ans=inf;
    for(auto x:out){
        long long tmp=0;
        A take(3);
        for (long long i=0; i<x.size(); i++){
            if (x[i]!=3){
                take[x[i]].push_back(l[i]);
            }
        }
        if (take[0].size()==0 or take[1].size()==0 or take[2].size()==0){
            continue;
        }
        for(long long i=0  ;i<3  ;i++){
            tmp+=(take[i].size()-1)*10;
            tmp+=abs(obj[i]-vsum(take[i]));
        }
        ans=min(tmp,ans);
    }
    print(ans);
}


Measured memory_bytes: 13620
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n,k;
int h[200010];
int main(){
  	LL sum = 0;
  	cin>>n>>k;
  	if (k >= n){
     	cout<<0<<endl;
    }else{
      	for (int i=1;i<=n;i++) cin>>h[i];
      	sort(h+1,h+1+n);
      	for (int i=1;i<=n-k;i++){
        	sum += h[i];
        }
      	cout<<sum<<endl;
    }
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    string s;
    cin>>s;
    if(s[0] >= 'a' && s[0] <= 'z')cout<<'a'<<endl;
    else cout<<'A'<<endl;
    
    return 0;
}


Measured memory_bytes: 3648
// template version 1.8

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}
int gcd(int a, int b){
  if (b>a) swap(a,b);
  if (b==0) return a;
  return gcd(b, a%b);
}

int solve(){
  int n;cin>>n;
  vector<int> a(n);
  int g = a[0];
  rep(i, n) {
    cin>>a[i];
    g = gcd(g, a[i]);
  }
  vi l(n, 0);
  l[0] = a[0];
  rep(i, 1, n){
    l[i] = gcd(l[i-1], a[i]);
  }
  dump(l);

  vi r(n, 0);
  r[n-1] = a[n-1];
  rrep(i, 0, n-1){
    r[i] = gcd(r[i+1], a[i]);
  }
  dump(r);

  int res=1;
  chmax(res, r[1]);
  chmax(res, l[n-2]);
  rep(i, 1, n-1){
    chmax(res, gcd(l[i-1],r[i+1]));
  }
  cout << res << endl;
  
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   int n;
   cin >> n;
   ll sum=0;
   rep(i,1,n){
       if(i%5==0||i%3==0) continue;
       sum+=i;
   }
   cout << sum;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int D, N;
	scanf("%d %d", &D, &N);
	if (D == 0 && N == 100) return !printf("101");
	else if (D == 1 && N == 100) return !printf("10100");
	else if (D == 2 && N == 100) return !printf("1010000");
	else printf("%d", (int)pow(100, D) * N);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

ll n, k;
vector<ll> a;

bool is_ok(ll x){
    ll cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] % x != 0){
            cnt += (a[i] / x);
        }
        else if(a[i] % x == 0){
            cnt += (a[i] / x) - 1;
        }
    }
    if(cnt <= k) return true;
    else return false;
}

int main(void){
    cin >> n >> k;
    a.resize(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    ll ok = 1000000010;
    ll ng = 0;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        if(is_ok(mid)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    if(k != 0) cout << ok << endl;
    else{
        ll ans = 0;
        for(int i = 0; i < n; i++){
            ans = max(ans, a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4780
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,d[300001],flg,i,cntm;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&d[i]);
	}
	cntm=d[1]/10;
	flg=0;
	for(i=1;i<n;i++){
		cntm=max(cntm,d[i]/10);
		if(cntm<=0){
			flg=1;
			break;
		}
		cntm--;
	}
	if(flg==1){
		printf("no\n");
	}
	else{
		for(i=n;i>1;i--){
			cntm=max(cntm,d[i]/10);
			if(cntm<=0){
				flg=1;
				break;
			}
			cntm--;
		}
		if(flg==1){
			printf("no\n");
		}
		else{
			printf("yes\n");
		}
	}
	return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define ll long long int
#define PI 3.14159265358979323846
#define ed "\n"
#define sp " "
#define f(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
using namespace std;

void solve()
{
 ll n;
 cin>>n;
 map<string,ll> m;
 f(i,0,n)
 {
   string s;
   cin>>s;
   m[s]++;
 }
 cout<<"AC x "<<m["AC"]<<ed;
 cout<<"WA x "<<m["WA"]<<ed;
 cout<<"TLE x "<<m["TLE"]<<ed;
 cout<<"RE x "<<m["RE"]<<ed;
}
 
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);
    #endif
  ll t=1;
//  cin>>t;
  while(t--)
  {
    solve();
  }
return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define write_to_file() freopen("output.txt" , "w" , stdout)
#define read_from_file() freopen("input.txt" , "r" , stdin)
#define GeoOutputFix(VV) cout<<fixed<<setprecision(VV)
#define MAX_V  1e9
#define MIN_V -1e9
template<class T>istream& operator>> (istream& is, complex<T>& p){T value;is >> value, p.real(value), is >> value, p.imag(value);return is;}
typedef long long lld;
typedef pair<lld, lld> dd;
typedef complex<double> point;
#define X real()
#define Y imag()
#define dist(a , b) sqrt(pow(a.X - b.X , 2) + pow(a.Y- b.Y , 2))
#define dist2(a , b) ((long double)hypot(a , b))
#define mid(a,b) (((a)+(b))/point(2,0))
#define compare(a , b) (fabs(a.X - b.X) < -1e9 && fabs(a.Y - b.Y) < -1e9)
#define all(c) c.begin() , c.end()
#define MOD (lld)(1e9+7)
#define EPS 1e-9
#define neighbours(u , e , v) for(int e = head[u] , v ; v = to[e] , ~e ; e = nxt[e])
#define watch1(x) cout<<(#x)<<" = "<<x<<"\n"
#define watch2(x , y) cout<<(#x)<<" = "<<x<<"  "<<(#y)<<" = "<<(y)<<"\n"
#define watch3(x , y , z) cout<<(#x)<<" = "<<x<<"  "<<(#y)<<" = "<<(y)<"  "<<(#z)<<" = "<<(z)<<"\n"
int dr[] = {1 , 1 , 1 , 0 , 0 , -1 , -1 , -1};
int dc[] = {-1 , 0 , 1 , -1 , 1 , -1 , 0 , 1};
int ddr[] = {1 , 0 , 0 , -1};
int ddc[] = {0 , -1 , 1 , 0};
inline int SD(){int i ;scanf("%d", &i);return i;}
inline lld SLL(){lld i;scanf("%lld", &i);return i;}
inline char SC(){char i;scanf(" %c", &i);return i;}
const int AKA = 1e6 + 6 , OO = 0x3f3f3f3f;
//----------------------------------------[TO_OO]--[To infinity and beyond]--------------------------------------------------------
int a[AKA];
int main()
{
    int n = SD(), m = SD();
    int i = 0 , cnt = 1;
    while(cnt + 1 < m)
        ++i , cnt = i * (n - 1);
    printf("%d" , i);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int N_MAX=50;
int main()
{
  int h,w,i,j;
  string s[N_MAX];
  cin >> h >> w;
  for(i=0;i<h;i++)
    cin >> s[i];
  for(i=0;i<h;i++)
    for(j=0;j<w;j++)
      if(s[i][j]=='#'
         &&(i==0||s[i-1][j]=='.')&&(i==h-1||s[i+1][j]=='.')
         &&(j==0||s[i][j-1]=='.')&&(j==w-1||s[i][j+1]=='.')){
        cout << "No" << endl;
        return 0;
      }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, t;
	cin>>n>>t;
	vector<int> arr;
	for(int i =0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
	}
	long long sum = 0;
	for(int i =0;i<arr.size();i++)
	{
		if(i + 1 == arr.size())
			sum+=t;
		else
		{
			int diff = arr[i + 1] - arr[i];
			if(diff >= t)
				sum += t;
			else
				sum += diff;
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int idx[n - 1];
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    idx[tmp - 1] = i;
  }
  multiset <int> s;
  s.insert(-1);
  s.insert(-1);
  s.insert(n);
  s.insert(n);
  s.insert(idx[n - 1]);
  long long int ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    auto itr = s.upper_bound(idx[i]);
    long long int r1 = *itr;
    itr++;
    long long int r2 = *itr;
    itr--;
    itr--;
    long long int l1 = *itr;
    itr--;
    long long int l2 = *itr;
    ans += (i + 1) * ((l1 - l2) * (r1 - idx[i]) + (idx[i] - l1) * (r2 - r1));
    s.insert(idx[i]);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 5376
use std::io;

macro_rules! read {
    () => {
        {
            let mut line = String::new();
            io::stdin().read_line(&mut line).unwrap();
            line
        }
    };
}

fn split(s: &String) -> std::str::SplitWhitespace {
    s.trim().split_whitespace()
}

fn main() {
    let mut line = read!();
    let mut line = split(&mut line);
    let H: u32 = line.next().unwrap().parse().unwrap();
    let W: u32 = line.next().unwrap().parse().unwrap();
    
    let mut line = read!();
    let mut line = split(&mut line);
    let h: u32 = line.next().unwrap().parse().unwrap();
    let w: u32 = line.next().unwrap().parse().unwrap();

    println!("{}", (H - h)*(W - w));
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
int main(void){
	char t[10];
	string s,s1,s2,s3;
	while(getline(cin,s1)){
		if(s1=="0") break;
		getline(cin,s2);
		getline(cin,s3);
		s=s1+s2+s3;
		for(int i=0;i<9;++i) t[i]=s[i];
		bool o[10],x[10];
		int i;
		for(i=0;i<9;++i){
			o[i]=(t[i]=='b')?true:false;
			x[i]=(t[i]=='w')?true:false;
		}
		int ans = 2;
		for(i=0;i<3;++i){
			if(o[i*3]&&o[i*3+1]&&o[i*3+2]||o[i]&&o[3*1+i]&&o[3*2+i]) ans=0;
			if(x[i*3]&&x[i*3+1]&&x[i*3+2]||x[i]&&x[3*1+i]&&x[3*2+i]) ans=1;
		}
		if(o[0]&&o[4]&&o[8]||o[2]&&o[4]&&o[6]) ans=0;
		if(x[0]&&x[4]&&x[8]||x[2]&&x[4]&&x[6]) ans=1;
		cout<<((ans<2)?((ans)?"w":"b"):"NA")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>

int main(){
  int n, k, lose[1000][2], i, j, a, b;
  int answer;

  scanf("%d",&n);
  scanf("%d",&k);
  for(i = 0 ; i < k ; i++){
    for(j = 0 ; j < 2 ; j++){
      scanf("%d",&lose[i][j]);
    }
  }
  for(i = 0 ; i < k ; i++){
    if(n%2 == 0){
      if(n/2 < lose[i][0])
	a = n - lose[i][0]+1;
      else a = lose[i][0];
      if(n/2 < lose[i][1])
	b = n - lose[i][1]+1;
      else b = lose[i][1];
    }
    else if(n%2 == 1){
      if(n+1/2 < lose[i][0])
	a = n - lose[i][0]+1;
      else a = lose[i][0];
      if(n+1/2 < lose[i][1])
	b = n - lose[i][1]+1;
      else b = lose[i][1];
    }
    if(a < b){
      answer = a % 3;
      if(answer == 0)
	answer = 3;
    }
    else if(a > b){
      answer = b % 3;
      if(answer == 0)
	answer = 3;
    }
    else {
      answer = a % 3;
      if(answer == 0)
	answer = 3;
    }
    printf("%d\n",answer);
  }
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int n;cin>>n;
    if(n==3){
        cout<<"2 5 63"<<endl;return 0;
    }
    queue<int> q2,q3;vector<int> ans;
    for(int i=1;i<=30000;i++){
        if(i==2||i==3||i==9) continue;
        if(i%2==0){
            q2.push(i);
        }
        else if(i%3==0){
            q3.push(i);
        }
    }    
    //片方の条件を満たしに行く
    n-=3;
    ans.push_back(2);
    ans.push_back(3);
    ans.push_back(9);

    //もう片方の条件を満たしに行く
    if(n%2==0&&n>0){
        while(!q3.empty()&&n>2){
            ans.push_back(q3.front());q3.pop();
            n--;
        }
        int sum=2;
        while(n>1){
            sum+=q2.front();
            sum%=3;
            ans.push_back(q2.front());q2.pop();
            n--;
            if(n==1) break;
        }
        while(1){
            if((q2.front()+sum)%3==0){
                ans.push_back(q2.front());
                break;
            }
            q2.pop();
        }
    }
    else if(n>0){
        while(!q3.empty()&&n>1){
            ans.push_back(q3.front());q3.pop();
            n--;
        }
        int sum=2;
        while(n>1){
            sum+=q2.front();
            sum%=3;
            ans.push_back(q2.front());q2.pop();
            n--;
            if(n==1) break;
        }
        while(1){
            if((q2.front()+sum)%3==0){
                ans.push_back(q2.front());
                break;
            }
            q2.pop();
        }
    }
    rep(i,ans.size()){
        cout<<ans[i];
        cout<<(i==ans.size()-1?'\n':' ');
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

LL n;
int main() {
#ifdef Wearry
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif 

    n = read<LL>();

    for(int i = 1; i <= 3500; ++i)
        for(int j = 1; j <= 3500; ++j) {
            LL X = 4LL*i*j - n*j - n*i, Y = n * i * j;

            if(X > 0 && Y % X == 0) {
                printf("%d %d %lld\n", i, j, Y / X);
                return 0;
            }
        }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdbool.h>

int main() {
	int n,k,r,s,p;
	int ans=0;
	char t[100001]={};
	scanf("%d%d%d%d%d", &n, &k, &r, &s, &p);
	scanf("%s", t);
	int cmpt[200001]={};
	for (int i = 0; i < n; i++) {
		if(t[i]=='r')
		cmpt[i]=0;
		else if(t[i]=='s')
		cmpt[i]=1;
		else if(t[i]=='p')
		cmpt[i]=2;
	}
	for (int i = 0; i < n; i++) {
		if(cmpt[i]==cmpt[i+k]){
			cmpt[i+k]=-1;
		}
		switch (cmpt[i]) {
			case 0:
			ans+=p;
			break;
			case 1:
			ans+=r;
			break;
			case 2:
			ans+=s;
			break;
			default:
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Cost[1000][1000], Dist[1000];

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

  fill((ll*)Cost, (ll*)(Cost + N), 1e18);

  for (int i = 0; i < M; i++){
    int A, B; ll C; cin >> A >> B >> C;
    A--; B--; C *= -1;
    Cost[A][B] = C;
  }

  fill(Dist, Dist + N, 1e18);
  Dist[0] = 0;
  bool flag = false;

  for (int k = 0; k < N; k++){
    for (int i = 0; i < N; i++){
      for (int j = 0; j < N; j++){
        if (i == j) continue;
        ll next = Cost[i][j];
        if (Dist[i] != 1e18 && Dist[j] > Dist[i] + next){
          Dist[j] = Dist[i] + next;
          if (k == N - 1 && j == N - 1) flag = true;
        }
      }
    }
  }

  if (flag == true){
    cout << "inf" << endl;
  }else{
    cout << -1 * Dist[N - 1] << endl;
  }

  return 0;
}

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

using namespace std;

int ketawa(int n) {
  int r = 0;
  while(n != 0) {
    r += n % 10;
    n /= 10;
  }
  return r;
}

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

  int sum = 0;
  for (int i = 1; i <= N; i++) {
    int num = ketawa(i);
    if (A <= num && num <= B) {
      sum += i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    while(true){
        int n,m; cin >> n >> m;
        if(n == 0)break;
        int sum[n] = {};
        rep(i,m){
            int p[n];
            rep(i,n){
                cin >> p[i];
                sum[i] += p[i];
            }
        }
        int ans = 0;
        rep(i,n)ans = max(ans, sum[i]);
        cout << ans << endl;    
    }
    return 0;
}
 
 



Measured memory_bytes: 3016
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
//$a = explode(" ",trim(fgets(STDIN)));
//$H = explode(" ",trim(fgets(STDIN)));
//
printf("%d\n",solve($A,$B,$C));

function solve($A,$B,$C) {
$total=0;
//Bの数
$m = min($B,$C);
$total += $m*2;
$C = $C - $m;
$B = $B - $m;
//$Aの数だけ食べれる
$m = min($A,$C);
$total +=  $m;
$C -= $m;
//Bは食べれる
$total +=  $B;
//Cが余ったら１個は食べれる
if ($C>0) $total += 1;
return $total;
}

Measured memory_bytes: 3828
N = int(input())
A = list(map(int, input().split()))



money = 1000
stock = 0

for i in range(N):
    if stock > 0 and i>=1:
        if A[i] > A[i-1]:
            money += stock * A[i]
            stock -= stock
    if money > A[i] and i<=N-2:
        if A[i]<A[i+1]:
            stock += money//A[i]
            money -= (money//A[i]) * A[i]

        
print(money)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
int A,B,T;
int ans = 0;
 
int main(){
  
  	cin >> A >> B >> T;
  	for ( int i = A; i <= T; i += A ){
    	ans += B;
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if ((a + b) > (c + d)) {
    cout << "Left" << endl;
} else if ((a + b) < (c + d)) {
    cout << "Right" << endl;
} else {
    cout << "Balanced" << endl;
}
}

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

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second

const int N = 305;

double dp[N][N][N];
int n;

double solve(int a, int b, int c) {
	if (dp[a][b][c] >= 0) return dp[a][b][c];
	if (a == 0 && b == 0 && c == 0) return dp[a][b][c] = 0;
	double res = 0;
	if (a) res += solve(a-1, b, c) * a;
	if (b) res += solve(a+1, b-1, c) * b;
	if (c) res += solve(a, b+1, c-1) * c;
	res = (res + n) / (1.0 * (a + b + c));
	return dp[a][b][c] = res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	cin >> n;
	int cnt[4] = {};
	for (int i=1; i<=n; i++) {
		int cur;
		cin >> cur;
		cnt[cur]++;
	}
	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			for (int k=0; k<N; k++) {
				dp[i][j][k] = -1;
			}
		}
	}
	double ans = solve(cnt[1], cnt[2], cnt[3]);
	cout << fixed << setprecision(12) << ans << "\n";
    return 0;
}


Measured memory_bytes: 221952
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

n = Ii()
a = Li()
mx = 0
ans = 0
for i in a:
  if mx > i:
    ans += mx - i
  else:
    mx = i
    
    
print(ans)

Measured memory_bytes: 32528
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 01/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N, M, K; cin>>N>>M>>K;
  vector<int> uf(N);
  iota(uf.begin(), uf.end(), 0);
  auto root = [f=[&](auto f, int x) {
    if (uf[x] == x)
      return x;
    return uf[x] = f(f, uf[x]);
  }](int x) {
    return f(f, x);
  };
  auto unite = [&](int a, int b) {
    uf[root(a)] = uf[root(b)];
  };

  vector<pair<int,int>> AB(M);
  for (int i = 0; i < M; i++) {
    int a,b; cin>>a>>b; a--; b--;
    AB[i]={a,b};
    unite(a, b);
  }
  vector<size_t> cands(N);
  for (int i = 0; i < N; i++) {
    cands[root(i)]++;
  }
  vector<size_t> pcands(N);
  for (int i = 0; i < N; i++) {
    pcands[i] = cands[root(i)]-1;
  }

  unordered_set<int> edges[N];
  for (auto ab : AB) {
    auto a = ab.first, b = ab.second;
    if (root(a) != root(b))
      continue;
    edges[a].insert(b);
    edges[b].insert(a);
  }
  for (int i = 0; i < K; i++) {
    int c,d; cin>>c>>d; c--; d--;
    if (root(c) != root(d))
      continue;
    edges[c].insert(d);
    edges[d].insert(c);
  }
  for (int i = 0; i < N; i++) {
    cout << pcands[i] - edges[i].size() << " ";
  }
  cout << endl;

  return 0;
}


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

int main(){
  int H,W,N;
  cin>>H>>W>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  queue<int> que;
  stack<int> sta;
  for(int i=0;i<N;i++)for(int j=0;j<v[i];j++)que.push(i+1);
  for(int i=0;i<H*W;i++){
    if((i/W)%2==0){
      cout<<que.front();
      que.pop();
      if(i%W==W-1)cout<<endl;
      else cout<<" ";
    }
    else{
      sta.push(que.front());
      que.pop();
      if(i%W==W-1){
        for(int j=0;j<W;j++){
          cout<<sta.top();
          sta.pop();
          if(j==W-1)cout<<endl;
          else cout<<" ";
        }
      }
    }
  }
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;

int N,X;
int main (){
    cin >> N >> X;
    int z = 1001;
    for(int i=0; i<N; i++){
        int m;
        cin >> m;
        z = min( z , m);
        X = X - m;
    }
    cout << N + X / z << endl;
    return 0;
}


Measured memory_bytes: 256