akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    
    int n;
    cin >> n;
    
    int cnt =0;
    int a=0,b=0;
    int suma =0,sumb =0,sum =0,ans = 1000000;

    for(int i=1;i<=n/2;i++){
            a = i;
            b = n-i;
            sum = 0;
            suma =0;
            sumb =0;
        for(int j=1;j<=5;j++){
            suma += a%10;
            a /= 10;
        }
        for(int j=1;j<=5;j++){
            sumb += b%10;
            b /= 10;
        }
        sum = suma + sumb;
        if(ans > sum) ans = sum;
    }
    cout << ans << endl;
    

    return 0;
};



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,n,aa,bb,cc;
int main()
{
	scanf("%lld %lld %lld %lld",&a,&b,&c,&n);
	if(n%2==0)printf("%lld",a-b);
	else printf("%lld",b-a);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n), tab(n, 1e9);
    
    for( int i = 0; i < n; i++ )
        cin >> a[i];
        
    tab[0] = 0;
    tab[1] = abs(a[1] - a[0]);
    
    if ( n == 2 ){
        cout << tab[1] << endl;
        return 0;
    }
    
    for ( int i = 0; i < n; i++ ){
        for( int j = i + 1; j <= i + k; j++ ){
          if ( j < n )
            tab[j] = min( tab[j], abs( a[i] - a[j] ) + tab[i] );
        }    
    }
    
    cout << tab[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 10005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int num_nodes,deg[MAXN],ans[MAXN];
ll res;
bool done[MAXN];
vector<int> vals,connections[MAXN];
set<pii> s;
vector<pii> edges;

int main(){
    scanf("%d",&num_nodes);
    for(int i=1; i<num_nodes; i++){
        int a,b; scanf(" %d %d",&a,&b);
        deg[a]++, deg[b]++;
        connections[a].pb(b);
        connections[b].pb(a);
        edges.pb(mp(a,b));
    }
    for(int i=1; i<=num_nodes; i++){
        int a; scanf(" %d",&a);
        vals.pb(a);
        s.insert(mp(deg[i],i));
    }
    sort(all(vals),greater<int>());
    while(s.size()){
        pii largest = *s.begin(); s.erase(largest); done[largest.second] = true;
        ans[largest.second] = vals.back(); vals.pop_back();
        for(int check:connections[largest.second]){
            if(done[check]) continue;
            s.erase(mp(deg[check]--,check));
            s.insert(mp(deg[check],check));
        }
    }
    for(pii check:edges)
        res+=min(ans[check.first],ans[check.second]);
    printf("%lld\n",res);
    for(int i=1; i<=num_nodes; i++)
        printf("%d ",ans[i]);
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		Position currentPosition = new Position();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		//入力値をもとに移動する
		while((input = br.readLine()) != null){
			String[] i = input.split(",");
			int distance = Integer.parseInt(i[0]);
			int angle = Integer.parseInt(i[1]);
			if(distance == 0 && angle == 0)	break;
			currentPosition.move(distance, angle);
		}
		System.out.println(currentPosition);
		br.close();
	}
}

class Position{
	private double x;
	private double y;
	private int currentAngle;
	public Position() {
		x = 0.0;
		y = 0.0;
		currentAngle = 90;
	}
	public void move(int distance, int angle){
		x += distance * Math.cos(Math.toRadians(currentAngle));
		y += distance * Math.sin(Math.toRadians(currentAngle));
		currentAngle -= angle;
	}
	@Override
	public String toString(){
		return (int)x + "\n" + (int)y;
	}
}

Measured memory_bytes: 16936
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {
	ll N, X;
	cin >> N >> X;
	vector<ll> b(N + 1), l(N + 1), u(N + 1);
	repn(i, N) cin >> b[i] >> l[i] >> u[i];

	vector<pair<ll, ll>> p(N + 1);
	repn(i, N) {
		p[i].first = (X - b[i])*u[i] + b[i] * l[i];
		p[i].second = i;
	}
	sort(++p.begin(), p.end(), greater<pair<ll, ll>>());

	//repn(i, N) cout << p[i].first <<" "<< p[i].second << endl;


	ll st = 0;
	repn(i, N) st -= b[i] * l[i];
	vector<ll> rui(N + 1, 0);
	rui[0] = st;
	repn(i, N) rui[i] += rui[i - 1] + p[i].first;

	auto itr = lower_bound(rui.begin(), rui.end(), 0);
	ll K = distance(rui.begin(), itr);

	//rep(i, N+1) cout << rui[i] << endl;

	ll ans = INF;

	if (K == 0) { ans = 0; }
	else {
		repn(i, N) {
			ll now = X * (K - 1);

			ll s = -rui[K];
			if (i < K) { s += p[i].first; }
			else { s += p[K].first; }

			ll j = p[i].second;

			//cout << s << endl;

			if (s == 0) { now += 0; }
			else if (s <= b[j] * l[j]) { now += (s - 1) / l[j] + 1; }
			else if (s <= p[i].first) {
				s -= b[j] * l[j];
				now += b[j] + (s - 1) / u[j] + 1;
			}
			else { now = INF; }

			ans = min(ans, now);

		}
	}

	cout << ans << endl;

	

	system("PAUSE");
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<algorithm>
#define ed "\n";
using namespace std;

struct tim{
    int a;
    int b;
};

int main(){
    int n;
    cin >> n;
    vector<tim> t(n);
    
    for(int i=0; i<n; i++){
        cin >> t[i].a >> t[i].b;
    }
    sort(t.begin(), t.end(), [](const tim &x, const tim &y){ return x.b<y.b;});
    int cnt=0;
    int l=0;
    for(int i=0; i<n; i++){
        cnt+= t[i].a;
        if(cnt>t[i].b) {
            l=1;
            break;
        }
    }
    if(l==0) {cout << "Yes" << ed;}
    else{ cout << "No" << ed};   
}

Measured memory_bytes: 1792
def main():
    inputs = input().split(' ')
    takahashi_hp = int(inputs[0])
    takahashi_pw = int(inputs[1])
    aoki_hp = int(inputs[2])
    aoki_pw = int(inputs[3])

    flag = True
    cnt = 1
    while flag:
        if cnt % 2 == 1:
            aoki_hp -= takahashi_pw
            if aoki_hp <= 0:
                flag = False
                result = 'Yes'
        
        else:
            takahashi_hp -= aoki_pw
            if takahashi_hp <= 0:
                flag = False
                result = 'No'

        cnt += 1

    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9208
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<long long int, long long int> P;
#define F first
#define S second
#define MAX_N 100000
#define INF 1e18
P house[2][2 * MAX_N + 1];
long long int ruiseki[2][2 * MAX_N + 1] = {};
int main() {
	long long int w, h, n, sum = 0, time = INF, ma = 0, mid, x = 0, y = 0, ansx = INF, ansy = INF, p, mid2, sum2;

	P save, save2, search;
	cin >> w >> h >> n;
	for (int i = 0; i <2 * n; i += 2) {
		long long int a, b;
		scanf("%lld%lld", &a, &b);
		house[0][i] = make_pair(a, b);
		house[0][i + 1] = house[0][i];
		house[1][i] = make_pair(b, a);
		house[1][i + 1] = house[1][i];
	}
	sort(house[0], house[0] + 2 * n);
	sort(house[1], house[1] + 2 * n);
	for (int i = 0; i < 2 * n; i++) {
		ruiseki[0][i] += abs(house[0][i].F - x); ruiseki[1][i] += abs(house[1][i].F - y);
		if (i) {
			ruiseki[0][i] += ruiseki[0][i - 1];
			ruiseki[1][i] += ruiseki[1][i - 1];
		}
	}
	mid = mid2 = n - 1;
	for (int j = 0; j < 2 * n; j += 2) {
		sum2 = 0;
		if (j < mid)
			mid++;
		search = make_pair(house[0][j].S, house[0][j].F);
		p = lower_bound(house[1], house[1] + n * 2, search) - house[1];
		if (p < mid2)
			mid2++;
		x = house[0][mid].F;
		y = house[1][mid2].F;

		sum2 += (mid + 1) * x + (mid2 + 1) * y - ruiseki[0][mid] - ruiseki[1][mid2];
		sum2 += ruiseki[0][2 * n - 1] + ruiseki[1][2 * n - 1] - ruiseki[0][mid] - ruiseki[1][mid2] - (2 * n - mid - 1) * x - (2 * n - mid2 - 1) * y;
		sum2 -= abs(house[0][j].F - x) + abs(house[0][j].S - y);
		if (time == sum2) {
			time = sum2;
			if (ansx > x) {
				ansx = x;
				ansy = y;
			}
			if (ansx == x) {
				if (ansy > y) {
					ansy = y;
				}
			}
		}
		if (time > sum2) {
			time = sum2;
			ansx = x;
			ansy = y;
		}
		if (j < mid)
			mid--;
		if (p < mid2)
			mid2--;
	}
	cout << time << endl;
	cout << ansx << ' ' << ansy << endl;
}

Measured memory_bytes: 10624
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,d;
    cin >> n >> d;
    cout << (n+d+d)/(d+d+1) << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
MOD = 10 ** 9 + 7

def main(): 
    N, Q = LI()
    STX = []
    for _ in range(N):
        STX.append(LI())
    D = []
    for _ in range(Q):
        D.append(II())

    STX.sort(key=lambda x:x[2])

    ans = [-1] * Q
    skip = [-1] * Q

    from bisect import bisect_left
    for s, t, x in STX:
        left = bisect_left(D, s-x)  # s-x を超える最小のdの位置
        right = bisect_left(D, t-x)  # t-x を超える最小のdの位置

        while left < right:
            if skip[left] == -1:  # 未踏
                ans[left] = x
                skip[left] = right  # つぎにここにきた際は、rightまで見るのをスキップしてよい。
                left += 1
            else:  # 来たことがある
                left = skip[left]  # 以前覚えておいた right まで見るのをスキップする。

    for i in ans: print(i)

main()

Measured memory_bytes: 61704
#include <bits/stdc++.h>
    using namespace std;
     
    using ll = long long;
     
    int main() {
       ll X, Y;
       cin >> X >> Y;
       ll ans = 0;
       while (X <= Y) {
          ans++;
          X*=2;
       }
       cout << ans << endl;
     
       return 0;
    }

Measured memory_bytes: 256
n, y = map(int, input().split())
max_x = y // 10000
max_y = y // 5000
max_z = y // 1000

for i in range(max_x + 1):
    for j in range(max_y + 1):
        remain = y - 10000 * i - 5000 * j
        if remain < 0:
            continue
        if remain // 1000 == n - (i + j):
            print(i, j, (n - i - j))
            exit()
print(-1, -1, -1)


Measured memory_bytes: 42552
package main

import (
	"fmt"
)

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

	if x%11 == 0 {
		x = x / 11 * 2
	} else if x%11 <= 6 {
		x = x/11*2 + 1
	} else {
		x = x/11*2 + 2
	}

	fmt.Println(x)
}


Measured memory_bytes: 512
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! 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")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        s: chars
    }
    let mut valid = true;
    for i in 0..a+b+1 {
        if i == a {
            if s[i] != '-' {
                valid = false
            }
        } else {
            if s[i] == '-' {
                valid = false
            }
        }
    }
    println!("{}", 
        if valid {"Yes"} else {"No"}
    );
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**8)

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

t = dict()
for i in range(1, n+1):
    t[i] = []
for a, b in ab:
    t[a].append(b)
    t[b].append(a)

cnt = [0] * n
s = set()
for p, x in px:
    cnt[p-1] += x

def solve(p):
    s.add(p)
    for c in t[p]:
        if c not in s:
            cnt[c-1] += cnt[p-1]
            solve(c)
solve(1)
print(*cnt, sep=' ')


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

class Combination:
    def __init__(self, size):
        self.size = size
        self.fact = [1] * size
        for i in range(1, size):
            self.fact[i] = i * self.fact[i - 1]

    def ncr(self, n, r):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fact[n] // self.fact[r] // self.fact[n - r]

odd = 0
even = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

ans = 0
comb = Combination(N + 100)
if P == 0:  # oddを偶数個
    for o in range(0, odd + 1, 2):
        for e in range(even + 1):
            ans += comb.ncr(odd, o) * comb.ncr(even, e)
else:
    for o in range(1, odd + 1, 2):
        for e in range(even + 1):
            ans += comb.ncr(odd, o) * comb.ncr(even, e)

print(ans)

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

int W, D;
int H1[15], H2[15];

void read();
void solve();

int main() {
  while (cin >> W >> D, W != 0 && D != 0)
    read(), solve();

  return 0;
}

void read() {
  for (int i = 0; i < W; ++i)
    cin >> H1[i];
  for (int i = 0; i < D; ++i)
    cin >> H2[i];
}

void solve() {
  static int c1[25], c2[25];

  fill(&c1[0], &c1[25], 0);
  fill(&c2[0], &c2[25], 0);
  for (int i = 0; i < W; ++i)
    c1[H1[i]] += H1[i];
  for (int i = 0; i < D; ++i)
    c2[H2[i]] += H2[i];

  int res = 0;

  for (int i = 1; i <= 20; ++i) {
    int m = min(c1[i], c2[i]);
    res += m, c1[i] -= m, c2[i] -= m;
  }

  res += accumulate(&c1[0], &c1[25], 0);
  res += accumulate(&c2[0], &c2[25], 0);

  cout << res << "\n";
}

Measured memory_bytes: 1156
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	var minusNums int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if a[i] < 0 {
			minusNums++
			a[i] = - a[i]
		}
	}

	var ret int64
	if minusNums%2 == 0 {
		for i := 0; i < n; i++ {
			ret += int64(a[i])
		}
	} else {
		sort.Ints(a)
		ret = -int64(a[0])
		for i := 1; i < n; i++ {
			ret += int64(a[i])
		}
	}

	fmt.Println(ret)
}


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

long long dfs(long long n){
	if(n==1) return 1;
	long long res=0;
	res+=dfs(n/2)*2+1;
	return res;
}
int main() {
	long long n;
	cin >> n;
	cout << dfs(n) << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		char[] ca = next().toCharArray();
		for(int i = 0; i < ca.length; i++) {
			if((int)ca[i] + n > 90){
				ca[i] = (char)((int)ca[i] + n - 26);
			}else {
				ca[i] = (char)((int)ca[i] + n);
			}
			
		}
				
		System.out.println(new String(ca));
	}
	
	private static int dfs(int dig, int cur, int max) {
		int result = 0;	
		if(dig >= 3) {
			if(dig <= Integer.toString(max).length()) {
				if(cur <= max) {
					if(is753(cur))result++;
				} else {
					return 0;
				}
			} else {
				return 0;
			}
		}	
		dig++;
		result += dfs(dig, cur * 10 + 3, max) + dfs(dig, cur * 10 + 5, max) + dfs(dig, cur * 10 + 7, max);
		return result;
	}

	private static boolean is753(int in) {
		boolean[] flags = new boolean[3];
		char[] inca = Integer.toString(in).toCharArray();
		for(char c:inca) {
			if(c == '3')flags[0] = true;
			if(c == '5')flags[1] = true;
			if(c == '7')flags[2] = true;
		}
		
		return flags[0] && flags[1] && flags[2];
	}
	//Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A[N], B[N], C[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);
    int *a, *c;
    ll ans = 0;
    rep(i, N) {
        a = lower_bound(A,A+N,B[i]);
        c = upper_bound(C,C+N,B[i]);
        //while(*c == *(c+1)) c = c+1;
        //cout << *c << endl;
        //dump(a-A);
        //dump(N+(C - c));
        ans += (a - A) * (N+(C - (c)));
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>
 
using namespace std;
 
int main(){
    
    string str;

    cin >> str;

    for(auto &&e : str){
        if(e == '1'){
            e = '9';
        }else if(e == '9'){
            e = '1';
        }
    }

    cout << str << endl;
    
    return 0;
}

Measured memory_bytes: 256
// Problem : A - Circle Pond
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    int r;
    cin >> r;
    cout << 2 * M_PI * r;
    
    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int N,M;
  cin>>N>>M;
  vector<int>p(M);
  vector<string>S(M);
  for(int i=0;i<M;i++){
    cin>>p[i]>>S[i];
  }
  vector<bool>ok(N+1,false);
  int sumw=0,suma=0;
  vector<int>WA(N);
  for(int i=0;i<M;i++){
   if(ok[p[i]]){continue;}
   if(S[i]=="AC"){ok[p[i]]=true;suma++;sumw+=WA[p[i]];}
   if(S[i]=="WA"){WA[p[i]]++;}
  }
  cout<<suma<<" "<<sumw<<endl;
  return 0;
}

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

int main() {
  
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  string str;
  
  for(int i =0; i<1000000;i++) {
    
    C -= B;
    
    if(C <= 0) {
      str = "Yes";
      break;
    }
    
    A -= D;
    
    if(A <= 0) {
      str = "No";
      break;
    }
  }
  cout << str <<endl;
  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
	int A, B;

	scanf("%d", &A);
	scanf("%d", &B);

	if (A == 1)
		A = 14;
	if (B == 1)
		B = 14;

	if (A > B)
		printf("Alice");
	else if (A == B)
		printf("Draw");
	else
		printf("Bob");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int>v;
    int n,k,i,a,s=0;
    cin>>n>>k;
    for(i=0; i<n; i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(i=0; i<k; i++)
        s+=v[i];
    cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int main()
{
    int n,s=0,r,i;
    scanf("%d",&n);
    r=n;
    while(n!=0)
    {
        i=n%10;
        s=s+i;
        n=n/10;
    }
    if(r%s!=0)
    printf("No");
    else
    printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,m;
	cin>>n>>m;
	int s=0;
	for(int i=1;i<=m;i++)
	{
		int x;
		cin>>x;
		s+=x;
	}
	if(s>n)
		cout<<"-1\n";
	else
		cout<<n-s<<"\n";
	return 0;
}

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

int main() {
  int N;
  int y = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    string X;
    cin >> X;
    
    if (X == "Y"){
      y += 1;
    }
  }
  
  if (y == 0){
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,rem; cin>>n;
    rem=n%10;
    if(rem==3) cout<<"bon";
    else if(rem==0 || rem==1 || rem==6 || rem==8) cout<<"pon";
    else cout<<"hon";
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '

const int MAXN = 200;
ll a[MAXN], ST[MAXN * 4], LZ[MAXN*4];
int gcd(int a , int b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

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

    return 0;  
}

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

int main(){
 int N,W;
 cin >> N >> W;
 int v[N];
 int w[N];
 for(int i=0; i<N; i++){
  cin >> v[i] >> w[i];
 }

 int DP[N+1][W+1];

 for(int j=0; j<=W; j++){
  DP[0][j] = 0;
 }
 
 for(int i=1; i<=N; i++){
  for(int j=0; j<=W; j++){
   if(j<w[i-1]){
    DP[i][j] = DP[i-1][j];
   }else{
    if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
     DP[i][j] = DP[i-1][j];
    }else{
     DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
    }
   }
  }
 }
  
 cout << DP[N][W] << endl;

/*???????????°
for(int i=0; i<=N; i++){
 for(int j=0; j<=W; j++){
  cout << DP[i][j] << " ";
 }
 cout << endl;
}*/

 return 0;
}
 

Measured memory_bytes: 7012
#include <stdio.h>

int main(){
	long n,s[100030],result=0;
	int i,j,k;
	
	scanf("%ld",&n);
	
	s[0]=0;
	s[n+1]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%ld",&s[i]);
	}
	
	for(i=0;i<=n;i++){
		
		if(s[i+1]>=s[i]){
		result=result+s[i+1]-s[i];
		}else{
		result=result+s[i]-s[i+1];
			
			}}
			
	long result2=result;
	for(i=1;i<=n;i++)
	{
		if(s[i]>=s[i-1]){
		result2=result2-s[i]+s[i-1];
		}else{
		result2=result2-s[i-1]+s[i];}
			
		
		if(s[i+1]>=s[i]){
		result2=result2-s[i+1]+s[i];
		}else{
		result2=result2-s[i]+s[i+1];}
		
		if(s[i+1]>=s[i-1]){
		result2=result2+s[i+1]-s[i-1];
		}else{
		result2=result2+s[i-1]-s[i+1];}
			
		
		printf("%ld\n",result2);
		result2=result;
	}
	
	}

Measured memory_bytes: 1920
H, W = map(int, raw_input().split())

g = [map(int, raw_input().split()) for _ in range(H)]

mvs = []
for i in xrange(H):
    r = range(W) if i % 2 == 0 else range(W)[::-1]
    mv = 1 if i%2==0 else -1
    for j in r:
        if g[i][j] % 2 == 0:
            continue
        if 0<=j+mv and j+mv < W:
            g[i][j] -=1
            g[i][j+mv] +=1

            mvs.append((i+1,j+1,i+1,j+mv+1))
        elif i+1 < H:
            g[i][j] -= 1
            g[i+1][j] += 1
            mvs.append((i+1,j+1,i+2,j+1))

print len(mvs)
for m in mvs:
    print "%d %d %d %d" % m


Measured memory_bytes: 24708
#include<iostream>
#define N 110000
using namespace std;
int main(){
  	bool num[N] ;
	for(int i =0;i<N;i++)
		num[i] = true;
	num[0] = false; num[1] = false;
	for(int i=2;i*i<N;i++){
	if(num[i] == true){
		for(int k = i * 2;k<N;k +=i)
		num[k] = false;
	}
	}
	
	int n;
	while(1){
	cin >> n;
	if(n == 0){
	 return 0;
	}
	long long s =0;
	for(int i=0;i<n;i++){
		for(int k=0;i<n;k++){
		if(num[k] == true){
			s = s + k; i++;
			}
		}
	}
	 cout << s << endl;
	
	}

}

Measured memory_bytes: 1260
n = int(input())

s = []
for i in range(n):
	s.append(input())
t = input()

before = 0
after = 0

for i in s:
	if t < i.replace('?','a'):
		after += 1
	if i.replace('?','z') < t:
		before += 1


print(*range(before+1,n-after+2))

Measured memory_bytes: 4084
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
	while(true){
		
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		if(H==0&&W==0)break;
		
		 for(int j=0;j<H;j++){
			for(int i=0;i<W;i++){
				System.out.print("#");
				
				
			}
			System.out.println("");
		 }
		System.out.println("");
		}
	

	}
	
	
	
}


Measured memory_bytes: 34412
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
using namespace std;
signed main() {
	string s;
	cin >> s;
	if (s == "otouto")cout << "e869120" << endl;
	else cout << "square1001" << endl;
}


Measured memory_bytes: 3204
#include <iostream>
#include <map>
#include <vector>

#define db(x) cout << "> " << #x << ": " << x << endl;

const int N = 200100;
using namespace std;

long long pos_pref[N];
long long neg_pref[N];

int T[4 *N];
vector <long long> val;
map <long long, int> cnt;

inline int c1(int n) { return (n << 1); }
inline int c2(int n) { return (n << 1)|1; }

void build(int curr, int st, int end)
{
	if(st == end)
	{
		T[curr] = cnt[val[st]];
		return;
	}
	
	int mid = st +end >> 1;
	
	build(c1(curr), st, mid);
	build(c2(curr), mid +1, end);
	
	T[curr] = T[c1(curr)] +T[c2(curr)];
}

void update(int curr, int st, int end, int idx)
{
	if(st == end)
	{
		T[curr]--;
		return;
	}
	
	int mid = st +end >> 1;
	
	if(idx <= mid)
		update(c1(curr), st, mid, idx);
	
	else
		update(c2(curr), mid +1, end, idx);
		
	T[curr] = T[c1(curr)] +T[c2(curr)];
}

int query(int curr, int st, int end, int l, int r)
{
	if(st > end || r < st || end < l)
		return 0;
	
	if(l <= st && end <= r)
		return T[curr];
	
	int mid = st +end >> 1;
	
	int q1 = query(c1(curr), st, mid, l, r);
	int q2 = query(c2(curr), mid +1, end, l, r);
	
	return q1 +q2;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		
		pos_pref[i] = pos_pref[i -1];
		neg_pref[i] = neg_pref[i -1];
		
		if(a -k > 0)
			pos_pref[i] += (a -k);
		
		else
			neg_pref[i] += (k -a);
	}
	
	for(int i = 1; i <= n; i++)
		cnt[pos_pref[i] -neg_pref[i]]++;
	
	for(auto it = cnt.begin(); it != cnt.end(); it++)
		val.push_back(it->first);
	
	map <long long, int> idx;
	int sz = val.size();
	for(int i = 0; i < sz; i++)
		idx[val[i]] = i;
	
	build(1, 0, sz -1);
	
	long long res = 0, offset = 0;
	for(int i = 1; i <= n; i++)
	{
		auto it = lower_bound(val.begin(), val.end(), offset);
		
		if(it == val.end())
		{
			offset = (pos_pref[i] -neg_pref[i]);
			update(1, 0, sz -1, idx[pos_pref[i] -neg_pref[i]]);
			continue;
		}
		
		res += query(1, 0, sz -1, idx[*it], sz -1);
		offset = (pos_pref[i] -neg_pref[i]);
		update(1, 0, sz -1, idx[pos_pref[i] -neg_pref[i]]);
	}
	
	cout << res << '\n';
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,D[101];
int cnt[13];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cnt[0]=2;
	FOR(i,N) {
		cin>>x;
		cnt[x]++;
		if(x==12) if(cnt[x]>1) return _P("0\n");
		if(cnt[x]>2) return _P("0\n");
	}
	
	int ma=0;
	for(int mask=0;mask<1<<12;mask++) {
		vector<int> V;
		FOR(i,12) {
			if(cnt[i]==2) V.push_back(i),V.push_back(24-i);
			if(cnt[i]==1) {
				if(mask&(1<<i)) V.push_back(i);
				else V.push_back(24-i);
			}
		}
		if(cnt[12]) V.push_back(12);
		
		sort(ALL(V));
		int dm=24;
		FOR(i,V.size()-1) dm=min(dm,V[i+1]-V[i]);
		ma=max(ma,dm);
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
S = input().strip()
m = int(S[:2])
n = int(S[2:])

res = None
if 1 <= m <= 12 and 1 <= n <= 12:
    res = 'AMBIGUOUS'
elif 1 <= m <= 12:
    res = 'MMYY'
elif 1 <= n <= 12:
    res = 'YYMM'
else: res = 'NA'

print(res)


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

int main(){
    long long X;
    cin >> X ;
    long long coin_500, coin_5;

    coin_500 = X / 500;
    X = X - coin_500 * 500;
    coin_5 = X / 5;

    cout << 1000 * coin_500 + 5 * coin_5 << endl;

    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i,j,x,y,size,paper[14][14],white=0,ichibankoi=0;
    for(i=0;i<14;i++){
        for(j=0;j<14;j++){
            paper[i][j]=0;
        }
    }
    while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
        x+=2;
        y+=2;
        if(size>=1){
            paper[y-1][x]+=1;
            paper[y][x-1]+=1;
            paper[y][x]+=1;
            paper[y][x+1]+=1;
            paper[y+1][x]+=1;
        }
        if(size>=2){
            paper[y-1][x-1]+=1;
            paper[y-1][x+1]+=1;
            paper[y+1][x-1]+=1;
            paper[y+1][x+1]+=1;
        }
        if(size>=3){
            paper[y-2][x]+=1;
            paper[y][x-2]+=1;
            paper[y][x+2]+=1;
            paper[y+2][x]+=1;
        }
    }
    for(i=2;i<12;i++){
        for(j=2;j<12;j++){
            //printf("%d ",paper[i][j]);
            if(paper[i][j]>ichibankoi)
                ichibankoi=paper[i][j];
            else if(paper[i][j]==0)
                white++;
        }
        //puts("");
    }
    printf("%d\n%d\n",white,ichibankoi);

    return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var ab = ReadLine().Split();
            var connectedAb = long.Parse(ab[0] + ab[1]);
            var heihou = (long)Math.Sqrt(connectedAb);
            WriteLine(connectedAb == heihou * heihou ? "Yes" : "No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11092
// ABC 86 A

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

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 3) {
    if (s[i] == '1') {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

// int dx4[4]={1,0,-1,0};
// int dy4[4]={0,-1,0,1};
int dx4[4]={-1,1,0,0};
int dy4[4]={0,0,-1,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> x;
  ll sum = 0;
  int i = 0;
  for(; sum<x;) {
    i++;
    sum += i;
  }

  cout << i << endl;
}


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

#define MATHPI acos(-1)

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}
template<class T> void chmin(T &a, T b) {
    if (b < a) a = b;
}

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;cin>>N;
    vector<int> v;
    while(N--) {
        int x;cin>>x;
        v.push_back(x);
    }
    double mean_v= accumulate(v.begin(),v.end(),0) / (double)v.size();
    
    int s1=0,s2=0;
    for (auto &&i : v)
    {
        int x1 = floor(mean_v);
        int x2 = ceil(mean_v);
        s1 += (i-x1) * (i-x1);
        s2 += (i-x2) * (i-x2);
    }
    // cout << "S1: " << s1 << " S2: " << s2 << "\n";
    cout << min(s1,s2) << "\n";
    


    return 0;
}


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


void solve(long long A, long long B){
    if(10>A&&10>B) cout<<A*B<<"\n";
    else if(10<=A||10<=B) cout<<-1<<"\n";
}


int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 1005;
const ll mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie(0);
    ll n;
    cin >> n;
    ll ans = (n/500)*1000;
    n %= 500;
    ans += (n/5)*5;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  
  ll money=1000;
  rep(i,n-1){
    ll stock=0;
    if(a[i]<a[i+1])stock=money/a[i];
    money+=(a[i+1]-a[i])*stock;
  }
  cout << money << endl;
  return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int N, M, R;
ll r[10];
bool flag[10];
ll d[201][201] = { 0 };
ll ans = 10000000000;

ll func(int h);

int main() {
	cin >> N >> M >> R;
	for (int i = 0; i < R; i++) {
		cin >> r[i];
		r[i]--;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			d[i][j] = 10000000000;
		}
	}
	for (int i = 0; i < N; i++) d[i][i] = 0;
	int a, b;
	ll c;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = d[b][a] = c;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	for (int s = 0; s < R; s++) {
		for (int i = 0; i < R; i++) flag[i] = true;
		ans = min(ans, func(s));

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

ll func(int h) {
	flag[h] = false;
	ll res = 10000000000;
	for (int i = 0; i < R; i++) {
		if (flag[i]) {
			res = min(res, func(i) + d[r[h]][r[i]]);
		}
	}
	flag[h] = true;
	if (res == 10000000000) return 0;
	return res;
}

Measured memory_bytes: 512
import java.io.*;class Main{
public static void main(String[]_)throws Exception{
int i,j;
boolean f;
float l[]=new float[8];
BufferedReader B=new BufferedReader(new InputStreamReader(System.in));
for(String s;(s=B.readLine())!=null;System.out.println(f?"NO":"YES")){
_=s.split(",");
f=false;
for(j=0;j<2;j++){
for(i=0;i<8;i++)l[i]=Float.valueOf(_[(4*j+i)%8]);
f|=
((l[0]-l[2])*(l[5]-l[1])+(l[1]-l[3])*(l[0]-l[4]))*
((l[0]-l[2])*(l[7]-l[1])+(l[1]-l[3])*(l[0]-l[6]))<0;
}
}
}
}

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

using namespace std;

int main(){
  int n, i, j, ain, minj, tmp, cnt = 0;
  vector<int> a;

  cin >> n;
  for(i = 0;i < n;++i){
    cin >> ain;
    a.push_back(ain);
  }

  for(i = 0;i < n;++i){
    minj = i;
    for(j = i;j < n;++j)
      if(a[j] < a[minj])minj = j;
    if(a[i] != a[minj])++cnt;
    tmp = a[i];
    a[i] = a[minj];
    a[minj] = tmp;
  }

  
  for(i = 0; i < n;++i){
    cout << a[i];
    if(i != n-1)cout << " ";
  }
  
  cout << "\n" <<cnt << endl;
  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

bool used[100001];
vector<pint> g[100001];
pint e[200001],d[100001];
int r[200001];
void bfs(int sr){
    queue<pint> q;q.push({sr,0});
    used[sr]=true;
    while(!q.empty()){
        pint pi=q.front();q.pop();
        rep(i,g[pi.first].size()){
            int nx=g[pi.first][i].first;
            if(!used[nx]){
                used[nx]=true;
                d[nx]={min(d[pi.first].first,g[pi.first][i].second),pi.second+1};
                q.push({nx,pi.second+1});
            }
            else{
                if(d[nx].second==pi.second+1){
                    d[nx].first=max(min(d[pi.first].first,g[pi.first][i].second),d[nx].first);
                }
            }
        }
    }
}
int main(){
    int n,m,q,ui,vi,ri;
    cin>>n>>m>>q;
    rep(i,m){
        cin>>ui>>vi;
        --ui,--vi;
        e[i]={ui,vi};
    }
    rep(i,m) r[i]=q;
    rep(i,q){
        cin>>ri;
        --ri;
        r[ri]=i;
    }
    FOR(i,0,m){
        g[e[i].first].pb(e[i].second,r[i]);
        g[e[i].second].pb(e[i].first,r[i]);
    }
    d[0]={q,0};
    bfs(0);
    int cnt=0,cur=0;
    sort(d,d+n);
    rep(i,q){
        while(cur<n&&d[cur].first<=i) ++cur;
        cout<<cur<<endl;
    }
    return 0;
}


Measured memory_bytes: 15116
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, K, a, b, c, d, e, H, W;
long long A[20000] = {};
long long B[20000] = {};
long long t[20000] = {};
long long tt[20000] = {};
bool f[1000][1000] = {};
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <long long>vpl;



int main() {
	cin >> N>>M;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		vpl.push_back(A[i]);
	}

	a = 0;
	sort(vpl.begin(), vpl.end());

	for (int i = 0; i < N;i++) {
		M -= vpl[i];
		if (M >= 0) {
			a++;
			if (i == N - 1 && M != 0) {
				a--;
			}
		}
		else {
			break;
		}
	}
	cout << a << endl;

	return 0;
}

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



int main(){
	int N;
	cin>>N;
	vector<int> A(N),B(N),C(N);
	
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	for(int i=0;i<N;i++){
		cin>>B[i];
	}
	for(int i=0;i<N;i++){
		cin>>C[i];
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	
	long long ans = 0;
	
	for(int i=0;i<N;i++){
		auto itr = (int)(lower_bound(A.begin(),A.end(),B[i])-A.begin());
		auto itr2 = N-(int)(upper_bound(C.begin(),C.end(),B[i])-C.begin());
		ans+=(long long)itr*itr2;
		//cout<<itr<<endl;
		//cout<<itr2<<endl;
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func calcPoint(orders, satisfactions, bonuses []int) (total int) {
	old := -999
	for _, order := range orders {
		index := order - 1 //array's index start 0. but, oder start 1.
		total += satisfactions[index]
		if old == index-1 {
			total += bonuses[old]
		}
		old = index
	}
	return
}

func main() {
	n := nextInt()

	orders := nextInts(n)
	satisfactions := nextInts(n)
	bonuses := nextInts(n - 1)

	result := calcPoint(orders, satisfactions, bonuses)

	fmt.Println(result)
}


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

using namespace std;

typedef long long int ll;
#define push_back pb
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/******************************************************/
void solve(){
	int a, b;
	cin >> a >> b;
	a *= 500;
	if(a >= b)cout << "Yes";
	else cout << "No";
}


/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 256