akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
  int x,i=2,j=2,max=1,temp;
  cin>>x;
  for(i=2;i*i<x;i++){
    for(j=2;;j++){
      temp=pow(i,j);
      if(temp<=max){
        continue;
      }
      if(temp>x){
        break;
      }
      max=temp;
    }
  }
  out:
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};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;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

void solve(long long n, long long m, std::vector<long long> a){
    rep(i,n)a[i]--;
    vl sum1(m+5),sumM(m+5);
    rep(i,n-1){
        if(a[i]<a[i+1]){
            sum1[a[i]+2]++;
            sum1[a[i+1]+1]--;
            sumM[a[i+1]+1]-=a[i+1]-a[i]-1;
        }else{
            sum1[a[i]+2]++;
            if(a[i]==m-1){
                sum1[1]++;
            }else{
                sum1[0]++;
                sumM[0]+=m-2-a[i];
            }
            sum1[a[i+1]+1]--;
            sumM[a[i+1]+1]-=m+a[i+1]-a[i]-1;
        }
    }

    rep(i,m)sum1[i+1]+=sum1[i];
    rep(i,m)sum1[i]+=sumM[i];
    rep(i,m)sum1[i+1]+=sum1[i];

    ll ma=0;
    rep(i,m){
        chmax(ma,sum1[i]);
    }

    ll ans=0;
    rep(i,n-1){
        ll tmp=a[i+1]-a[i];
        if(tmp<0)tmp+=m;
        ans+=tmp;
    }
    ans-=ma;
    cout<<ans<<endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    long long m;
    scanf("%lld",&m);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    solve(n, m, std::move(a));
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

double pi = 3.14159;

int main(void) {
    int a, b;
    double rad = 0.0;
    double x = 0;
    double y = 0;
    
    do {
        scanf("%d,%d", &a, &b);
        x += a * sin((rad/180) * pi);
        y += a * cos((rad/180) * pi);
        rad += b;
    }while(!(a == 0 && b == 0));
    cout << (int)x << endl
         << (int)y << endl;
}


Measured memory_bytes: 3340
import sys
from io import StringIO
import unittest
def getxor(i):
    if i%4==0:
        t=i
    elif i%4==1:
        t=1
    elif i%4==2:
        t=i+1
    else:
        t=0
    return t
class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 4"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """123 456"""
        output = """435"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """123456789012 123456789012"""
        output = """123456789012"""
        self.assertIO(input, output)

def resolve():
    (A,B)=(int(i) for i in input().split())
    xx=getxor(A-1)
    yy=getxor(B)
    print(xx^yy)
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 51568
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, D, A;
    cin >> N >> D >> A;
    vector<tuple<ll, ll, int, int>> X;
    vector<ll> cnt(N);

    REP(i,N){
        ll x, H;
        cin >> x >> H;
        X.emplace_back(2*x, H, -1, i);
        X.emplace_back(2*x+4*D+1, H, 1, i);
    }
    sort(X.begin(), X.end());
    ll ans = 0;
    ll now = 0;
    for(auto t : X){
        ll x, h;
        int flg, idx;
        tie(x, h, flg, idx) = t;
        //cout << x << " " << h << " " << flg << " " << idx << endl;
        if(flg == 1){
            now -= cnt[idx];
        }
        else{
            ll need = (h - now*A + A - 1) / A;
            //cout << x << " " << h << " " << flg << " " << idx << " " << need << endl;
            if(need > 0){
                ans += need;
                cnt[idx] = need;
                now += need;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 15980
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define s(x) x.size()

using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e5+2;
const ll mod = 1e9+7;
int dp[SIZE];
int cnt[SIZE];


void solve(){
	int n; cin >> n;
	string s; cin >> s;
	stack<char> st;
	for(int i = 0; i < s(s); i++){
		if(st.empty()){
			st.push(s[i]);
		}else{
			if(st.top() != s[i]){
				st.push(s[i]);
			}
		}
	}
	cout << st.size() << endl;
}













int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int ans = 1900 * m + 100 * (n - m);
    ans = ans * (int)Math.pow(2, m);
    System.out.println(ans);
  }
}

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

int main(void) 
{
    int r;
    cin >> r;
    double PI = 3.14;
    cout << 2* r * PI << endl;
    return 0;
}

Measured memory_bytes: 3752
#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 dot[2003][2003];
int sum[2003][2003];
int N, K;

void prepare(void) {
    rep(i, K * 2 + 2) {
        rep(j, K * 2 + 2) {
            sum[i+1][j+1] = dot[i+1][j+1] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
            //cout << "s[" << i+1 << "][" << j+1 << "] = " << sum[i+1][j+1] << endl;
        }
    }
}

int query(int x1, int y1, int x2, int y2) {
    if(x1 > x2 || y1 > y2) return 0;
    else return sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1]; 
}


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

    cin >> N >> K;

    rep(i, N) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'W') y += K;
        x = x % (K * 2);
        y = y % (K * 2);
        //dump(x+1); dump(y+1);
        dot[x+1][y+1]++;
    }
    int ans = 0;
    int tmp;
    prepare();
    for(int x = 1; x <= K; x++) {
        for(int y = 1; y <= K; y++) {
            tmp = query(x, y, x+K-1, y+K-1) + query(x + K, y + K, K*2, K*2) + query(1,1,x-1,y-1)
                  + query(x+K, 1, K*2, y-1) + query(1, y+K, x-1, K*2); 
            //dump(tmp);
            ans = max(ans, max(tmp, N-tmp));
        }

    } 
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n, m;
int s1[102], s2[102];
bool ok(int a, int b) {
    swap(s1[a], s2[b]);
    int sum1 = 0, sum2 = 0;
    rep(i, n) sum1 += s1[i];
    rep(i, m) sum2 += s2[i];
    swap(s1[a], s2[b]);
    return sum1 == sum2;
}
void solve() {
    int ans[2] = {-1, -1};
    int mini = INF;
    rep(i, n) rep(j, m) {
        if (ok(i, j)) {
            if (mini > s1[i] + s2[j]) {
                ans[0] = s1[i];
                ans[1] = s2[j];
                mini = s1[i] + s2[j];
            }
        }
    }
    if (ans[0] == -1)
        cout << "-1" << endl;
    else
        cout << ans[0] << " " << ans[1] << endl;
}
int main() {
    while (cin >> n >> m, n) {
        rep(i, n) cin >> s1[i];
        rep(i, m) cin >> s2[i];
        solve();
    }
    return 0;
}

Measured memory_bytes: 3080
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

const int N = 1e6 + 5;
ll inv[N],arr[N],pf[N],mult[N];

void sieve(){
	for(int i = 1;i < N;i++)
		pf[i] = i;
	for(int i = 2;i * i <= N;i++){
		if(pf[i] == i){
			for(int j = 2;i * j < N;j++)
				pf[i * j] = i;
		}
	}
	return;
}

void pre()
{
	inv[1] = 1;
	for(ll i = 2;i < N;i++)
		inv[i] = mul(MOD - MOD / i,inv[MOD % i],MOD);
	sieve();
	return;
}

ll fp(ll x,ll y){
	if(y == 0) return 1;
	ll temp = fp(x,y / 2);
	temp = mul(temp,temp,MOD);
	if(y & 1)
		return mul(x,temp,MOD);
	else
		return temp;
}

void solve()
{
	int n;
	cin >> n;
	pre();
	for(int i = 0;i < n;i++)
	{
		cin >> arr[i];
		ll temp = arr[i];
		while(temp > 1)
		{
			ll div = pf[temp];
			ll cnt = 0;
			while(temp % div == 0)
				cnt++,temp /= div;
			mult[div] = max(mult[div],cnt);
		}
	}
	ll lcm = 1;
	for(int i = 2;i < N;i++)
		lcm = mul(lcm,fp(i * 1ll,mult[i]),MOD);
	ll res = 0;
	for(int i = 0;i < n;i++)
		res = add(res,inv[arr[i]],MOD);
	res = mul(res,lcm,MOD);
	cout << res << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	clock_t start,stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for(int tc = 1;tc < t + 1;tc++) solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 25216
k = int(input())

print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][k - 1])
   


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,D,X,A;
    cin>>N>>D>>X;
    int count=0;
    while(cin>>A){
    count+=(D-1)/A+1;
    }
    cout<<X+count<<endl;
    return 0;
}

Measured memory_bytes: 256
ary = []
['S', 'H', 'C', 'D'].each do |s|
  (1..13).each do |i|
    ary << "#{s} #{i}"
  end
end

n = gets.to_i
(1..n).each do |_x|
  ary -= [gets.chomp]
end
puts ary.join("\n") unless ary.empty?

Measured memory_bytes: 8668
using System;
namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            int n = int.Parse(Console.ReadLine());
            double debt = 100000;
            for (int i = 0; i < n; i++) {
                debt +=debt * 0.05;
                debt = Math.Ceiling(debt/1000)*1000;
            }
            Console.WriteLine((int)debt);
        }
    }
}

Measured memory_bytes: 5600
/// 1行の文字を空白で分割してVec<T>にする。
fn read_split<T : std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}


fn main() {
    let input : Vec<i64> = read_split();
    let vec_n = input[0];
    let vec_m = input[1];
    if vec_n * 2 > vec_m {
        println!("{}", vec_m / 2);
        return;
    }
    let vec_m = vec_m - (vec_n * 2);

    println!("{}", vec_n + (vec_m / 4));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 101, K = 1e5+10;

int n, k;
int a[N];
int dp[K][2];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < K; i++) {
    dp[i][0] = 1;
  }
  bool b = 1;
  for (int i = 0; i < n; i++, b ^= 1) {
    for (int j = 0; j <= k; j++) {
      dp[j][b] = (dp[j][b^1] + MOD - (j - a[i] - 1 >= 0 ? dp[j-a[i]-1][b^1] : 0)) % MOD;
    }
    for (int j = 1; j <= k; j++) {
      dp[j][b] = (dp[j-1][b] + dp[j][b]) % MOD;
    }
  }
  cout << (dp[k][b^1] + MOD - dp[k-1][b^1]) % MOD << nl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, char const *argv[]) {
  long long int a=0,x=0,y=1000000,z=0;
  scanf("%d",&a);
  int s[a];
  for (int i = 0; i < a; i++) {
    scanf("%d",&s[i]);
  }
  for (int i = 0; i < a; i++) {
    if (s[i]<y) {
      y=s[i];
      x++;
    }
    }
  printf("%d\n",x);
  return 0;
}


Measured memory_bytes: 896
use std::cmp;

const INF: i32 = 1 << 30;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc
        .read::<String>()
        .chars()
        .map(|c| c as usize - 'a' as usize)
        .collect::<Vec<_>>();

    let mut prefix_dp = vec![INF; 1 << 26];
    prefix_dp[0] = 0;

    let mut cur_mask: usize = 0;
    for c in s.into_iter() {
        cur_mask ^= 1 << c;
        if cur_mask.count_ones() <= 1 {
            prefix_dp[cur_mask] = 1;
        }
        for i in 0..26 {
            let suffix = 1 << i;
            let prefix = cur_mask ^ suffix;
            prefix_dp[cur_mask] = cmp::min(prefix_dp[cur_mask], prefix_dp[prefix] + 1);
        }
    }
    println!("{}", prefix_dp[cur_mask]);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 268540
H, W = map(int, input().split())
if H == 1 or W == 1:
  print(1)
elif W%2 == 0:
  print(int(H*W/2))
elif H%2 == 0 and W%2 == 1:
  print(int(H*(W-1)/2+H/2))
elif H%2 == 1 and W%2 == 1:
  print(int(H*(W-1)/2+(H+1)/2))
  

Measured memory_bytes: 2940
import java.util.*;

class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			int tmp=0;
			int now=i;
			while(now>0)
			{
				tmp+=now%10;
				now/=10;
			}
			if(tmp>=a && tmp<=b)
				ans+=i;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int n,i,j,k,c=0,l,h=0,height=-1,height0=-1;
	scanf("%d",&n);
	int a[n][3];
	for(i=0;i<n;i++)
		scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);

	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			for(k=0;k<n;k++){
				h=abs(i-a[k][0])+abs(j-a[k][1])+a[k][2];
				if(a[k][2]!=0 && height ==-1)
					height=h;
				if(h!=height && a[k][2]!=0)
					break;
				if(a[k][2]==0 && height0 ==-1)
					height0=h;
				if(a[k][2]==0 && height0>h)
					height0=h;
				c++;
			}
			if(c==n){
				if(height==-1){
					printf("%d %d %d",i,j,height0);
					return 0;
				}
				else if(height <= height0 || height0==-1){
					printf("%d %d %d",i,j,height);
					return 0;
				}
			}
			height=-1;
			height0=-1;
			c=0;
		}
	}
	return 0;
}
				

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


auto solve(long long A, long long B){
    return (A + B) % 24;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    auto result = solve(A, B);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long s, c, num=0;
    scanf("%ld %ld", &s, &c);
 
    if(s * 2 <= c){
        num += s;
        c = c - (s * 2);
        num += c / 4;
    } else {
        num += c / 2;
    }
    printf("%ld", num);
    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    ll n; std::cin >> n;
    ll a = 1;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i) continue;
        a = i;
    }
    ll b = n/a;
    std::cout << a-1+b-1 << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[1005]={},s1[100];
    int c=0,i;

    scanf("%s",&s1);
while(1){
    scanf("%s",&s);
    if(strcmp(s,"END_OF_TEXT")==0)
        {break;}
        for(i=0;s[i]!='\0';i++)
        if(s[i]<91) s[i] += 32;
       if(strcmp(s,s1)==0)
        {c++;}

    }
    printf("%d\n",c);


    return 0;
}



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

int main()
{
    int n, k;
    cin >> n >> k;
    ll h[n];
    rep(i, n) cin >> h[i];
    sort(h, h + n);
    ll sum = 0;
    rep(i, n - k) sum += h[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1920
open System

let N=stdin.ReadLine()|>int
let V=stdin.ReadLine().Split()|>Array.map int
let C=stdin.ReadLine().Split()|>Array.map int
[<EntryPoint>]
let main argv =
    [for i in [0..N-1] do yield (V.[i]-C.[i])]
    |>Seq.sumBy(fun c -> if c>0 then c else 0)
    |>stdout.WriteLine
    0

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int f=0;
	string s;
	cin>>s;
	int l=s.length();
	for(int i=0;i<l-1;i++)
	{
		if(s[i]==s[i+1])
     	{
			cout<<i+1<<" "<<i+2;
		    f=1;
			break;
		}
		else if(i<l-2 && s[i]==s[i+2])
		{
			cout<<i+1<<" "<<i+3;
			f=1;
			break;
		}
	}
	if(!f)
	cout<<"-1"<<" "<<"-1";
	return 0;
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
from collections import defaultdict

INF = float("inf")


def solve(N: int, X: int, D: int):
    if D == 0:
        if X == 0:
            print(1)
        else:
            print(N+1)
        return

    if D < 0:
        X = X + (N-1)*D
        D = abs(D)

    segs = defaultdict(list)
    for k in range(N+1):
        L = k*(k-1)//2
        R = k*N - k*(k+1)//2
        Ck = k*X + D*L
        Rk = R-L
        seg = (Ck//D, Ck//D+Rk+1)
        s = Ck % D
        segs[s].append(seg)

    tot = 0
    for k in segs:
        event = defaultdict(int)
        for l, r in segs[k]:
            event[l] += 1
            event[r] -= 1

        curr = 0
        pre = -1
        for k in sorted(event.keys()):
            if curr > 0:
                tot += k - pre
            curr += event[k]
            pre = k
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, X, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 71248
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.size()<=k) cout << s << endl;
  else {
    while(s.size()>k){
      s.pop_back();
    }
    cout << s << "..." <<endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

const int N = 100100;
int n, k;
ll a[N];
ll sum[N];
ll pref[N], suf[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sum[0] = 0;
	for (int i = 0; i < n; i++)
		sum[i + 1] = sum[i] + a[i];
	pref[0] = 0;
	for (int i = 0; i < n; i++)
		pref[i + 1] = pref[i] + max(0LL, a[i]);
	suf[n] = 0;
	for (int i = n - 1; i >= 0; i--)
		suf[i] = suf[i + 1] + max(0LL, a[i]);
	ll ans = 0;
	for (int i = 0; i + k <= n; i++)
		ans = max(ans, pref[i] + suf[i + k] + max(0LL, sum[i + k] - sum[i]));
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;
using Edges = vector<int>;
using Graph = vector<Edges>;
Graph graph;
vector<vector<int>> dist;
int id;

void dfs(int s, int par) {
    if (~par) dist[id][s] = dist[id][par] + 1;
    for (auto &next: graph[s]) {
        if (next != par) dfs(next, s);
    }

}

int main() {
    int n; cin >> n;
    graph.assign(n, Edges());
    dist.assign(2, vector<int>(n, 1e9));
    rep(i, n - 1) {
        int a, b; cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    id = 0;
    dfs(0, -1);
    id = 1;
    dfs(n - 1, -1);

    int ans = 0;
    rep(i, n) {
        if (dist[0][i] <= dist[1][i]) ++ans;
    }
    if (ans >= (n + 2) / 2) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}


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



typedef struct CARD{
    int num;
    char var;
}CARD;

#define NUM 100000

CARD A[NUM + 1];
CARD B[NUM + 1];

#define SENT 1000000000


void merge(CARD A[], int first, int mid, int last){
    
    int i,j,k, former, latter;
    CARD *L, *R, sent;
    
    sent.num = SENT;
    
    former = mid - first + 1;
    latter = last - mid;
    
    L = (CARD*)malloc(sizeof(CARD) * (former+1));
    R = (CARD*)malloc(sizeof(CARD) * (latter+1));
    
    for (i=0; i < former; i++) {
        L[i] = A[first + i];
    }
    L[former] = sent;
    
    for (i=0; i < latter; i++) {
        R[i] = A[i + mid + 1];
    }
    R[latter] = sent;
    
    j=k=0;
    for (i = first; i < last + 1; i++) {
        if (L[j].num <= R[k].num) {
            A[i] = L[j];
            j++;
        }
        else
        {
            A[i] = R[k];
            k++;
        }
    }
    return;
    
}

void MergeSort(CARD A[], int first, int last){
    
    int mid;
    
    if (first < last) {
        mid = (first + last)/2;
        MergeSort(A, first, mid);
        MergeSort(A, mid+1, last);
        merge(A, first, mid, last);
    }
    
    return;
}

int checkStable(CARD *A, CARD * B, int N){
    
    int  i = 0;
    int ans = 1;
    
    for (i = 0; i < N; i++) {
        if(A[i].num == B[i].num && A[i].var == B[i].var){
            continue;
        }
        else{
            ans = 0;
            break;
        }
    }
    return ans;
}

/*
 * *A int type array
 * left?????????A????????????????´??????????
 * right?????????A????????????????´??????????
 */
int partition(CARD *A, int left, int right){
    
    /*pivot??¨?????????????????????????´?????????¶*/
    CARD pivot = A[right];
    int i = left - 1;
    int j;
    CARD tmp;
    
    for (j=left; j<right; j++) {
        if (A[j].num <= pivot.num) {
            i = i+1;
            /* A[i] ??¨ A[j] ????????? */
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
        }
    }
    
    /* A[i+1] ??¨ A[r] ????????? */
    tmp = A[i+1];
    A[i+1] = A[right];
    A[right] = tmp;
    
    return i+1;   
}

/*
 * *A int type array
 * left?????????A????????????????´??????????
 * right?????????A????????????????´??????????
 */
void quicksort(CARD * A, int left, int right){
    
    int q;
    if (left < right) {
        q = partition(A, left, right);
        quicksort(A, left, q-1);
        quicksort(A, q+1, right);
    }
    
}


int main( ){
    
    int i, n, isStable;
    isStable = 1;
    
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        while (!getchar());
        scanf("%c %d", &(A[i].var), &(A[i].num) );
    }
    
    memcpy(B, A, sizeof(CARD)*n);
    
    quicksort(A, 0, n-1);
    MergeSort(B, 0, n-1);
    
    isStable = checkStable(A, B, n);
    
    if (isStable) {
        printf("%s\n", "Stable");
    }
    else{
        printf("%s\n", "Not stable");
    }
    
    
    for (i=0; i<n; i++) {
        printf("%c %d\n", A[i].var, A[i].num);
    }
    
    return 0;
}

Measured memory_bytes: 19436
#include <stdio.h>
#include <stdlib.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main(int argc, char *argv[])
{
  int n, m;
  scanf("%d %d", &n, &m);

  int k, *a;
  a = (int*)calloc(m, sizeof(int));

  int i,j;
  int buf;
  for(i=0;i<n;i++){
    scanf("%d", &k);
    for(j=0;j<k;j++){
      scanf("%d", &buf);
      a[buf-1]+=1;
    }
  }
  int counter=0;
  for(j=0;j<m;j++){
    if(a[j]==n)counter++;
  }
  printf("%d\n", counter);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ks ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
typedef pair<int,int>pa;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=1e6+177;
const ll mod=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
template<class T>inline void read(T &res){
    char c;T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
void wenjian(){freopen("concatenation.in","r",stdin);freopen("concatenation.out","w",stdout);}
void tempwj(){freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){a %= mod;ll ans = 1;while(b){if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}

int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.length();i++){
        
        if(s[i]!=t[i]){
            ans++;
        }
    }
    printf("%d\n",ans);

}


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

ans = 0
for i in range(1,n+1):
    if i%2==0:
        continue
    else:
        divcnt = 0
        for j in range(1,i+1):
            if i%j==0:
                divcnt += 1
            if divcnt == 8:
                ans += 1

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int A[n + 1] = {};
    for(int i = 0; i < n * (n - 1) / 2; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(c > d) A[a] += 3;
        else if(c < d) A[b] += 3;
        else
        {
            A[a]++;
            A[b]++;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        int r = 1;
        for(int j = 1; j <= n; j++)
        {
            if(A[i] < A[j]) r++;
        }
        cout << r << endl;
    }
    return 0;
}



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

using ll = long long;
constexpr ll INF = 1000000000;
constexpr ll mod = 1e9 + 7;

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; }

using namespace std;

//fixed << setprecision(10)

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

int main() {
	ll a,r;
	long double b;
	cin >> a >> b;

	b *= 100;
	b = round(b);

	r = a * b / 100;

	cout << r << endl;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

bool	ok(int n)
{
	int d = n, cnt = 0;

	while (d) {
		if (n % d == 0)
			cnt++;
		d--;
	}
	return (cnt == 8);
}

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

	int n;
	cin >> n;

	int ans = 0;

	while (n) {
		if ((n & 1) and ok(n))
			ans ++;
		n--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b;
  	ci(a>>b);
  st s;
  FOR(i,0,2*a){
    if(i%2==0){
      ci(s)
    }
    co(s)
  }
}


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

int main() {
	int n; cin >> n;
	vector<pair<int, int>> A(n - 1);
	vector<vector<int>> graph(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		A[i] = make_pair(a, b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	queue<int> q;
	vector<int> cs(n);
	map<pair<int, int>, int> map;

	q.emplace(0);

	int k = 0;
	while (!q.empty()) {
		auto v = q.front(); q.pop();

		k = max(k, (int) graph[v].size());
		int color = 1;

		for (auto u : graph[v]) {
			if (map.count(make_pair(u, v))) 
				continue;

			if (color == cs[v])
				color++;

			cs[u] = map[make_pair(u, v)] = map[make_pair(v, u)] = color;
			color++;
			q.emplace(u);
		}
	}

	cout << k << "\n";
	for (int i = 0; i < n - 1; i++) {
		cout << map[A[i]] << "\n";
	}
}

Measured memory_bytes: 19712
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238

typedef pair<int, int> P;
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    int suma = 0, sumb = 0;
    REP(i,n){
        cin>>a[i];
        suma+=a[i];
    }
    REP(i,n){
        cin>>b[i];
        sumb+=b[i];
    }
    if(suma<sumb) cout<<"-1"<<endl;
    else{
        vector<int> sa(n);
        int cnt = 0;
        int ans = 0;
        REP(i,n){
            sa[i]=a[i]-b[i];
            if(sa[i]<0){
                cnt+=sa[i];
                ans++;
            }
        }
        sort(all(sa),greater<int>());
        REP(i,n){
            if(cnt>=0) break;
            cnt+=sa[i];
            ans+=1;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 2560
n, k = map(int, input().split())

d = dict()

for _ in range(n):
    a, b = map(int, input().split())
    if a in d.keys():
        d[a] += b
    else:
        d[a] = b

d = sorted(d.items())

for a, b in d:
    k -= b
    if k <= 0:
        print(a)
        exit()


Measured memory_bytes: 14564
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    real(int64):: n,a,b,c,d,e
    read*, n
    read*, a
    read*, b
    read*, c
    read*, d
    read*, e

    print'(i0)', 5 + ceiling(n/minval([a,b,c,d,e]),kind=int64) -1
end program name

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

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, h.size()) cin >> h.at(i);

    int tmp = 0;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (h.at(i-1) < h.at(i))
            tmp = 0;
        else
            tmp++;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		int ss = s.length();
		if (k >= ss) {
			System.out.println(s);
		} else {
			String sss = s.substring(0, k);
			System.out.println(sss + "...");
		}

		sc.close();
	}
}

Measured memory_bytes: 27040
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int> crveni(n+1,false);
	vector<int> broj_na_topki(n+1,1);
	crveni[1]=true;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		if(!broj_na_topki[a])
			continue;
		if(crveni[a])
		{
			crveni[b]=true;		
		}
		broj_na_topki[a]--;
		broj_na_topki[b]++;
		if(!broj_na_topki[a])
			crveni[a]=false;
	}
	int brojac=0;
	for(int i=1;i<=n;i++)
	{
		if(crveni[i])
			brojac++;
	}
	cout<<brojac<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll N; cin >> N;

    if(N % 2 == 0){
        cout << N / 2 - 1 << endl;
    }else{
        cout << N / 2<< endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int A,B,C,X,ans=0;
    cin >> A >> B >> C >> X;

    for(int i=0; i<A+1; i++){
        for(int j=0; j<B+1; j++){
            for(int k=0; k<C+1; k++){
                if(500*i+100*j+50*k == X)
                    ans++;
            }
        }
    }

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



Measured memory_bytes: 380
#include<stdio.h>

int main(void){
  int a,b,c,k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  int x,i;
  x = 0;
  for(i = 0; i < k; i++) {
      if(a != 0) {
        x++;
        a--;
      } else if(b != 0) {
        b--;
      }else if(c != 0) {
        x--;
        c--;
      }
    }
    printf("%d", x);
    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=1e9+7;
int32_t main() {
    int n;
    cin>>n;
    int a[n];
    int p[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i!=0)p[i]=p[i-1]+a[i];
        else p[i]=a[i];
    }
    int sum=0;
    for(int i=0;i<n-1;i++){
        
        sum=(sum+(a[i]*((p[n-1]-p[i])%MOD)))%MOD;
    }
    cout<<sum%MOD<<"\n";
    return 0;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
long long num;
cin>>num;
string s="";
while(num){
    int mod=num%26;
    if(mod==0){
        s+='z';
        num/=26;
        num-=1;
    }
    else{
        s+='a'+mod-1;
        num/=26;
    }
}
reverse(s.begin(),s.end());
cout<<s;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  N%=1000;
  if(N==0) {
cout<<0<<endl;
  }
  else {
cout<<1000-N<<endl;
  }
}

Measured memory_bytes: 3604
#[allow(unused_imports)]
use proconio::input;
 
fn main() {
  input! {
    h: usize,
    w: usize,
    mut vals: [String;h]
  }
  let mut map: Vec<Vec<char>> = vec![];
  for val in vals {
    map.push(val.chars().collect());
  }
  
  let mut row = map.len()-1;
  let mut column = map[0].len()-1;
  while 0 <= row {
    let mut flag = true;
    for c in map[row].iter() {
      if c == &'#' {
        flag = false;
          break
      }
    }

    if flag {
      map.remove(row);
      if map.is_empty() { break }
      row = map.len() - 1;
      continue
    }

    if row == 0 { break }
    row -= 1;
  }
  
  row = map.len();
  while 0 <= column {
    let mut flag = true;
    for r in 0..row {
      let c = map[r][column];
      if c == '#' {
        flag = false;
        break
      }
    }

    if flag {
      for r in 0..row {
        map[r].remove(column);
      }
      if map[0].is_empty() { break }
      column = map[0].len() - 1;
      continue
    }

    if column == 0 { break }
    column -= 1;
  }
  
  for v in map {
    println!("{}", v.iter().collect::<String>());
  }
}

Measured memory_bytes: 2156
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a,c=0,d=0,i;
	int *b;
	scanf("%d",&a);
	b=(int *)malloc(a * sizeof(int));
	for(i=0;i<a;i++) scanf("%d",&b[i]);
	for(i=0;i<a-1;i++){
		if(b[i]>=b[i+1]) c++;
		else{
			if(d<c) d=c;
			c=0;
		}
	}
	if(d<c) d=c;
	printf("%d\n",d);
}

Measured memory_bytes: 512
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
#define pb push_back
#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;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,k,dp[maxn],ind[maxn],f,vis[maxn],d[maxn];
vector <int> mp[maxn];
const ll mod=1000000007;
queue <int> q;

int main()
{
	n=read(); k=read(); ll ans=1,f=0;
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		mp[u].pb(v); mp[v].pb(u); ind[u]++; ind[v]++;
	}
	rep(i,1,n) if(ind[i]==1) {f=i; break;}
	q.push(f); vis[f]=1; ans=k;
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(int i=0;i<mp[u].size();i++)
		{
			int v=mp[u][i];
			if(vis[v]) continue;
			q.push(v); vis[v]=1; d[u]++; d[v]++;
			ans=(ans*(k-d[u]))%mod;
		}
		//cout<<u<<" "<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef pair<int, int> P;

int main() {
    int N, M;
    cin >> N >> M;
    vector<P> v(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        v[i] = P(a, b);
    }
    sort(v.begin(), v.end());

    long long res = 0;
    int need = M;
    for (int i = 0; i < N; i++) {
        if (need <= 0) break;
        P p = v[i];
        int t = min(need, v[i].second);
        need -= t;
        res += (long long)t * v[i].first;
    }
    cout << res << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1000000000+7;

int main(){
	int H,W;
	cin>>H>>W;
	string s[H];
	REP(i,H)cin>>s[i];
	string num[H][W];
	REP(i,H){
		REP(j,W){
			if(s[i][j]=='#'){
				num[i][j]='#';
				continue;
			}
			int count=0;
			REP(k,8){
				int nx=j+dx[k];
				int ny=i+dy[k];
				if(nx<0 || nx>=W || ny<0 || ny>=H)continue;
				if(s[ny][nx]=='#')count++;
			}
			num[i][j]=to_string(count);
		}
	}
		REP(i,H){
			REP(j,W){
				cout<<num[i][j];
				if(j==W-1)cout<<endl;
			}
		}
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
int H,W,N;
int P=0,C=0;
scanf("%d", &H);
scanf("%d", &W);
scanf("%d", &N);
if(H > W)
{
    P = H;
}  
else
{
    P = W;
}
int i = 0; 
do
{
    C++;
    i = i +P;
}
while(i < N);
printf("%d\n",C);
return 0;
}


Measured memory_bytes: 1700
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// GCD : greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

// LCM : find Least Common Multiple (LCM) via GCD
func LCM(a, b int, integers ...int) int {
	result := a / GCD(a, b) * b

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}

// PfsMap : 素因数分解し、マップを作成
func PfsMap(n int) map[int]int {
	pfs := make(map[int]int)
	for n%2 == 0 {
		pfs[2] = pfs[2] + 1
		n = n / 2
	}

	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs[i] = pfs[i] + 1
			n = n / i
		}
	}

	if n > 2 {
		pfs[n] = pfs[n] + 1
	}

	return pfs
}

func main() {
	sc.Split(bufio.ScanWords)
	x, y := getInt(), getInt()

	if x%y == 0 {
		out(-1)
		return
	}

	out(x)
}


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

const int MAX_RC = 3005;
int R, C, K;
int64_t mem[MAX_RC][MAX_RC][4];
int64_t grid[MAX_RC][MAX_RC];

int64_t dp(int r, int c, int count) {
  if (r == R - 1 && c == C - 1) {
    return count != 3 ? grid[r][c] : 0;
  }
  if (r >= R || c >= C) return LONG_LONG_MIN/2;
  if (mem[r][c][count] != -1) return mem[r][c][count];
  // Without picking up:
  int64_t best = dp(r + 1, c, 0);
  best = std::max(best, dp(r, c+1, count));
  // With picking up:
  if (count != 3) {
    best = std::max(best, dp(r + 1, c, 0) + grid[r][c]);
    best = std::max(best, dp(r, c+1, count+1) + grid[r][c]);
  }
  mem[r][c][count] = best;
  return best;
}

int main() {
  scanf("%d %d %d", &R, &C, &K);
  memset(mem, -1, sizeof(mem));
  for (int k = 0; k < K; ++k) {
    int r, c;
    int v;
    scanf("%d %d %d", &r, &c, &v);
    r--;
    c--;
    grid[r][c] = v;
  }
  printf("%lld\n", dp(0, 0, 0));
}


Measured memory_bytes: 356812