akhauriyash/Code-Regression huggingface dataset:
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int X;
    cin>>X;
    vector<bool>expo(X+1);

    expo[1]=1;

    for(int b=2;b<=X;b++){
        int v=b*b;
        while(v<=X){
            expo[v]=1;
            v*=b;
        }
    }
    for(int i=X;i>=1;i--){
        if(expo[i]){
            cout<<i<<endl;

            break;
        }
    }

}




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

using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
void solve(int a) { cout << (a ? "Yes" : "No") << endl; }

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;
}
const int MAX = 5010000;
const int MOD = 1000000007;

long long modinv(long long a, long long m)
{
	long long b = m, u = 1, v = 0;
	while (b)
	{
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= m;
	if (u < 0)
		u += m;
	return u;
}
int main()
{
	
	int n, a, b;
	cin >> n >> a >> b;
	long long ans = 0;
	vector<int> inve(b+6, 0);
	for (int i = 1; i <b+2;i++){
		inve[i]=modinv(i,MOD);
	}
		ans = modpow(2, n, MOD);
	//cout << modpow(2, n, MOD) << endl;

	//cout << COM(n, a) << endl;
	//cout << COM(n, b) << endl;
	long long ca=1;
	long long cb=1;
	for(int i=1;i<=a;i++){
		ca *= ((n + 1 - i));
		ca%=MOD;
		ca*= inve[i];
		ca%=MOD;
	}
	cb=ca;
	for(int i=a+1;i<=b;i++){
		cb *= ((n + 1 - i));
		cb %= MOD;
		cb *= inve[i];
		cb %= MOD;
	}
	ans -= ca;
	ans -= cb;
	ans -= 1;
	ans%=MOD;
	if(ans <0){
		ans+=MOD;
	}
	//cout << ans % MOD << endl;
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

bool comp(PPPII x, PPPII y){
	return x.first > y.first;
}

int main(void){
	int a, b, c;
	int qual[1000000]; // ok->1, aimai->0, batu-> -1
	int N;
	while(cin >> a >> b >> c && a && b && c){
	vector<pair<int, pair<int, pair<int, int> > > > query;
	cin >> N;
	fill(qual, qual+1000000, 0);
	REP(i, N){
		int x, y, z, ok;
		cin >> x >> y >> z >> ok;
		x--;
		y--;
		z--;
		query.push_back({ok, {x, {y, z}}});
	}
	sort(query.begin(), query.end(), comp);
	REP(i, query.size()){
		int ok = query[i].first;
		int x = query[i].second.first;
		int y = query[i].second.second.first;
		int z = query[i].second.second.second;
		if(query[i].first == 1){
			qual[x] = 1;
			qual[y] = 1;
			qual[z] = 1;
		}else{
			if(qual[x] + qual[y] + qual[z] == 2){
				if(qual[x] == 0) qual[x] = -1;
				if(qual[y] == 0) qual[y] = -1;
				if(qual[z] == 0) qual[z] = -1;
			}
		}
	}
	REP(i, a+b+c){
		if(qual[i] == -1)
			cout << 0 << endl;
		else if(qual[i] == 0)
			cout << 2 << endl;
		else
			cout << 1 << endl;
	}
	}
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { this->w = w; if (f) fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	inline modulo& operator += (const modulo &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline modulo& operator -= (const modulo &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline modulo& operator *= (const modulo &b) { w = (num) w * b.w % mod; return *this; }
	inline modulo& operator /= (const modulo &b) { w = (num) w * b.inv() % mod; return *this; }
	inline modulo  operator +  (const modulo &b) { modulo r = *this; r += b; return r; }
	inline modulo  operator -  (const modulo &b) { modulo r = *this; r -= b; return r; }
	inline modulo  operator *  (const modulo &b) { modulo r = *this; r *= b; return r; }
	inline modulo  operator /  (const modulo &b) { modulo r = *this; r /= b; return r; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9 + 7);
typedef modulo<mod> rem;

const int nsz = int(5e3);
int n, k, a[nsz + 5];
rem dp[nsz + 5], ans;
vector<int> r;

struct union_find {
	int pr[nsz + 5], siz[nsz + 5];
	
	union_find() {
		cont (u, nsz) pr[u] = u, siz[u] = 1;
	}
	
	int inline operator [] (int id) { return qry(id); }
	
	int qry(int u) { return pr[u] == u ? u : pr[u] = qry(pr[u]); }
	
	bool inline link(int u, int v) {
		int pu = qry(u), pv = qry(v);
		if (pu == pv) return 0;
		pr[pv] = pu;
		siz[pu] += siz[pv];
		return 1;
	}
};
union_find uf;

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
		if (a[i] != -1) uf.link(a[i], i);
		if (a[i] == -1) r.push_back(i);
	}
	k = int(r.size());
	
	cont (u, n) {
		if (uf[u] != u || a[u] == -1) continue;
		ans += rem(n - 1).pow(k);
	}
	
	dp[0] = 1;
	loop (i, k) {
		int sz = uf.siz[r[i]];
		ans += rem(sz - 1) * rem(n - 1).pow(k - 1);
		for (int j = i; j >= 0; --j) {
			dp[j + 1] += dp[j] * (j ? rem(j) : rem(1)) * rem(sz);
		}
	}
	
	circ (j, 2, k) {
		ans += dp[j] * rem(n - 1).pow(k - j);
	}
	
	ans = rem(n) * rem(n - 1).pow(k) - ans;
	printf("%d\n", ans);
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }

int main(){
	int n;cin>>n;
	vector<ll> a(n);
	vector<ll> s(n + 1,0);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	sort(ALL(a));
	ll ans = 1;
	for(int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}
	for(int i = n - 1; i >= 1 ; i--) {
		if (2 * s[i] >= a[i]){
			ans++;
		}
		else{
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
M = 1000000007
H,W,A,B = map(int,input().split())
factorial_list = [0] * (H+W)
factorial_list[0] = 1
for i in range(1,H+W):
    factorial_list[i] = factorial_list[i-1]*i %M
inverse_factorial_list = [0] * (H+W)

def power(a,n):
    if n == 0:
        return 1
    if n == 1:
        return a % M
    if n % 2 == 0:
        return power(a,n//2)**2 % M
    return (power(a,n-1) * a) % M

inverse_factorial_list[H+W-1] = power(factorial_list[H+W-1],M-2)
for i in range(H+W-2,-1,-1):
    inverse_factorial_list[i] = inverse_factorial_list[i+1] *(i+1) %M

def C(a,b):
    return factorial_list[a+b] * inverse_factorial_list[a] * inverse_factorial_list[b] % M
    
route = 0
for i in range(B,W):
    a = H - A - 1
    b =  i
    c = A - 1
    d = W - i - 1
    route += ((C(a,b)%M) * (C(c,d)%M)) 
    route %= M

print(route)

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

#define N 5001
int n, ans;
string s;

int dp[N][N];
int main(){
    cin >> n;
    cin >> s;

    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            if (dp[i][j]) continue;

            int cnt = 0;
            while (i+cnt < j && j + cnt < n && s[i+cnt] == s[j+cnt]) cnt++;

            ans = max(ans, cnt);

            for (int k = 0; k < cnt; k++)
                dp[i+k][j+k] = cnt-k;
        }
    }

    cout << ans;
}


Measured memory_bytes: 96768
import Data.Typeable

ans :: Int -> String
ans x   | elem n [2, 4, 5, 7, 9] = "hon"
        | elem n [0, 1, 6, 8] = "pon"
        | otherwise = "bon"
        where 
            n = mod x 10


main = do  
    a <- getLine  
    let x = (read a :: Int)
    putStrLn $ ans x



Measured memory_bytes: 3872
package main

import "fmt"

func main() {
	var n, m int
	var s, t string
	fmt.Scan(&n, &m, &s, &t)

	g := gcd(n, m)
	l := n / g * m
	n /= g
	m /= g

	ok := true
	for i := 0; i < g; i++ {
		if s[i*n] != t[i*m] {
			ok = false
			break
		}
	}
	if ok {
		fmt.Println(l)
	} else {
		fmt.Println(-1)
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N, M, K; cin >> N >> M >> K;
	for (int i = 0; i <= N; i++) for (int j = 0; j <= M; j++) if (i * M + j * N - i * j * 2 == K) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ss(x) (int) x.size()
#define cat(x) cout << #x << " = " << x << endl
 
using namespace std;

int h, w, k;
char s[301][301];
int r[301];
vector <int> row[301];

int res[301][301];

void paint(int lh, int rh, int lw, int rw, int id) {
	for(int H = lh; H <= rh; ++H)
		for(int W = lw; W <= rw; ++W)
			res[H][W] = id;
}

int main() {
	scanf("%d %d %d", &h, &w, &k);
	for(int i = 1; i <= h; ++i) {
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= w; ++j) {
			if(s[i][j] == '#') {
				r[i] = 1;
				row[i].pb(j);
			}
		}
	}
	r[h + 1] = 1;
	int ja = 1;
	while(!r[ja])
		ja++;
	int type = 1;
	while(true) {
		int on = ja + 1;
		while(!r[on])
			on++;
		int D = (type == 1 ? 1 : ja);
		int U = on - 1;
		for(int i = 0; i < ss(row[ja]); ++i) {
			int left = 0;
			int right = 0;
			if(i > 0)
				left = row[ja][i - 1] + 1;
			if(i == 0)
				left = 1;
			if(i < ss(row[ja]) - 1)
				right = row[ja][i + 1] - 1;
			else
				right = w;
			paint(D, U, left, right, type++);
		}
		ja = on;
		if(ja == h + 1)
			break;
	}
	
	for(int i = 1; i <= h; ++i) {
		for(int j = 1; j <= w; ++j)
			printf("%d ", res[i][j]);
		printf("\n");
	}
		
	
	
	
	
	return 0;
}


Measured memory_bytes: 1792
N = gets.to_i
array = gets.split.map(&:to_i)

result = Array.new(10**6+5, 0)

array.each do |num|
  i = 1
  if result[i * num] == 0
    while 10 ** 6 >= i * num
      result[i * num] += 1
      i += 1
    end
  else
    result[i * num] = 2
  end
end
count = 0
array.each do |num|
  count += 1 if result[num] == 1
end
puts count


Measured memory_bytes: 35300
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	int answer[4];
	int a;
	char comma;
	string input;

	for( int i = 0;i < 4;i++ ) answer[i] = 0;
	while( cin >> a >> comma >> input ){
		if( input == "A" ) answer[0]++;
		else if( input == "B" ) answer[1]++;
		else if( input == "AB" ) answer[2]++;
		else if( input == "O" ) answer[3]++;
	}

	for( int i = 0;i < 4;i++ ){
		cout << answer[i] << endl;
	}

	
	return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static boolean[] p=new boolean[1000020];
	
	static void eratos() {
		Arrays.fill(p, true);
		p[0]=p[1]=false;
		for(int i=2; i*i<1000010; i++){
			if(p[i]){
				for(int j=2; i*j<1000010; j++){
					p[i*j]=false;
				}
			}
		}
	}

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			eratos();
			while(sc.hasNext()) {
				int n, x;
				n=sc.nextInt();
				x=sc.nextInt();
				int[] v=new int[n];
				if(n+x==0) break;

				for(int i=0; i<n; i++){
					v[i]=sc.nextInt();
				}
				
				//Arrays.sort(v);
				boolean[] dp=new boolean[1000010];
				dp[0]=true;

				for(int i=0; i<n; i++){
					for(int j=0; j<=x; j++){
						if(dp[j] && j+v[i]<=x) {
							dp[j+v[i]]=true;
						}
					}
				}
				int ans=-1;

				for(int i=x; i>1; i--){
					if(dp[i]){
						if(p[i]){
							ans=i;
							break;
						}
					}
				}
				System.out.println(ans==-1 ? "NA" : ans);
			}

		}
	}
}


Measured memory_bytes: 61928
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        nums = Arrays.stream(nums).boxed()
                .sorted(Comparator.reverseOrder()).mapToInt(i -> i).toArray();
        long ans = 0;
        int ptr = 0, cnt = 1;
        for (int i = 1; i < n; i++) {
            ans += nums[ptr];
            cnt++;
            if (cnt == 2) {
                ptr++;
                cnt = 0;
            }
        }
        System.out.println(ans);
    }
}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 x; cin >> x; cout << (_i64)pow(x, 3) << endl;
    }
    return 0;
}


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

int main(void) {
    double a[10], v1, v2;
    char c;
    while (cin >> a[0]) {
        for (int i= 1; i < 10; ++i)
            cin >> c >> a[i];
        cin >> c >> v1 >> c >> v2;

        double t = 0.0;
        for (int i = 0; i < 10; ++i)
            t += a[i] / (v1 + v2);

        double t2 = 0.0;
        for (int i = 0; i < 10; ++i) {
            t2 += a[i] / v1;
            if (t2 >= t) {
                cout << i+1 << endl;
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.ThreadLocalRandom;
public class Main 
{

 static long N = 100;
 static long CNT = 62;
 static long  INF = 1 << 62;




	
	 static long p[] = new long[50005];
	 static long si[] = new  long[50005];
    static void merge(long u, long v) 
    {
    	u = get(u);
    	v = get(v);
    	if (si[(int)v] > si[(int)u])
    	{
    		long k = v;
    		v = u;
    		u = k;
    	}
    	p[(int)v] = u;
    	si[(int)u] += si[(int)v];
    }
	  static long get(long u) {
	      	if(p[(int)u] == u) return  u;
	      	else return p[(int)u] = get(p[(int)u]);
	      }
	 static void init()
	 {
		 
	 int n = 5;
	      	for (int i = 0; i <= n; i++)
	      	{
	      		p[i] = i;
	      		si[i] = 1;
	      	}
	 }
	
	 static long clc(long c ,long m ,long n , long k)
	 {
		 return k - c * m * (2 * n - 2);
	 }
	 static long call(long n2, long m2 ,long n ,long m ,long k)
	 {
	 	if (n == 1 && true)
	 	{
	 		long r = k / m;
	 		if (m2 <= k - r * m) r = r + 1;
	 		return r;
	 	}
	 	 long r = k / m;
	 	 long c = r / (2 * n - 2); 
	 	 long res =  - 1;
	 	if (n2 != n && n2 != 1)
	 		res =res + 2 * c + 1;
	 else
	 		res = res + c + 1;	
	 	 long l = clc(c , m , n , k);
	 	for (int i = 1; l > 0 && i <= n; i++)
	 	{
	 		for (int j = 1; k > 0 && j <= m; j++,  l = l - 1)
	 		{
	 			if (i == n2 && j == m2)
	 				res = res + 1;
	 		}
	 	}
	 	for (int i =(int) n - 1; l > 0 && i > 0; i++)
	 	{
	 		for (int j = 1; l > 0 && j < m + 1; j++, l = l - 1)
	 		{
 				if (i == n2 && j == m2)
	 				res = res + 1;
	 		}
	 	}
	 	return res;
	 }

	 static String k;


	 static long parsenum(long j, long l)
	 {
	 	 long cur = 0;
	 	for (int i = (int) j; i <= l; ++i)
	 	{
	 		cur *= 10;
	 		cur += k.charAt(i) - '0';
	 	}
	 	return cur;
	 }

	 static long gcd(long a, long b) 
		{
			if (b == 0)
			{	
				return a;
			}
			
			else
			{
				 return gcd(b, a % b);
			}
		}
	static boolean pri( int k)
	 { 
		if( k == 1) return false;
	     for(int i = 2; i * i <= k; i++)
	     {

	         if( k % i == 0) return false;
	     }
	     return true;
	 }
	public static void main(String[] args) throws Exception
	{

		
		   PrintWriter out = new PrintWriter(System.out);
		   Scanner in = new Scanner(System.in);
		  
		 int n = in.nextInt();
		 long a[] = new long [n];
		 long b[] = new long[n];
		 long cnt = 0;
		 for(int i = 0; i < n  ;i ++)
		 {
			 a[i] = in.nextInt();
			b[i] = in.nextInt();
		 }
		 int ans = 0;
		 for(int i = n - 1; i >= 0; i--)
		 {
			 if((a[i] + cnt) % b[i] != 0)
			 {
				 
			   if( a[i] + cnt > b[i] ) cnt+=b[i] - (cnt + a[i]) % b[i];
			   else cnt+= b[i] - ( a[i] + cnt);
			 }
		 }
		
		out.println(cnt);
		 
		out.close();
		
	}
 

}

	
      

	  
	


Measured memory_bytes: 76432
a,b=map(int,input().split())
n=int(100*100/8)+1
ans=0
x=0
for i in range(1,n+1):
  x=i
  if int(i*0.08)==a and int(i*0.1)==b:
    ans=i
    break
if x==n:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 38640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int INF = 2e9 + 239;

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

	vector<int> mx(4, -INF);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		mx[0] = max(mx[0], x + y);
		mx[1] = max(mx[1], x - y);
		mx[2] = max(mx[2], -x - y);
		mx[3] = max(mx[3], -x + y);
	} 
	cout << max(mx[0] + mx[2], mx[1] + mx[3]) << endl;
}

Measured memory_bytes: 3180
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  map<ll, ll> count;
  for (auto i = 0; i < N; i++) {
    ll x;
    cin >> x;
    if (count.find(x) == count.end()) count[x] = 0;
    count[x]++;
  }
  ll res = 0;
  for (auto x : count) {
    if (x.first < x.second) res += x.second - x.first;
    else if (x.first > x.second) res += x.second;
  }

  cout << res << endl;

  return 0;
}


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

#define MAX 100000

int parent(int i) { return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

int main() {
  int H;
  int i;
  int A[MAX+1];

  scanf("%d", &H);
  for(i=1; i<=H; i++)
    scanf("%d", &A[i]);

  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i) >= 1) printf("parent key = %d, ", A[parent(i)]);
    if(left(i) <= H) printf("left key = %d, ", A[left(i)]);
    if(right(i) <= H) printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
int main(void){
  int n,num;
  scanf("%d",&n);
  num = n % 10;
  
  if(num == 2)
    printf("hon");
  else if(num == 4)
    printf("hon");
  else if(num == 5)
    printf("hon");
  else if(num == 7)
    printf("hon");
  else if(num == 9)
    printf("hon");
  
  else if(num == 0)
    printf("pon");
  else if(num == 1)
    printf("pon");
  else if(num == 6)
    printf("pon");
  else if(num == 8)
    printf("pon");
  
  else if(num == 3)
    printf("bon");
  return 0;
}

Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    vector<ll> b(m * 2, 0);
    vector<pair<int, ll>> c(n - 1, {0,0});
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        if (i > 0) {
            if (a[i - 1] + 1 < a[i]) {
                if (a[i - 1] + 2 < m * 2) b[a[i - 1] + 2]++;
                if (a[i] + 1 < m * 2) b[a[i] + 1]--;
                c[i - 1].first = a[i] + 1;
                c[i - 1].second = a[i] - 1 - a[i - 1];
            }
            else if (a[i] < a[i - 1] && a[i - 1] + 1 < a[i] + m) {
                if (a[i - 1] + 2 < m * 2) b[a[i - 1] + 2]++;
                if (a[i] + 1 < m) b[a[i] + m + 1]--;
                c[i - 1].first = a[i] + m + 1;
                c[i - 1].second = a[i] + m - 1 - a[i - 1];
            }
        }
    }
    for (int i = 1; i < m * 2; i++) {
        b[i] += b[i - 1];
    }
    ll sum = 0;
    for (int i = 0; i < n - 1; i++) {
        b[c[i].first] -= c[i].second;
        sum += c[i].second + 1;
    }
    for (int i = 1; i < m * 2; i++) {
        b[i] += b[i - 1];
    }
    ll ans = 0;
    for (int i = 0; i < m; i++) {
        ans = max(ans, b[i] + b[i + m]);
    }
    cout << sum - ans << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void) {
	int i,a=0,b=0,temp;
	for(i=0;i<4;i++) {
		scanf("%d",&temp);
		a+=temp;
	}
	for(i=0;i<4;i++) {
		scanf("%d",&temp);
		b+=temp;
	}
	if(a>b){
		printf("%d\n",a);
	} else {
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 592
#include <stdio.h>

    int main(void){

        int n, a, b = 1;
        scanf("%d %d %d", &n, &a, &b);
        int na = 1;

        if( 1 <= n <= 20 && 1 <= a <= 50 && 1 <= b <= 50){
            na = n * a;
        }else{
            return 0;
        }

        if( na == b){
            printf("%d\n",b );
        }else if( na > b){
            printf("%d\n", b );
        }else{
            printf("%d\n", na );
        }

        return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <vector>
#include <stdio.h>
using namespace std;

int main(){
  vector<int> x(1024,0),y(1024,0),dif(1024,0);
  int n,i,p;
  double d=0.0;
  
  cin >> n;
  for( i=0;i<n;i++ ) cin >> x[i];
  for( i=0;i<n;i++ ) cin >> y[i];

  for( p=1;p<=3;p++ ){
    for( i=0;i<n;i++ ){
      d += pow(fabs(x[i]-y[i]),p);
    }
    printf("%.6f\n",pow(d,1.0/p));
    d=0;
  }
  
  for( i=0;i<n;i++ ) dif[i] = fabs(x[i] - y[i]);
  double max=dif[0];
  for( i=0;i<n;i++ ){
    if( max < dif[i] ){
      max = dif[i];
    }
  }
  printf("%.6f\n",max);

  return 0;
}

Measured memory_bytes: 1300
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int sum = X;
  sum += N;
  int a;
  rep(i, N) {
    cin >> a;
    sum += (D - 1) / a;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

public class Problem_C
{
  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int H = inputs[0], W = inputs[1];
    var grid = new char[H, W];
    for (var i = 0; i < H; i++)
    {
      var line = Console.ReadLine();
      for (var j = 0; j < W; j++) grid[i, j] = line[j];
    }

    for (var i = 0; i < H; i++)
    {
      for (var j = 0; j < W; j++)
      {
        if (grid[i, j] == '.') continue;
        if (!findDrawable(i, j, grid))
        {
          Console.WriteLine("No");
          return;
        }
      }
    }
    Console.WriteLine("Yes");
  }

  private static bool findDrawable(int h, int w, char[,] grid)
  {
    var isDrawable = false;
    if (h - 1 >= 0) isDrawable |= grid[h - 1, w] == '#';
    if (w - 1 >= 0) isDrawable |= grid[h, w - 1] == '#';
    if (h + 1 < grid.GetLength(0)) isDrawable |= grid[h + 1, w] == '#';
    if (w + 1 < grid.GetLength(1)) isDrawable |= grid[h, w + 1] == '#';
    return isDrawable;
  }
}


Measured memory_bytes: 13140
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let s: String = read();
    let t = s.as_bytes();
    if t[0] == t[1] && t[1] == t[2] {
        println! {"No"};
    } else {
        println! {"Yes"};
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K, X;
  cin >> K >> X;
  for (int i = X - K + 1; i < X + K; i++) {
    cout << i << (i == X + K - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b;
  cin >> a >> b;
  if(a == 1) {
    if(b == 2) cout << 3 << endl;
    else cout << 2 << endl;
  }
  else if(a == 2) {
    if(b == 1) cout << 3 << endl;
    else cout << 1 << endl;
  }
  else {
    if(b == 1) cout << 2 << endl;
    else cout << 1 << endl;
  }
}

Measured memory_bytes: 256
S = input()
T = input()
s,t = len(S),len(T)
for i in range(s-t,-1,-1):
    for j in range(t):
        if S[i+j] != T[j] and S[i+j] != "?":
            break
    else: 
        S = S[:i] + T + S[i+t:]
        break
else:
    print("UNRESTORABLE")
    exit()

S = list(S)
for i in range(s):
    if S[i] == "?":
        S[i] = "a"
print(*S, sep = "")

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

int N,M,a,b,dp[100010] = {},visited[100010] = {0},cnt[100010] = {0};
vector<vector<int>> v(100010);
vector<int> u;

void dfs(int n){
	visited[n] = 1;
	for(int i=0;i<v[n].size();i++){
		if(visited[v[n][i]]==0){
			dfs(v[n][i]);
		}
	}
	u.push_back(n);
}


int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> a >> b;
		v[a].push_back(b);
		cnt[b]++;
	}
	int s = 0;
	for(int i=1;i<=N;i++){
		if(cnt[i]==0 && visited[i]==0) dfs(i);
	}
	reverse(u.begin(),u.end());
	for(int i=0;i<u.size();i++){
		for(int j=0;j<v[u[i]].size();j++){
			dp[v[u[i]][j]] = max(dp[v[u[i]][j]],dp[u[i]]+1);
		}
	}
	int ans = 0;
	for(int i=1;i<=N;i++) ans = max(ans,dp[i]);
	cout << ans << endl;
}


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

int main() {
  string S,T;
  cin >> S >> T;
  bool ans=true;
  
  for(int i=0; i<S.size(); i++){
    if(S.at(i) != T.at(i)){
      ans = false;
      break;
    }
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3556
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n[5];
  for(int i=0;i<5;i++) cin >> n[i];
  sort(n,n+5,greater<int>());
  for(int i=0;i<5;i++){
    if(i!=4) cout << n[i] << ' ';
    else cout << n[i] << endl;
  }
  return 0;
}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n;
  cin >> n;
  vector<int> abc(3);
  rep(i,3) cin >> abc.at(i);
  sort(abc.begin(),abc.end());
  vector<int> l(n);
  rep(i,n) cin >> l.at(i);
  setfspattern(4,n);
  int64_t mincost = 1000000000000000;
  rep(i,fspcnt){
    vector<bool> exist123(3);
    vector<int> totalabc(3);
    rep(j,n){
      if(fspattern.at(i).at(j) != 3){
        exist123.at(fspattern.at(i).at(j)) = true;
      }
    }
    //cout << exist123.at(0) << exist123.at(1) << exist123.at(2) << endl;
    if(exist123.at(0) && exist123.at(1) && exist123.at(2)){
      //cout << "W";
      rep(j,n){
        int bb = fspattern.at(i).at(j);
        if(bb != 3){
          totalabc.at(bb) += l.at(j);
        }
      }
      sort(totalabc.begin(),totalabc.end());
      int64_t cost = 0;
      rep(j,3){
        cost += abs(totalabc.at(j) - abc.at(j));
      }
      int cnt4 = 0;
      rep(j,n){
        if(fspattern.at(i).at(j) != 3){
          cnt4++;
        }
      }
      cost += (cnt4-3)*10;
      /*cout << totalabc.at(0) <<","<< totalabc.at(1) <<","<< 
      totalabc.at(2) <<","<< endl;
      cout << cost << endl;*/
      mincost = min(mincost,cost);
    }
  }
   cout << mincost << endl;
}

Measured memory_bytes: 4864
#include<iostream>

using namespace std;

int main(){
        int n,d;
        cin >> n >> d;
        if( n % (2 * d + 1) == 0){
                cout << n / (2 * d + 1) << endl;
        }else {
                cout << n / (2 * d + 1)  + 1 << endl;
        }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = ["0"]*(N+2)
ans[0] = 0
ans[1] = 1
mod = 10**9 + 7

for _ in range(M):
  a = int(input())
  ans[a+1] = 0

for i in range(2, N+2):
  if ans[i] == "0":
    ans[i] = (ans[i-2] + ans[i-1]) % mod

print(ans[-1])

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


int main(){

    int N, M, X, A[100];
    cin >> N >> M >> X;
    for( int i = 0; i < M; i++ ) cin >> A[i];


    int right_cost = 0;
    int left_cost = 0;

    for( int i = 0; i < M; i++ ){
        if( A[i] > X ) right_cost++;
        else left_cost++;
    }

    cout << min( right_cost, left_cost ) << endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

/*ユークリッドの互除法を使って、最大公約数を返す関数*/
LL Euqlid_num(LL a, LL b)
{
    LL r;
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a%b;
    }    
    return b;
}


int main()
{
    LL A, B, C, D;
    LL count;
    LL count_B1, count_B2, count_B3, count_A1, count_A2, count_A3;
    LL least_multi, ans;
    
    
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);

    /*Bいかに何個の割り切れる数があるかを探す*/
    count_B1 = B / C; count_B2 = B / D;
    least_multi = C * D /(Euqlid_num(C, D));
    count_B3 = B / least_multi;
    count = count_B1 + count_B2 - count_B3;


    /*A以下に何個割り切れる数があるか*/
    count_A1 = (A-1) / C; count_A2 = (A-1) / D;
    count_A3 = (A-1) / least_multi;
    count += count_A3 - count_A1 - count_A2 ;
    ans = B - A - count + 1;
    
    printf("%lld", ans);
    
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String x = "^A?KIHA?BA?RA?$";
		System.out.println(s.matches(x) ? "YES" : "NO");

//		StringBuilder builder = new StringBuilder();
//		builder.append(s);
//		if(builder.charAt(0) != 'A') {
//			builder.insert(0, "A");
//		}
//		if(builder.length() >= 5 && builder.charAt(4) != 'A') {
//			builder.insert(4, "A");
//		}
//		if(builder.length() >= 7 && builder.charAt(6) != 'A') {
//			builder.insert(6, "A");
//		}
//		if(builder.length() >= 9 && builder.charAt(8) != 'A') {
//			builder.insert(8, "A");
//		}
//		System.out.println(builder.toString());
//		if(builder.toString().equals("AKIHABARA")) {
//			System.out.println("YES");
//		} else {
//			System.out.println("NO");
//		}
	}
}


Measured memory_bytes: 23124
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <array>
#include <bitset>
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
// #include <fstream>//ifstream/ofstream
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <list>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME_SHORT 10007
#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

void rar(int n, int* a);
void rar2(int n, int m, int** a);

int ipow(int base, int exp);
int left(int current, bool swap);
int right(int current, bool swap);
int griddist(int x, int y, int s, int t);
int griddist(pii one, pii two);
double sqeucldist(double x, double y, double s, double t);
double sqeucldist(pii one, pii two);
ull modadd(ull a, ull b, int mod);
ull modmult(ull a, ull b, int mod);

int main(void) {
    size_t n;
    cin >> n;
    char *s, *t;
    s = new char[n];
    t = new char[n];
    for (size_t i = 0; i < n; ++i){
        cin >> s[i];
    }
    for (size_t i = 0; i < n; ++i){
        cin >> t[i];
    }
    size_t start = 0;
    size_t search = 0;
    for (size_t pos = 0; pos < n; ++pos)
    {
        if (s[pos] == t[search]) {
            ++search;
        } else if (s[pos] == t[0]) {
            start = pos;
            search = 1;
        } else {
            start = pos+1;
            search = 0;
        }
    }
    cout << start+n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a, b, c, work,sum;
	scanf("%d %d", &a,&b);
	sum = a + b;
	if (a<b) {
		work = a;
		a = b;
		b = work;
	}
	c = a % b;
	while (c != 0) {
		a = b;
		b =c;
		c = a % b;
	}
	printf("%d\n", sum - (b - 1));
	return 0;
}


Measured memory_bytes: 2744
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<queue>
#include<vector>
#define LL long long
#define ULL unsigned long long
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define itn int
#define pritnf printf
#define mp make_pair
#define pb push_back
using namespace std;

int n;

int main(){
	cin>>n;
	For(i,n,999){
		if (i%111==0){
			printf("%d",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
def main():
    x,y,a,b,c=map(int,input().split())
    P=list(map(int,input().split()))
    Q=list(map(int,input().split()))
    R=list(map(int,input().split()))
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    Z=P[:x]+Q[:y]
    heapq.heapify(Z)
    for r in R:
        if Z[0]>=r:
            break
        heapq.heapreplace(Z,r)
    print(sum(Z))

    

if __name__=='__main__':
    main()

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

#define fio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);
#define md 1000000007
#define mem(ar,avg) memset(ar,avg,sizeof(ar))
#define pb push_back

typedef long long int lli;
typedef float fl;


int main()
{
	fio();
	int t;
	//cin >> t;
	//while (t--)
	{
		lli n, d;
		cin >> n ;

		string s = "";
		s += '7';
		lli l = 1;

		if (n % 2 == 0 || n % 5 == 0 )  cout << -1 << endl;
		else
		{
			lli temp = 0;
			lli l = 1;
			for (int i ; ; i++)
			{
				temp *= 10;
				temp += 7;
				temp %= n;
				if (temp % n == 0 )break;
				l++;

			}
			cout << l << endl;
		}


	}

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

ll func(ll x){ //f(x,0)
    if(x < 0) return 0;
    if(x % 2 == 1){
        ll tmp = (x+1)/2;
        return tmp % 2;
    }else{
        ll tmp = x/2;
        return (tmp%2) ^ x;
    }
}
int main(){
    ll A,B;
    cin >> A >> B;
    cout << (func(B) ^ func(A-1)) << endl;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
*/

ll dist(char c){
    int tmp = c - 'a';
    return tmp;
}

ll nex[300100][30];

void solve(){
    string s,t;
    cin >> s >> t;
    ll i=0;
    ll j=0;
    ll ss = s.size();
    ll ts = t.size();
    
    rep(i,300100){
        rep(j,30){
            nex[i][j]=-1;
        }
    }

    string str = s + s;
    /*
    for(int i=str.size()-1; i>0; i--){
        for(int j=i-1; j>=0; j--){
            nex[j][dist(str[i])] = i-j;
        }
    }
    */
    rep(i,26){
        nex[str.size()][i] = -1;
    }
    rep(i,26){
        for(int j=str.size()-1; j>=0; j--){
            nex[j][i] = i==dist(str[j+1])? 1: nex[j+1][i]==-1? -1:nex[j+1][i]+1;
        }
    }
    
    /*
    rep(i,str.size()+10){
        rep(j,30){
            cout << nex[i][j] << " ";
        }
        cout << endl;
    }
    */
    
    
    set<char> st;
    rep(i,ss){
        st.insert(s[i]);
    }
    rep(i,ts){
        if(st.count(t[i])==0){
            cout << -1 << endl;
            return;
        }
    }
    

    ll ans = t[0]==s[0]? 1:nex[0][dist(t[0])]+1;
    
    ll tmp = t[0]==s[0]? 0:nex[0][dist(t[0])];
    for(ll i=1; i<ts; i++){
        if(nex[tmp%ss][dist(t[i])]==-1){
            ans = -1;
            break;
        }
        ans += nex[tmp%ss][dist(t[i])];
        tmp += nex[tmp%ss][dist(t[i])];
    }
    

    

    cout << ans << endl;

}

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

Measured memory_bytes: 71248
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

l = []
r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

ans = 0
b = Counter(r)
for i in l:
   ans += b.get(i, 0)

print(ans)


Measured memory_bytes: 50824
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n,m;
  string s;
  cin>>n>>m>>s;

  int cnt=0;
  rep(i,n+1){
    if(s[i]=='1') cnt++;
    else cnt=0;
    if(cnt>=m) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> ans;
  int now=n;
  while(now>0){
    if(now<=m) {
      ans.pb(now);
      break;
    }
    for(int i=now-m;i<now;i++){
      if(s[i]=='0') {
        ans.pb(now-i);
        now=i;
        break;
      }
    }
  }

  reverse(all(ans));
  rep(i,ans.size()){
    cout << ans[i];
    if(i!=ans.size()-1) cout << " ";
  }

  cout << endl;

}


Measured memory_bytes: 3916
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

struct Node
{
	vector<int> to,cost;
};

struct Tri
{
	int p,ct;
	Tri(int pp, int cc) {p=pp;ct=cc;}

	bool operator<(const Tri &t) const
	{
		return ct > t.ct;
	}
};

Node node[32];
bool visited[32];

int main()
{
	char c1,c2,c3;
	int x1,x2,y1,y2;
	int n,m,a,b,ab,ba;
	cin >> n >> m;
	while(m--)
	{
		cin >> a >> c1 >> b >> c2 >> ab >> c3 >> ba;
		node[a].to.push_back(b);
		node[a].cost.push_back(ab);
		node[b].to.push_back(a);
		node[b].cost.push_back(ba);
	}
	cin >> x1 >> c1 >> x2 >> c2 >> y1 >> c3 >> y2;
	
	memset(visited,0,sizeof(visited));
	priority_queue<Tri> pq;
	pq.push(Tri(x1,0));
	while(!pq.empty())
	{
		Tri tt = pq.top(); pq.pop();
		
		if(tt.p == x2)
		{
			y1-=tt.ct;
			break;
		}

		if(visited[tt.p])continue;
		visited[tt.p] = true;

		for(int i=0; i<node[tt.p].to.size(); i++)
		{
			pq.push(Tri(node[tt.p].to[i], node[tt.p].cost[i]+tt.ct));
		}
	}
	memset(visited,0,sizeof(visited));
	while(!pq.empty()) pq.pop();
	pq.push(Tri(x2,0));
	while(!pq.empty())
	{
		Tri tt = pq.top(); pq.pop();
		
		if(tt.p == x1)
		{
			y1-=tt.ct;
			break;
		}

		if(visited[tt.p])continue;
		visited[tt.p] = true;

		for(int i=0; i<node[tt.p].to.size(); i++)
		{
			pq.push(Tri(node[tt.p].to[i], node[tt.p].cost[i]+tt.ct));
		}
	}

	cout << y1-y2 << endl;
}

Measured memory_bytes: 0