akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, x;
    ll count = 0;
    vector<ll> A;
    cin >> N >> x;
    A.resize(N);
    for(ll i = 0;i < N;i++) cin >> A[i];
    sort(A.begin(), A.end());
    for(auto &i: A) {
        if(x < i) {
            break;
        } else {
            count++;
            x -= i;
        }
    }
    if(count == N && x) count--;
    cout << max(0LL, count) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int N;
	static int[] L = new int[10];
	
	static int max = 0, sum = 0;
	
	static Scanner scanner = new Scanner(System.in);
	
	public static void main(String args[]) {
		Input();
		Findmax();
		Sumothers();
		Compare();
		
		return;
	}
	
	static void Input() {
		N = scanner.nextInt();
		for(int i=0; i<N; i++) {
			L[i] = scanner.nextInt();
		}
		return;
	}
	static void Findmax() {
		for(int i=0; i<N; i++) {
			if(max < L[i])max = L[i];
		}
		return;
	}
	static void Sumothers() {
		for(int i=0; i<N; i++) {
			sum += L[i];
		}
		sum -= max;
		return;
	}
	static void Compare() {
		if(max < sum)System.out.print("Yes");
		else System.out.print("No");
	}
	
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    set<int> st;
    REP(i,n) {
        int x; cin >> x;
        st.insert(x);
    }

    CFYN(st.size()== n)

    return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdbool.h>


typedef  long long ll;

int int_cmp(const void *a, const void *b){ 
    const int *ia = (const int *)a;
    const int *ib = (const int *)b;
    return *ia  - *ib; 
} 



int max(int a,int b){
	if(a<b)
		a=b;
	return a;	
}

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

int absolu(int n){
	if(n<0)
		n*=-1;
	
	return n;	
}


void solve(){
int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	
	while(k>0){
		if(b>=c)
			c*=2;
		else if(a>=b)
			b*=2;	
		k--;	
	}
	
	if(a<b && b<c)
		printf("Yes\n");
	else 
		printf("No\n");	
}



int main(){
   /*int t;
	scanf("%d",&t);
	
	while(t--)*/
		solve();
	
	
	
	return 0;
}	
					

Measured memory_bytes: 1652
N = int(input())
MB = {}; MW = {}
for i in range(2*N):
    c, a = input().split()
    c = "BW".index(c); a = int(a)
    if c:
        MW[a-1] = i
    else:
        MB[a-1] = i

P = [[0]*(N+1) for i in range(N+1)]
Q = [[0]*(N+1) for i in range(N+1)]

for p in range(N):
    cnt = MW[p] - sum(MW[p0] < MW[p] for p0 in range(p))

    P[p][0] = cnt
    for q in range(N):
        if MB[q] < MW[p]:
            cnt -= 1
        P[p][q+1] = cnt

for q in range(N):
    cnt = MB[q] - sum(MB[q0] < MB[q] for q0 in range(q))

    Q[q][0] = cnt
    for p in range(N):
        if MW[p] < MB[q]:
            cnt -= 1
        Q[q][p+1] = cnt

dp = [[10**9]*(N+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    dp[i+1][0] = dp[i][0] + P[i][0]
for i in range(N):
    dp[0][i+1] = dp[0][i] + Q[i][0]
for i in range(N):
    for j in range(N):
        dp[i+1][j+1] = min(dp[i][j+1] + P[i][j+1], dp[i+1][j] + Q[j][i+1])
print(dp[N][N])

Measured memory_bytes: 147928
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = -1
f = False
for i in range(3):
    for j in range(3):
        if (a[0][0] == a[0][1] == a[0][2]== -1) or (a[1][0] == a[1][1] == a[1][2]== -1) or (a[2][0] == a[2][1] == a[2][2]== -1):
            f = True
        elif (a[0][0] == a[1][0] == a[2][0] == -1) or (a[0][1] == a[1][1] == a[2][1] == -1) or (a[0][2] == a[1][2] == a[2][2] == -1):
            f = True
        elif (a[0][0] == a[1][1] == a[2][2] == -1) or (a[2][0] == a[1][1] == a[0][2] == -1):
            f = True
if f:
    print('Yes')
else:
    print('No')

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

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	std::vector<std::pair<int, int>> jobs(N);
	for (auto& e: jobs) scanf("%d%d", &e.first, &e.second);
	std::sort(jobs.begin(), jobs.end());
	jobs.push_back({1 << 30, -1});
	int j_i{};
	std::priority_queue<int> pq;
	int64_t ans{};
	for (int i{M - 1}; i >= 0; i--)
	{
		while (i + jobs[j_i].first <= M)
		{
			pq.push(jobs[j_i].second);
			j_i++;
		}
		if (pq.empty()) continue;
		ans += pq.top();
		pq.pop();
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1904
#include<iostream>
#include<cmath>
using namespace std;
main(){
  long long a,b,c,k,ans;
  cin >> a>>b>>c>>k;
  if(a==max(max(a,b),c) )ans=a*pow(2,k) +b+c;
  else if(b==max(b,c))ans=b*pow(2,k) +a+c;
  else ans=c*pow(2,k)+a+b;
     
     cout<<ans<<endl;
     return 0;
     }
  

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let b: Vec<i64> = sc.read_vec(n);

    let a_sum = a.iter().sum::<i64>();
    let b_sum = b.iter().sum::<i64>();
    if a_sum < b_sum {
        println!("-1");
        return;
    }

    let mut good = vec![];
    let mut bad = vec![];
    for i in 0..n {
        if a[i] > b[i] {
            good.push((a[i], b[i]));
        } else if a[i] < b[i] {
            bad.push((a[i], b[i]));
        }
    }

    let mut required = bad.iter().map(|&(a, b)| b - a).sum::<i64>();
    good.sort_by_key(|&(a, b)| a - b);
    good.reverse();

    let mut used_goods = 0;
    for &(a, b) in good.iter() {
        if required <= 0 {
            break;
        }
        used_goods += 1;
        required -= a - b;
    }

    assert!(required <= 0);
    println!("{}", used_goods + bad.len());
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_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: 10492
from collections import defaultdict

n,k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
    print(0)
    exit()
s = [0]
for i in a:
    s.append((s[-1]+i-1)%k)

d = defaultdict(int)
d[0] = 1
ans = 0
for r in range(1, n+1):
    sr = s[r]
    if d[sr]>0:
        ans += d[sr]
    d[sr] += 1
    l = r-k+1
    if l >= 0:
        d[s[l]] -= 1
print(ans)

Measured memory_bytes: 112408
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long a; cin >> a;
    long b;
    int cnt = 0;
vector<long> v(a);
for(int i=0;i<a;i++)cin >> v[i];
sort(v.begin(),v.end());
if(a >= 3){for(int i=0;i<a-2;i++){
    for(int j=i+1;j<a-1;j++){
        for(int k=j+1;k<a;k++){
            b = v[i] + v[j];
            if(b > v[k]){
                if(v[i] != v[j] && v[j] != v[k] && v[i] != v[k])cnt++;
            }
        }
    }
}
cout << cnt << endl;
}else cout << 0 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    bool is_ex[8];
    rep(i, 8) is_ex[i] = false;
    int over_count = 0;
    rep(i, N){
        rep(j, 8){
            if(a[i] >= 400 * j && a[i] < 400 * (j + 1)) is_ex[j] = true;
        }
        if(a[i] >= 3200) over_count++;
    }
    int unover_count = 0;
    rep(i, 8) if(is_ex[i] == true) unover_count++;
    if(unover_count == 0) cout << 1 << " " << unover_count + over_count << endl;
    else cout << unover_count << " " << unover_count + over_count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;

int main() {
    cin >> n;

    bool f = false;
    for (int i = 1; i <= 9; i++) {
        if (n % i == 0 &&
            n / i / 10 == 0) f = true;
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : January 18 2020 17:56:47 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const int INF=1e9;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n,k,s;
    cin >> n >> k >> s;
    vi a(n);
    fori(i,k) a[i] = s;
    int rem = (s == INF ? s - 1 : INF);
    rep(i,k,n-1) a[i] = rem;
    fori(i,n){
        cout << a[i] << " ";
    }
    cout << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 1792
X, Y = map(int, input().split())

res = 0
mod = 10 ** 9 + 7

def IsPositiveAndInt(num):
    return int(num)-num == 0.0 and num >= 0

# Copy from https://atcoder.jp/contests/abc145/submissions/8515099
def Comb(n, r, mod=mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

if (X+Y) % 3 == 0:
    A = (2*X-Y) / 3
    B = (-X + 2*Y) / 3
    if IsPositiveAndInt(A) and IsPositiveAndInt(B):
        A, B = int(A), int(B)
        res = Comb(A+B, A, mod)
        
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 40005;
const double eps = 1e-8;

struct Point {
	double x, y;
	
	void read() {
		scanf("%lf%lf", &x, &y);
	}
};
double mat[25][25];

int n;
Point p[N];

double sqr(double x) {
	return x * x;
}

void init() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		p[i].read();
	}
}

void gauss() {
	for (int i = 1; i <= 3; i ++) {
		int best;
		double cc = -5.0;
		
		for (int j = i; j <= 3; j ++) {
			if (abs(mat[j][i]) > cc) {
				cc = abs(mat[j][i]);
				best = j;
			}
		}
		for (int j = 1; j <= 4; j ++) {
			swap(mat[i][j], mat[best][j]);
		}
		
		for (int j = i + 1; j <= 3; j ++) {
			if (abs(mat[j][i]) > eps) {
				double t = mat[i][i] / mat[j][i];
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] *= t;
				}
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] -= mat[i][k];
				}
			}
		}
	}
	
	double ans[5];
	for (int i = 3; i >= 1; i --) {
		if (abs(mat[i][i]) > eps) {
			ans[i] = mat[i][4] / mat[i][i];
		} else {
			ans[i] = 0.0;
		}
		for (int j = i - 1; j >= 1; j --) {
			mat[j][4] -= mat[j][i] * ans[i];
		}
	}
	
	for (int i = 1; i <= 3; i ++) {
		printf("%.3f%c", ans[i], i == 3 ? '\n' : ' ');
	}
}

void work() {
	for (int i = 1; i <= n; i ++) {
		double tmp[6];
		tmp[1] = p[i].x, tmp[2] = p[i].y;
		tmp[3] = 1.0, tmp[4] = p[i].x * p[i].x + p[i].y * p[i].y;
		
		for (int j = 1; j <= 4; j ++) {
			mat[1][j] += tmp[j] * p[i].x;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[2][j] += tmp[j] * p[i].y;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[3][j] += tmp[j];
		}
	}
	for (int i = 1; i <= 3; i ++) {
		mat[i][4] *= -1.0;
	}
	
	gauss();
}

int main() {
	//freopen("A.in", "r", stdin);
	//ios::sync_with_stdio(false);
	
	init(), work();
	
	return 0;
}

Measured memory_bytes: 1904
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vs32 A;

bool solve(int m, int idx)
{
    if (m == 0)
    {
        return true;
    }
    else if (idx == A.size())
    {
        return false;
    }
    return solve(m - A[idx], idx + 1) || solve(m, idx + 1);
}

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

    int n, q;
    cin >> n;
    A.resize(n);
    rep (i, n) cin >> A[i];

    cin >> q;
    vs32 m(q);
    rep (i, q) cin >> m[i];

    rep (i, q)
    {
        if (solve(m[i], 0))
        {
            cout << "yes\n";
        }
        else
        {
            cout << "no\n";
        }
    }

    return 0;
}



Measured memory_bytes: 3212
#pragma GCC optimize("Ofast")
/*#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                      
using namespace std;
                      
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                      
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define prev prev228
#define list list228

const int MOD = 2286661337;

mt19937 rnd(rand());

struct node
{
	int x, y, mx, sz;
	int sum;
	node *l, *r;
	node(int _x) {
		x = mx = sum = _x;
		y = rnd() % MOD;
		sz = 1;
		l = r = NULL;
	}
};

int get_sz(node *v) {
	if (!v) return 0;
	return v->sz;
}

int get_mx(node *v) {
	if (!v) return -MOD;
	return v->mx;
}

int get_sum(node *v) {
	if (!v) return 0;
	return v->sum;
}

void update(node *&v) {
	if (v) {
		v->sz = 1 + get_sz(v->l) + get_sz(v->r);
		v->mx = max(v->x, max(get_mx(v->l), get_mx(v->r)));
		v->sum = v->x + get_sum(v->l) + get_sum(v->r);
	}
}

void split(node *v, int x, node *&l, node *&r) {
	if (!v) {
		l = r = NULL;
		return;
	}
	if (1 + get_sz(v->l) <= x) {
		l = v;
		split(v->r, x - 1 - get_sz(v->l), l->r, r);
		update(l);
	} else {
		r = v;
		split(v->l, x, l, r->l);
		update(r);
	}
}

node* merge(node *a, node *b) {
	if (!a) return b;
	if (!b) return a;
	if (a->y > b->y) {
		a->r = merge(a->r, b);
		update(a);
		return a;
	}
	b->l = merge(a, b->l);
	update(b);
	return b;
}

int find_pos(node *v, int x) {
	if (!v) return 0;
	if (v->x == x) return 1 + get_sz(v->l);
	if (x > v->x) return 1 + get_sz(v->l) + find_pos(v->r, x);
	return find_pos(v->l, x);
}

node *L, *M, *R;

void insert(node *&v, int x, int pos) {
	split(v, pos, L, R);
	v = merge(L, merge(new node(x), R));
}

int ith(node *v, int pos) {
	if (1 + get_sz(v->l) == pos) return v->x;
	if (1 + get_sz(v->l) < pos) return ith(v->r, pos - 1 - get_sz(v->l));
	return ith(v->l, pos);
}

int get(node *v, int l, int r) {
	split(v, l - 1, L, v);
	split(v, r - l + 1, M, R);
	int ans = get_sum(M);
	v = merge(L, merge(M, R));
	return ans;
}

ghost main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int Q;
	cin >> Q;
	node *v = NULL;
	int cnt = 0;
	int add = 0;
	while (Q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int a, b;
			cin >> a >> b;
			add += b;
			insert(v, a, find_pos(v, a));
			++cnt;
		} else {
			int mid = (cnt + 1) >> 1;
			int x = ith(v, mid);
			int ans = add;
			ans += x * mid - get(v, 1, mid);
			ans += get(v, mid + 1, cnt) - x * (cnt - mid);
			cout << x << " " << ans << '\n';
		}
	}
	return 0;
} // kek ;





Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];
    ll c = 1000;
    ll x = 0;
    ll now = 1000;

    rep(i,0,N){
        if(now <= A[i])now = A[i];
        else{
            c += now*x;
            x = 0;
            x = c/A[i];
            c -= (c/A[i]) * A[i];
            now = A[i];
        }
    }

    cout<<c + now*x;
    return 0;
}

Measured memory_bytes: 3624
from collections import deque
N = int(input())
nums = ['3', '5', '7']
now = ''
q = deque(nums)
ans = 0
flag = True
while flag:
    n = q.popleft()
    for num in nums:
        tmp = n
        tmp += num
        if int(tmp) > N:
            flag = False
            break
        if '3' in tmp and '5' in tmp and '7' in tmp:
            ans += 1
        q.append(tmp)

print(ans)

Measured memory_bytes: 10544
n = gets.chomp.to_i
s = gets.chomp
array = s.split(" ").map(&:to_i)
 
ans = 10**15
 
a = array.inject(:+)
b = 0
for i in 0..(n-2)
  a -= array[i]
  b += array[i]
  if (a-b).abs<ans
    ans = (a-b).abs
  end
end
 
puts ans


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

const int mod = 1000000007;
int dp[100005][2];

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i, n)
    {
        { // a+b = 0
            if (s[i] == '0')
            {
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
            }
            else
            {
                dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
            }
        }
        { // a+b = 1
            if (s[i] == '0')
            {
                (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
            }
            else
            {
                (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
                (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
            }
        }
    }
    int ans = (dp[n][0] + dp[n][1]) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
#define read(n) scanf("%d",&n)
#define f(i,a,b) for(int i=a;i<=b;++i)
char turn(int x)
{
	return x+'a'-1;
}
int main()
{
	ll n;
	cin>>n;
	int str[1005]={0};
	int len=0;
	while(n)
	{
		if(n%26==0) str[++len]=26,--n;
		else str[++len]=n%26;
		n/=26;
	}
	for(int i=len;i>=1;--i) cout<<turn(str[i]);
	return 0;
}

Measured memory_bytes: 3624
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vs s(n);
  rep(i, n){
    cin >> s[i];
  }
  map<string, ll> cnt;
  rep(i, n){
    cnt[s[i]]++;
  }
  ll ma = -INF;
  for(auto&& e: cnt){
    chmax(ma, e.second);
  }
  for(auto&& e: cnt){
    if(e.second == ma){
      print(e.first);
    }
  }
}


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

/*template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}*/
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

 // const long long INF = 1LL << 60;
  long long dp[100010][3];
  long long a[100010][3];
  for(int i = 0; i < 100010; i++){
    for(int j = 0; j < 3; j++){
      cin >> a[i][j];
    }
  }
for(int j = 0; j < 3; j++){
	dp[0][j] = 0;
}
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
      	if(j != k){
     	 	chmax(dp[i+1][k], dp[i][j]+ a[i][k]);
      	} 
      }         	
    }
  }

  cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
  
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

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

	if (N == 3) printf("2 5 63\n");
	else if (N == 4) printf("2 5 20 63\n");
	else if (N == 5) {
		printf("2 5 20 63 30\n");
	}
	else{
		ll sum = 0;
		int tot = 0, num = 2, cnt = 0;
		map<int, bool> mp;
		while (cnt < N) {
			if (num % 2 == 0 || num % 3 == 0) {
				mp[num] = true;
				cnt++;
				tot += num;
				tot %= 6;
				sum += num;
			}
			num++;
		}

		//cout << "tot1=" << tot << endl;
		//cout << "sum1=" << sum << endl;
		if (tot % 6 == 2) {
			mp[8] = false;
			while (num % 6 != 0) {
				num++;
			}
			mp[num] = true;
			sum += num-8;
			tot = (tot + num-8) % 6;
		}

		else if (tot % 6 == 3) {
			mp[9] = false;
			while (num % 6 != 0) {
				num++;
			}
			mp[num] = true;
			sum += num-9;
			tot = (tot + num-9) % 6;
		}

		else if (tot % 6 == 5) {
			mp[8] = false;
			while (num % 6 != 3) {
				num++;
			}
			mp[num] = true;
			sum += num-8;
			tot = (tot + num-8) % 6;
		}
		
		//cout << "tot2=" << tot << endl;
		//cout << "sum2=" << sum << endl;
		for (int i = 2; i <= 3e4; i++) {
			if (mp[i])cout << i << " ";
		}
		cout << endl;
	}
}


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

class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

}



public class Main {

    public static PrintWriter out;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next();
        String t = sc.next();
        String sub = t.substring(0,t.length()-1);
        if (sub.equals(s)){
            out.println("Yes");
        }else {
            out.println("No");
        }
        out.close();
    }

}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
typedef long long ll;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(A * B, C * D) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O3","Ofast")
using namespace std;

template<class T> ostream& operator<<(ostream &os,vector<T> V){os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";}
template<class L,class R> ostream& operator<<(ostream &os,pair<L,R> P){return os<<"("<<P.first<<","<<P.second<<")";}
#define DEBUG1(x) cout  << '>' << " " << #x << ':' << " " <<  x << endl;
#define DEBUG2(x,y) cout  << '>' << " " << #x << ':' << " " <<  x <<  " " << #y << ':' << " " <<  y <<endl;
#define DEBUG3(x,y,z) cout  << '>' << " " << #x << ':' << " " <<  x << " " << #y << ':' << " " <<  y <<" " << #z << ':' << " " <<  z << " " <<endl;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define TC int t; cin >> t;while(t--)
#define forn(i,n) for(int i=0;i<n;i++)

#define ALL(x) x.begin(),x.end()
#define LL long long int
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define endl "\n"

typedef pair<int,int>PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<PII> VPII;

const int mod = 10*9+7;
const int inf = 2e9;
const LL linf = 2e18;
const double eps = 1e-9;

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

int main(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    int arr[n];
    forn(i,n){
        cin >> arr[i];
    }
    int dp[n ];
    fill(dp, dp + n, inf);
    dp[0] = 0;
    for (int i = 1; i < n;i++){
        for (int j = 1; j <=k;j++){
            if(i-j>=0){
                dp[i] = min(dp[i],dp[i - j] + abs(arr[i] - arr[i-j]));
                //DEBUG2(dp[i-j],abs(arr[i] - arr[j]))
            }
        }
    }
    cout << dp[n - 1] << endl;

        return 0;
}

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

using namespace std;

int main(){
  int a=0,b=0;
  char s[100000];
  cin >>s;
  sort(s,s+strlen(s));
  for(int i=0;i<strlen(s);i++){
    if(s[i]=='0')a++;
     if(s[i]=='1')b++;
  }
  cout <<min(a,b)*2;
 
}

Measured memory_bytes: 384
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
#include <list>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int main(){
    int n;cin >> n;
    string s;cin >> s;
    if (n % 2 != 0){ cout << "No" << endl;return 0;}
    else{
        for(int i=0;i<(n/2);i++){
            if (s[i] != s[i+(n/2)]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
def die():
	x = int(raw_input())
	ans = (x/11)*2
	x = x%11
	c_sum = 0
	_temp = 5
	while c_sum<x:
		if _temp==5:
			c_sum+=6
			_temp=6
			ans+=1
		else:
			c_sum += 5
			_temp = 5
			ans += 1
	print ans

if __name__ == "__main__":
	die()

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

int main(){
	
	/*
	for(int i=0; i<7; i++){
		int a,b;
		cin >> a >> b;
		cout << a - b <<endl;
		*/
	/*
	for(int i=0; i<4; i++){
		int T, K;
		cin >> T >> K;
		if(T == 1){
			cout << K*6000 << endl;
		}
		else if(T == 2){
			cout << K*4000 << endl;
		}
		else if(T == 3){
			cout << K*3000 << endl;
		}
		else{
			cout << K*2000 << endl;
		}

	}
	*/
	/*
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int x, y, b, p;
		cin >> x >> y >> b >> p;

		if(b >= 5 && p >= 2){
			cout << (x*b + y*p)*4/5 << endl;
		}

		else{
			cout << min(x*b + y*p,(x * max(b,5) + y * max(p,2))*4/5 ) << endl;
		}
	}
	*/
	/*	
	for(int data = 0; data<100; data++){
		int n;
		cin >> n;
		if(n == 0)return 0;

		int  N = n;
		bool jud = false;

		for(int i=0; i<n; i++){
			int k;
			cin >> k;
			if(k == 0) N--;
			else if(k > 1)jud = true;
		}

		if(jud == false) cout << "NA" << endl;
		else cout << N+1 << endl;


	}
	*/

	for(int D = 0; D < 100; D++){

		int n;
		cin >> n;
		if(n == 0)return 0;
		int hand[10] = {};
		int ba = 0;

		string top;
		cin >> top;

		for(int i=0; i<100; i++){
			if(top[i] == 'M') hand[i%n]++;
			if(top[i] == 'S'){
				ba += hand[i%n]+1;
				hand[i%n] = 0;
			}
			if(top[i] == 'L'){
				hand[i%n]+=ba+1;
				ba = 0;
			}
		}

		sort(hand,hand+n);

		for(int i=0; i<n; i++){
			cout << hand[i] << " ";
		}
		cout << ba << endl;

	}

	return 0;

}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int k,s;cin>>k>>s;
    int ans=0;
    for (int i=0;i<=k;i++){
        for (int j=0;j<=k;j++){
            if ((i+j)>s)break;
            if (s-(i+j)<=k){
                ans++;
            }
        }
    }cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nk = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var p = (long)Math.Pow(10, 9) + 7;
            for (var i = 1; i <= nk[1]; i++)
            {
                var continuousBlue = CombinationCount(nk[0] - nk[1] + 1, i, p);
                var modBlue = CombinationCount(nk[1] - 1, i - 1, p);
                Console.WriteLine((continuousBlue * modBlue) % p);
            }
        }

        static long PermutationCount(long n, long k, long mod)
        {
            if (n < k) return 0;
            var result = 1L;
            for (var i = 0; i < k; i++)
                result = (result * (n - i) % mod) % mod;
            return result;
        }

        static long CombinationCount(long n, long k, long mod)
        {
            if (n < k) return 0;
            k = Math.Min(k, n - k);
            var top = PermutationCount(n, k, mod);
            var bottom = PermutationCount(k, k, mod);
            return (top * Power(bottom, mod - 2, mod)) % mod;
        }

        static long Power(long x, long y, long mod)
        {
            var result = 1L;
            while (y > 0)
            {
                if ((y & 1) == 1) result = ((result % mod) * (x % mod)) % mod;
                x = ((x % mod) * (x % mod)) % mod;
                y >>= 1;
            }
            return result;
        }
    }
}


Measured memory_bytes: 13396
n = gets.chomp.to_i

dp = Array.new(n){Array.new(3, 0)}
a = gets.split.map(&:to_i)
dp[0][0] = a[0]
dp[0][1] = a[1]
dp[0][2] = a[2]
 
(1..(n - 1)).each do |i|
  b = gets.split.map(&:to_i)
  (0..2).each do |j|
    (0..2).each do |k|
    next if k == j
    cost = dp[i - 1][k] + b[j]
    dp[i][j] = cost if cost > dp[i][j]
   end
  end
end
puts [dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]].max

Measured memory_bytes: 9340
N = int(input())
h = [int(v) for v in input().split()]

ans = 0
while True:
    left = 0
    right = 0
    num_zero = 0
    for i in range(N):
        if h[i] == 0:
            if left != right:
                h[left:right] = [v - 1 for v in h[left:right]]
                ans += 1
            left = i + 1
            right = i + 1
            num_zero += 1
        else:
            right += 1
    if num_zero == N:
        break
    if h[N-1] != 0:
        h[left:right] = [v - 1 for v in h[left:right]]
        ans += 1

print(ans)


Measured memory_bytes: 3064
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, m;
  cin >> n;
  string s[n];
  REP(i, n) cin >> s[i];
  cin >> m;
  string t[m];
  REP(i, m) cin >> t[i];

  ll sum, ans = 0;
  REP(i, n + m){
    sum = 0;
    string p = (i < n) ? s[i] : t[i - n];
    REP(j, n){
      if(s[j] == p) sum++;
    }
    REP(j, m){
      if(t[j] == p) sum--;
    }
    ans = max(ans, sum);
  }
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

        string s;cin>>s;
        if( s == "KIHBR" || s == "AKIHBR"||s=="KIHABR"||s=="KIHBAR"||s=="KIHBRA"||
                s== "AKIHABR"||s=="AKIHBAR"||s=="AKIHBRA"||s=="KIHABAR"||s=="KIHABRA"||
                s=="KIHBARA"||s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="KIHABARA"||
                s=="AKIHABARA"){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        
        
        
        

    return 0;
}

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

int main() {
  string s, t, u;
  cin >> s >> t >> u;
  char a, b, c;
  a = s.at(0);
  b = t.at(1);
  c = u.at(2);
  cout << a << b << c << endl;
}

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

int Max(int*, int);
int Min(int*, int);
int Abs(int, int);

int main() {
    int N = 0;
    int* A = NULL;
    int max = 0;
    int min = 0;
    int abs = 0;
    
    cin >> N;
    A = new int[N]; //キーボードから入力したN個分のメモリを確保
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    max = Max(A,N);
    min = Min(A,N);
    abs = Abs(max, min);

    delete[] A;
    cout << abs << endl;
    
    return 0;
}


int Max(int* A, int size) {
    int max = A[0];
    for (int i = 1; i < size; i++) {
        if (max < A[i]) {
            max = A[i];
        }
    }
    return max;
}

int Min(int* A, int size) {
    int min = A[0];
    for (int i = 1; i < size; i++) {
        if (min > A[i]) {
            min = A[i];
        }
    }
    return min;
}

int Abs(int a, int b) {
    if ((a - b) >= 0) {
        return (a - b);
    }else {
        return (-1 * (a - b));
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
 
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
 
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
 
int main() {
 
	int A, B, ans;
 
	cin >> A >> B;
 
	ans = A*B;
 
	cout << ans << endl;
 
	return 0;
 
 
}

Measured memory_bytes: 3636
#include <queue>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
int H, W, ax, ay, bx, by, x[52][52], dp[52][52][52][52];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main() {
	while(cin >> W >> H >> ax >> ay >> bx >> by) {
		for(int i = 0; i < H + 2; i++) {
			for(int j = 0; j < W + 2; j++) {
				x[i][j] = 1;
				if(i && i != H + 1 && j && j != W + 1) scanf("%d", &x[i][j]);
			}
		}
		memset(dp, -1, sizeof(dp)); dp[ay][ax][by][bx] = 0;
		queue<vector<int> > que; que.push({ax, ay, bx, by});
		bool flag = false;
		while(!que.empty()) {
			vector<int> v1 = que.front(); que.pop();
			for(int i = 0; i < 4; i++) {
				vector<int> v2 = v1;
				if(!x[v1[1] + dy[i]][v1[0] + dx[i]]) v2[0] += dx[i], v2[1] += dy[i];
				if(!x[v1[3] - dy[i]][v1[2] - dx[i]]) v2[2] -= dx[i], v2[3] -= dy[i];
				if(v2[0] == v2[2] && v2[1] == v2[3]) {
					flag = true; break;
				}
				if(dp[v2[1]][v2[0]][v2[3]][v2[2]] == -1) {
					dp[v2[1]][v2[0]][v2[3]][v2[2]] = dp[v1[1]][v1[0]][v1[3]][v1[2]] + 1;
					que.push(v2);
				}
			}
			if(dp[v1[1]][v1[0]][v1[3]][v1[2]] >= 100) break;
			if(flag) {
				cout << dp[v1[1]][v1[0]][v1[3]][v1[2]] + 1 << endl; break;
			}
		}
		if(!flag) cout << "NA" << endl;
	}
}

Measured memory_bytes: 32372
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    string s,cp_s;
    cin >> s;
    cp_s = s;
    int count_1,count_2;
    count_1 = count_2 = 0;
    //1start
    for(int i = 0; i < s.size() - 1; i++){
        if(i == 0){
            if(s[0] == '0'){
                s[0] = '1';
                count_1++;
            }
        }
        if(s[i] == s[i+1]){
            if(s[i+1] == '1') s[i+1] = '0';
            else s[i+1] = '1';
            count_1++;
        }
    }
    //0スタート
    for(int i = 0; i < cp_s.size() - 1; i++){
        if(i == 0){
            if(cp_s[i] == '1'){
                cp_s[0] = '0';
                count_2++;
            }
        }
        if(cp_s[i] == cp_s[i+1]){
            if(cp_s[i+1] == '1') cp_s[i+1] = '0';
            else cp_s[i+1] = '1';
            count_2++;
        }
    }
//    cout << count_1 << cp_s << endl;
    int ans = min(count_1, count_2);
    cout << ans << endl;    
}

Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var line, err = nextLine()
	if err != nil {
		fmt.Fprintf(os.Stderr, "wtf")
	}
	var nums = make([]int, 0, 100)
	for _, a := range strings.Split(line, " ") {
		num, err := strconv.Atoi(a)
		if err != nil {
			fmt.Println(err)
		}
		nums = append(nums, num)
	}

	fmt.Println(nums[0] * nums[1] / 2)
}

func nextLine() (string, error) {
	if sc.Scan() {
		return sc.Text(), nil
	} else {
		return "", errors.New("cant read next_line")
	}
}


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

sum_array=[]
total=0
temp_sum=sum(A)
for i in range(N-1):
    temp_sum=temp_sum-A[i]
    sum_array.append(temp_sum)
    total+=A[i]*sum_array[i]

print(total % (10**9 + 7))

Measured memory_bytes: 31640
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int, input().split())
ab = []
uf = UnionFind(n+1)
for i in range(m):
    a,b = map(int, input().split())
    ab.append((a,b))

ans = []
huben = n*(n-1)//2
for a,b in ab[::-1]:
    ans.append(huben)
    if not uf.same(a,b):
        huben -= uf.size(a)*uf.size(b)
        uf.union(a,b)
    
for aa in ans[::-1]:
    print(aa)

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

long long N;

vector<pair<long long, long long> > ab;
vector<pair<long long, long long> > ba;


int main(){
	cin >> N;
	for(long long i = 0; i < N; i++) {
		long long a, b;
		cin >> a >> b;
		ab.push_back(make_pair(a, b));
		ba.push_back(make_pair(b, a));
	}

	if(N % 2 == 1) {
		sort(ab.begin(), ab.end());
		sort(ba.begin(), ba.end(), greater<pair<long long, long long> >());
		cout << ba[N/2].first - ab[N/2].first + 1 << endl;
	} else {
		sort(ab.begin(), ab.end());
		sort(ba.begin(), ba.end(), greater<pair<long long, long long> >());
		cout << (ba[N/2-1].first + ba[N/2].first) - (ab[N/2-1].first + ab[N/2].first) + 1 << endl;
	}
}


Measured memory_bytes: 9724
#include <iostream>
using namespace std;
int main(){
  long long N, ans = 0;
  cin >> N;
  for(long long i = 1; i*i <= N; ++i){
    if(N%i) continue;
    long long m = i-1;
    if(m > 0 and N/m == N%m) ans += m;;
    if(N/i == m+1) continue;
    m = N/i - 1;
    if(m > 0 and N/m == N%m) ans += m;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
  #define ll  long long int
  #define N 1000000
   #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
  #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
  #define po pop_back
  #define pb push_back
  #define lb lower_bound
  #define fi first
  #define se second
  #define debug(x) cout << #x << " = " << x << endl
  #define ub upper_bound
  #define ibs ios_base::sync_with_stdio(false)
  #define cti cin.tie(0)
  #define all(x) x.begin(),x.end()
  #define PI 3.14159265
  #define cot cout.tie(0)
  using namespace std;
  /**
    * @author :: Sawlani
    *
    */
using namespace std;
/**
  * @author :: Sawlani
  *
  */

  bool prime[N+1];
  vector <ll> res;
  void sieve()
{
    memset(prime,true,sizeof(prime));
	prime[1]=false;
	 for(int i=2;i*i<=N;i++)
	 {
	 	if(prime[i])
	 	{
	    	for(int j=i*i;j<=N;j+=i)
	 	   {
	 		prime[j]=false;
	 	  }
	    }
     }

     f(i,1,N)
     {

         if(prime[i])
            res.pb(i);
     }
}

  int main()
  {
      sieve();
      ll x;
      cin >> x;
       ll ans=*lb(all(res),x);
      cout <<  ans;

  }


Measured memory_bytes: 2424
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int main()
{
	int r, g, b;
	cin >> r >> g >> b;

	cout << ((10 * g + b) % 4 == 0 ? "YES" : "NO") << endl;

}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;

    vector<ll> ans(n, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            int d = min({abs(i - j), abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1});
            ++ans[d];
        }
    }

    for (int i = 1; i < n; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256