akhauriyash/Code-Regression huggingface dataset:
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N;
	cin >> N;
 
	// 解法
	if (N%2==0){
		cout << N*(N-2)/2 << endl;
		REP(i,N){
			REP(j,N){
				if (j<=i | j==N-i-1) continue;
				printf("%lld %lld\n", i+1, j+1);
			}
		}
	}
	else{
		cout << (N-1)*(N-1)/2 << endl;
		REP(i,N){
			REP(j,N){
				if (j<=i | j==N-i-2) continue;
				printf("%lld %lld\n", i+1, j+1);
			}
		}
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            sS = Console.ReadLine().Trim().Split('-');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Yes";
            int iTmp = 0;
            if (sS.Length != 2) { sOut = "No"; }
            if (sOut == "Yes" && sS[0].Length != iA) { sOut = "No"; }
            if (sOut == "Yes" && sS[1].Length != iB) { sOut = "No"; }
            if (sOut == "Yes" && !int.TryParse(sS[0], out iTmp)) { sOut = "No"; }
            if (sOut == "Yes" && !int.TryParse(sS[1], out iTmp)) { sOut = "No"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	static Queue<Pair> queue = new LinkedList<Pair>();
	
	static class Pair {
		int nextNumber;
		int cost;
		
		Pair(int nextNumber, int cost) {
			this.nextNumber = nextNumber;
			this.cost = cost;
		}
	}
	
	static class Router {
		int number;
		int degree;
		Router next[];
		int cost;
		boolean mark;
		
		Router(int number) {
			this.number = number;
		}
	}
	
	public static void main(String srgs[]) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		Router rt[];
		
		n = sc.nextInt();
		rt = new Router[n + 1];
		for (int i = 0; i < n + 1; i++) {
			rt[i] = new Router(i);
		}
		for (int i = 0; i < n; i++) {
			int number = sc.nextInt();
			int degree = sc.nextInt();
			rt[number].next = new Router[degree];
			rt[number].degree = degree;
			for (int j = 0; j < degree; j++) {
				int nextIndex = sc.nextInt();
				rt[number].next[j] = rt[nextIndex];
			}
		}
		
		m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			int start = sc.nextInt();
			int goal = sc.nextInt();
			int ttl = sc.nextInt();
			for (int j = 1; j <= n; j++) {
				rt[j].mark = false;
				rt[j].cost = Integer.MAX_VALUE;
			}
			queue.clear();
			bestWay(rt, start, goal, 1);
			if (rt[goal].cost <= ttl) {
				System.out.println(rt[goal].cost);
			} else {
				System.out.println("NA");
			}
		}
	}
	
	public static boolean bestWay(Router rt[], int start, int goal, int cost) {
		if (rt[start].mark) {
			return false;
		}
		rt[start].mark = true;
		rt[start].cost = cost;
		if (rt[goal].mark) {
			return true;
		}
		
		for (int i = 0; i < rt[start].degree; i++) {
			Pair p = new Pair(rt[start].next[i].number, cost + 1);
			queue.add(p);
		}
		
		while (!queue.isEmpty()) {
			Pair p = queue.poll();
			if (bestWay(rt, p.nextNumber, goal, p.cost)) {
				return true;
			}
		}
		return false;
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
signed main(){
    cin>>n>>m;
    priority_queue<int>q;
    for(int i=0;i<n;i++){int t;cin>>t;q.push(t);}
    while(m--){int x=q.top()/2;q.pop();q.push(x);}
    int ans=0;
    while(!q.empty()){ans+=q.top();q.pop();}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vb vector<bool>
#define mod 1000000007
#define pii pair<int,int>
const int inf = 0x3f3f3f3f3f3f3f3f;
int fun(int i , vi &a , vi &dp)
{
    if(i<0) return inf;
    if(i == 0) return 0;
    if(dp[i]!=-1) return dp[i];
    dp[i] = min( fun(i-1, a , dp) + abs(a[i] - a[i-1]) , fun(i-2, a , dp) + abs(a[i] - a[i-2]) ); 
    
    return dp[i]; 
}
int32_t main(){
    
    int n , i; 
    cin >> n;
    
    vi a(n);
    for(i = 0 ; i <  n ; i++) cin >> a[i];
   
    vi dp(n,-1);
    
    cout << fun(n-1 , a, dp);
    
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n;
  string str;
  cin >> n;
  
  for(int i=0;i<n;i++){
    
    int out = 0;
    int a[4] = {};
    
    while(out != 3){
      
      cin >> str;
      
      if(str == "OUT") out++;
      else if(str == "HOMERUN"){
	a[3] += a[0]+a[1]+a[2]+1;
	a[0] = a[1] = a[2] = 0;
      }
      else if(str == "HIT"){
	a[3] += a[2];
	a[2] = 0;
	a[2] = a[1];
	a[1] = 0;
	a[1] = a[0];
	a[0] = 1;
      }
      
    }
    cout << a[3] << endl;
  }
  return (0);
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007



              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
        	int a,b,c,l,j=0;
        	bool flag=false;
        	cin>>a>>b>>c>>l;
        	while(a>=b){b*=2;j++;}
        	while(b>=c){c*=2;j++;}
       
       		if(j<=l) cout<<"Yes";
       		else cout<<"No";


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


Measured memory_bytes: 3804
import java.util.*;

public class Main {
    private static final long INF = 1 << 60;
    private static long[][] dp = new long[110][100100];
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int[] weight = new int[110];
        long[] value = new long[110];
        for(int i=0;i<N;i++){
            weight[i] = Integer.parseInt(sc.next());
            value[i] = Long.parseLong(sc.next());
        }
        for(int i=0;i<N;i++){
            for(int sumW=0;sumW<=W;sumW++){
                if(sumW - weight[i] >= 0){
                    dp[i+1][sumW] = Math.max(dp[i+1][sumW],dp[i][sumW - weight[i]] + value[i]);
                }
                dp[i+1][sumW] = Math.max(dp[i+1][sumW],dp[i][sumW]);
            }
        }
        System.out.println(dp[N][W]);
    }
}


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

int main(){
  int n, m;
  cin >> n >> m;
  if (n==0) n=1;
  vector<P> num(n);
  if (n>1) num[0].first = 1;
  else num[0].first = 0;
  rep(i,n-1) num[i+1].first = 0;
  rep(i,n) num[i].second = 0;
  int out=0;
  int s, c;
  rep(i,m) {
    cin >> s >> c;
    if ((n!=1) && (s==1) && (c==0)) {out = 1; break;}
    if (num[s-1].second==0) {num[s-1].first = c; num[s-1].second = 1;}
    else if ((num[s-1].second==1) && (num[s-1].first==c)){continue;}
    else {out=1;break;}
  }
  if (out==1) cout << -1 << endl;
  else {
    int ans = num[0].first;
    for (int j=1;j<n;++j) ans = 10*ans + num[j].first;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n,t;
    cin >> n >> t;
    long a[n];
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }
    long temmin = 1e9+7;
    int cnt = 0;
    long temmax = 0;
    for(int i = 0;i<n;i++){
        temmin = min(a[i],temmin);
        if(a[i]!=temmin){
            if(temmax<a[i]-temmin){
                temmax=a[i]-temmin;
                cnt=1;
            }
            else if(temmax==a[i]-temmin){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans,l,r;
const ll mod=1e9+7;
int n,k;
int main()
{
	cin>>n>>k;
	for(ll i=k;i<=n+1;i++)
	{
		l=(0+i-1)*i/2;
		r=(n+n-i+1)*i/2;
		ans=(ans+r-l+1)%mod;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;

bool ok(int n) {
    int a, b;
    a = n, b = n % 10;
    while(n) {
        if(n % 10 != b) return false;
        n /= 10;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    while(!ok(n)) n++;
    cout << n << endl;
}

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

using namespace std;

int main(){
    string S,x;
    double ans=0;
    int count=0,rop=0,now=0;
    cin >> S;
    x.push_back(S[0]);

    while(count!=pow(2,S.size()-1)){
        now = count;
        for(int i=1;i<S.size();i++){
            if(now&1 == 1){
                x.push_back(S[i]);
            }else{
                ans += stod(x);
                x.clear();
                x.push_back(S[i]);
            }
            now >>= 1;
        }
        ans += stod(x);
        x.clear();
        x.push_back(S[0]);
        count++;
    }

    cout << setprecision(S.size()+1) << ans << endl;
}

Measured memory_bytes: 256
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj0154().doIt();
    }
    class aoj0154{
    	int card_point[];
    	int card_num[];
    	int accept[];
    	int cnt = 0;
    	void dfs(int index,int ac_index,int result,int max_n){
    		if(accept[ac_index] == result){
    			cnt++;
    		}else if(index < max_n){
    			for(int i = 0;i <= card_num[index];i++){
    				if(result + (i*card_point[index]) > accept[ac_index])break;
    				else{
    					dfs(index+1,ac_index,result + (i*card_point[index]),max_n);
    				}
    			}
    		}
    	}
    	void doIt(){
    		while(true){
    			int n = sc.nextInt();
    			if(n == 0)break;
    			card_point = new int[n];
    			card_num = new int[n];
    			for(int i = 0;i < n;i++){
    				card_point[i] = sc.nextInt();
    				card_num[i] = sc.nextInt();
    			}
    			int m = sc.nextInt();
    			accept = new int[m];
    			for(int i = 0;i < m;i++){
    				accept[i] = sc.nextInt();
    			}
    			for(int i = 0;i < m;i++){
    				cnt = 0;
    				dfs(0,i,0,n);
    				System.out.println(cnt);
    			}
    		}
    	}
    }
}

Measured memory_bytes: 26928
#include <iostream>

int main(){
    int n, k;
    std::string s;
    std::cin >> n >> k >> s;

    if (s[k - 1] == 'A')
    {
        std::cout << s.replace(k - 1, 1, "a") << std::endl;
    }
    else if (s[k - 1] == 'B')
    {
        std::cout << s.replace(k - 1, 1, "b") << std::endl;
    }
    else
    {
        std::cout << s.replace(k - 1, 1, "c") << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3588
# A - One out of Three
# https://atcoder.jp/contests/abc075/tasks/abc075_a

A, B, C = map(int, input().split())

if A == B and A != C:
    print(C)
elif A == C and A != B:
    print(B)
elif B == C and A != C:
    print(A)


Measured memory_bytes: 9080
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	int k = read.to!int;
	
	long[] vs;
	foreach(i; 0 .. n) vs ~= read.to!long;
	print!1("vs:", vs);
	
	long[][][] xs = new long[][][](k + 1, k + 1, 0);
	foreach(i; 0 .. k + 1) foreach(j; 0 .. k + 1 - i){
		if(i + j > n) continue;
		if(j == 0){
			if(i == 0) xs[i][j] = [];
			else xs[i][j] = xs[i - 1][j] ~ vs[i - 1];
		}
		else xs[i][j] = xs[i][j - 1] ~ vs[n - j];
		print!1("i:", i, " j:", j, " x:", xs[i][j]);
	}
	print!1("xs:", xs);
	
	long[] sum = [0];
	foreach(v; vs) sum ~= sum[$ - 1] + v;
	print!1("sum:", sum);
	
	long[][] ys = new long[][](k + 1, k + 1);
	foreach(i; 0 .. k + 1) foreach(j; 0 .. k + 1 - i){
		if(i + j > n) continue;
		ys[i][j] = sum[i] + sum[n] - sum[n - j];
		xs[i][j].sort();
		foreach(t, x; xs[i][j]) if(t < k - i - j) if(x < 0) ys[i][j] -= x;
	}
	print!1("ys:", ys);
	
	long ans = long.min;
	foreach(i; 0 .. k + 1) foreach(j; 0 .. k + 1 - i){
		if(i + j > n) continue;
		print!1("i:", i, " j:", j, " y:", ys[i][j]);
		ans = max(ans, ys[i][j]);
	}
	
	ans.writeln;
	
}


/*
いらない宝石を返す操作は、必ず最後にまとめて行うものとしてよい
その場合左とか右は関係ないのでゴミ箱に捨てると考えてよい
途中でも、いらない宝石はゴミ箱に捨てるものとして考えてよい

xs[i][j] = i回左から取り、j回右から取る場合の手持ち
	= vs[0 .. i] ~ vs[n - j .. n]
	= xs[i] ~ vs[n - j]

ys[i][j] = 
	= sum[i] + sum[n] - sum[n - j] - take(k - i - j)

求めるものは max(i, j) ys[i][j]


*/


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

using namespace std;

const int MAXN = 1e5 + 3;
int N,M;
int memo[MAXN];
vector < vector < int > > adj;

int dfs (int node) {
    if (memo[node]!=0) {
        return memo[node];
    }
    int tmp=0;
    for (auto i : adj[node]) {
        tmp = max(tmp,dfs(i));
    }
    memo[node] = tmp+1;
    return tmp+1;
}

int main() {
    scanf("%d%d",&N,&M);
    adj.resize(N+2);
    for (int i=0;i<M;i++) {
        int a, b;
        scanf("%d%d",&a,&b);
        a--,b--;
        adj[a].push_back(b);
    }
    int ans=0;
    for (int j=0;j<N;j++) {
        ans = max(ans,dfs(j));
    }
    printf("%d\n",ans-1);
    return 0;
}


Measured memory_bytes: 8192
import math

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

p = 0
nf = math.factorial(N)
X = [False]*N
for i in range(N):
    nf //= (N-i)
    x = X[:P[i]].count(True)
    p += nf * (P[i]-1-x)
    X[P[i]-1] = True

q = 0
nf = math.factorial(N)
X = [False]*N
for i in range(N):
    nf //= (N-i)
    x = X[:Q[i]].count(True)
    q += nf * (Q[i]-1-x)
    X[Q[i]-1] = True

print(abs(p-q))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int n;
struct P { double x, y;};
vector<P> p;

double dist(P a, P b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return dx*dx + dy*dy;
}
double f(double x, double y) {
  double res = 0;
  rep(i,n) {
    res = max(res, dist((P){x,y}, p[i]));
  }
  return res;
}

double g(double x) {
  // xを決めたときのf(x,y)の極小値を三分探索で計算
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (f(x,c1) > f(x,c2)) l = c1; else r = c2;
  }
  return f(x,l);
}

int main () {
  cin >> n;
  p = vector<P>(n);
  rep(i,n) cin >> p[i].x >> p[i].y;

  // f(x,y)を最小にするxを三分探索
  // 評価関数 g(x)はxに対して、yを好き勝手に動かしたときのf(x,y)の極小値
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (g(c1) > g(c2)) l = c1; else r = c2;
  }

  double ans = sqrt(g(l));
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint a;
  string b;
  cin>>a>>b;
  lint b_val=100*(b[0]-'0')+10*(b[2]-'0')+b[3]-'0';
  if(a*b_val<100){
    cout<<0<<endl;
    return 0;
  }
  string res=to_string(a*b_val);

  cout<<res.substr(0,res.size()-2)<<endl;


  return 0;
}




Measured memory_bytes: 3720
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int X = in.nextInt();
            int Y = in.nextInt();
            int Z = in.nextInt();

            X -= Z;

            System.out.println(X / (Y + Z));
        }
    }
}


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

#define ll long long
using namespace std;
#define MX 100000
map<ll,int> op;
void init()
{
	ll a1=0,a2=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ll temp;
		cin>>temp;
		if(op[temp]%2==1)
		{
			if(temp>a1)
			{
				a2=a1;
				a1=temp;
			}
			else if(temp>a2)
			{
				a2=temp;
			}
			
		}
		op[temp]++;
		
	}
    cout<<a1*a2<<endl;
}
int main()
{
   init();
   return 0;
}


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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = koujo(N, 2);
        System.out.println(N * 2 / ans);
    }

    int koujo(int n, int m) {
        if (m > n) {
            return koujo(m, n);
        }
        if (m == 0) {
            return n;
        }
        return koujo(m, n % m);
    }
}


Measured memory_bytes: 21972
#include<stdio.h>
int main(){
    int n,m;
    int i,j;
    int a[100][100];
    int b[100];
    int sum=0;
    
    scanf("%d %d",&n,&m);
    
    for (i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    
    for (i=0;i<n;i++){
        for(j=0;j<m;j++){
            sum+=a[i][j]*b[j];
        }
        printf("%d\n",sum);
        sum=0;
    }
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main() {
 int N, M;
  
  cin >> N >> M;
  vector<int> v(N);
  int t =0;
  for(int i=0;i < N;i++){
    int a;
    cin >> a;
    t += a;
    v.at(i) = a;
  }
  
  int c = 0;
  for(int i=0;i < N;i++){
    //   v.at(i) < t / 4M
    if ( 4 * M * v.at(i) >= t) {
      c++;
    }
  }
  
  if (c>=M) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int hmax = 0;
    for(int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        if (hmax <= tmp) ans++;
        hmax = max(hmax, tmp);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
//https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};

int d[10];
int k[10];
int main(){
    for(int i:range(3)){
        int a,b;
        cin>>a>>b;
        d[a]++;
        d[b]++;
    }
    for(int i:range(1,5)){
        k[d[i]]++;
    }
    if(k[1]==2&&k[2]==2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(){
  int i, j, k, n, b, f, r, v, arr[4][3][10]={0};
  scanf("%d", &n);
  for (i=0; i<n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    arr[b-1][f-1][r-1] += v;
  }

  for (i=0; i<4; i++) {
    for (j=0; j<3; j++) {
      for (k=0; k<10; k++) {
        printf(" %d", arr[i][j][k]);
      }
      printf("\n");
    }
    if (i<3) printf("####################\n");
  }
}


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

int main() {
  int N;
  double n;
  cin >> N;
  n=N;
  if(N%2==0){
    cout << 0.5 << endl;
  }else{
    if(N==1){
      cout << 1 << endl;
    }else{
      double ans;
      ans=((n+1)/2)/n;
      cout << ans << endl;
    }
  }
}



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

long long n, a, b;

int main() {
	cin >> n >> a >> b;
	if(a > b) swap(a, b);
	if((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
	}
	else {
		cout << (b - a + 1) / 2 + min(a - 1, n - b) << endl;
	}
	return 0;
}

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back

const int N = 100005;



void solve() {
	ld n;
	cin >> n;
	n *= 2;
	n *= M_PI;
	cout << setprecision(10) << fixed;
	cout << n;
	return ;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t; cin >> t; while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 3804
# https://atcoder.jp/contests/abc124/tasks/abc124_d

N, K = map(int, input().split())
S = input()
arr = []
prev = '1'
length = 0
for c in S:
  if prev != c:
    arr.append(length)
    length = 0
  length += 1
  prev = c
arr.append(length)
if S[-1] == '0':
  arr.append(0)

arr = [0] + arr
for i in range(len(arr) - 1):
    arr[i + 1] += arr[i]


L = K * 2 + 1
if L >= len(arr):
  print(N)
  exit()
ans = 0
for i in range(0, len(arr) - L, 2):
  t = arr[i+L] - arr[i]
  ans = max(ans, t)
print(ans)


Measured memory_bytes: 79660
using System;
using System.Linq;
using static System.Console;

class P
{
    static void Main()
    {
        var s = ReadLine();
        int ans = 0, max = 0;
        foreach (var c in s)
        {
            if (c == 'R') max++;
            else {
                ans = ans < max ? max : ans;
                max = 0;
            }
        }
        ans = ans < max ? max : ans;
        WriteLine(ans);
    }
}

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

int main(){
  	int H, N, sum;
  	cin >> H >> N;
  	for(int i=0; i<N; i++){
    	int A;
      	cin >> A;
      	sum+=A;
    }
  
  	if(sum>=H){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
	return 0;
}

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

int main(){
  int A,N,five_hun,rest;
  
  cin >> N >> A ;
  
  five_hun=N/500;
  rest=N%500;
  
  if(rest<=A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var r = ReadStringArray();
            string ret = string.Empty;
            foreach (var s in r)
            {
                ret += s.First().ToString().ToUpper();
            }

            Console.WriteLine(ret);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!
typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<"#x:"<<x<<endl
#define ERR2(x,y) cout<<"#x:"<<x<<" "<<"#y:"<<y<<endl;
#define ERR3(x,y,z) cout<<"#x:"<<x<<" "<<"#y:"<<y<<" "<<"#z:"<<z<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define all(v) v.begin(),v.end()

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>p(n);
	FOR(i,0,n)
	{
		cin>>p[i];
	}
	sort(all(p));
	int sum = 0;
	FOR(i,0,k)
	{
		sum += p[i];
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3600
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 
 
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n,k;
  std::cin>>n>>k;

  std::vector<ll> a(n),f(n);
  rep(i,0,n)std::cin>>a[i];
  rep(i,0,n)std::cin>>f[i];

  std::sort(all(a));
  std::sort(all(f));

  ll left=-1,right=1e12+10;

  while(right-left>1){
    ll mid=left+(right-left)/2;

    ll cnt=0;
    rep(i,0,n){
      if(f[i]*a[n-1-i]>mid){
        cnt+=(a[n-1-i]-mid/f[i]);
      }
    }

    if(cnt<=k)right=mid;
    else left=mid;
  }

  std::cout<<right;
 
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        if (i%2 == 1 && s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        } else if (i%2 == 0 && s[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
void _main() {
	int A,B;
	cin >> A>>B;
	cout << (B % A == 0? A + B : B - A) << endl;
}

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

namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

ll f(ll n) {
    return n / 5 + n / 3;
}

ll g(ll n) {
    return n / 5 + n / 3 - n / 15;
}

ll cnt(ll mid) {
    ll cnt = 0;
    for (ll k = 1; k <= mid; k *= 10) {
        ll keta = 0;
        for (ll kk = k; kk > 0; kk /= 10) keta++;
        ll cap = min(k * 10 - 1, mid);
        ll f1 = f(cap);
        ll f2 = f(k-1);
        ll g1 = g(cap);
        ll g2 = g(k-1);
        cnt += (f1 - f2) * 4 + ((cap - k + 1) - (g1 - g2)) * keta;
    }
    return cnt;
}
 
int main() {
    ll N;
    cin >> N;

    ll hi = 100000000000000000;
    ll lo = 0;

    while (hi - lo > 1) {
        ll mid = (hi + lo) / 2;
        if (cnt(mid) >= N) hi = mid;
        else lo = mid;
    }

    
    string ans;
    int amari = cnt(hi) - N;
    
    if (hi % 15 == 0) {
        ans = "FizzBuzz";
    } else if (hi % 5 == 0) {
        ans = "Buzz";
    } else if (hi % 3 == 0) {
        ans = "Fizz";
    } else {
        ans = patch::to_string(hi);
    }
    ans = ans.substr(ans.size() - amari - 1, amari + 1);

    while (ans.size() < 20) {
        hi += 1;
        if (hi % 15 == 0) {
            ans += "FizzBuzz";
        } else if (hi % 5 == 0) {
            ans += "Buzz";
        } else if (hi % 3 == 0) {
            ans += "Fizz";
        } else {
            ans += patch::to_string(hi);
        }
    }
    
    cout << ans.substr(0, 20) << endl;

    return 0;
}

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

const int MOD = 1000000007;

using namespace std;
class Solver {
public:
    void solve();
};


void Solver::solve() {
    // 入力
    int n;
    string S;
    cin >> n >> S;
    
    vector<int> a(26, 0);
    for (int i = 0; i < S.size(); ++i) {
        int index = S[i] - 'a';
        a[index]++;
    }
    long long ans = 1;
    for (auto c : a) {
        ans *= (c + 1);
        ans %= MOD;
    }
    ans -= 1;
    cout << ans << endl;
}

int main() {
    Solver solver = Solver();
    solver.solve();
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
typedef pair<ll,ll> RR;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

ll pt[51]={0},so[51]={0};

ll band(int lv,ll &k){
    ll ans=0;
    if(lv==0){
        k--;
        return 1;
    }
    k--;
    if(k<=0) return ans;

    if(so[lv-1]<k){
        k-=so[lv-1];
        ans+=pt[lv-1];
    }else{
        ans+=band(lv-1,k);
        if(k<=0) return ans;
    }
    
    ans++;
    k--;
    if(k<=0) return ans;

    if(so[lv-1]<k){
        k-=so[lv-1];
        ans+=pt[lv-1];
    }else{
        ans+=band(lv-1,k);
        if(k<=0) return ans;
    }

 //   printf("B");
    k--;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N;
    ll K;
    cin >>N>>K;
    //-----------------------------------
    pt[0]=1;
    so[0]=1;
    repd(i,1,51){
        pt[i]=pt[i-1]*2+1;
        so[i]=so[i-1]*2+3;
    }
    ll ans=0,i=0;
    ans=band(N,K);


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

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        List<Long> a = new ArrayList<>();
        IntStream.range(0, n).forEach(i -> a.add(sc.nextLong()));

        Collections.sort(a);

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            if (x < a.get(i)) {
                break;
            }
            x -= a.get(i);
            count++;
        }
        if (x == a.get(n - 1)) {
            count++;
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 28116
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N = sc.nextInt();
        int[] x =new int[N];
        int[] y =new int[N];
        int[] h =new int[N];
        
        for(int i=0;i<N;i++){
            x[i]=sc.nextInt();
            y[i]=sc.nextInt();
            h[i]=sc.nextInt();
        }
        for(int X =0;X<=100;X++){
            for(int Y=0;Y<=100;Y++){
                boolean ok=true;
                int H=0;
                for(int i=0;i<N;i++){
                    if(h[i]!=0){
                        H=Math.abs(x[i]-X)+Math.abs(y[i]-Y)+h[i];
                    }
                }
                for(int i=0;i<N;i++){
                    if(h[i]!=0){
                        if(H != Math.abs(x[i]-X)+Math.abs(y[i]-Y)+h[i]){
                            ok=false;
                        }
                    }else{
                        if(H > Math.abs(x[i]-X)+Math.abs(y[i]-Y)){
                            ok=false;
                        }
                    }
                }
                if(ok){
                    System.out.println(X +" "+Y+" "+H);
                }
            }
        }
    }
}

Measured memory_bytes: 23464
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    vector<ll> b(n, 0);
    rep(i, 33){
        int m = 0;
        rep(j, n)if(1 & (a[j] >> i))m++;
        if(m % 2 == 0){
            rep(j, n){
                if(1 & (a[j] >> i)){
                    b[j] += (1 << i);
                }
            }
        }else{
            rep(j, n){
                if(!(1 & (a[j] >> i))){
                    b[j] += (1 << i);
                }
            }
        }
    }
    rep(i, n)cout << b[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 6420
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int a[100005],maxi[100005];
void solve() {
	int n;
	cin>>n;
	fr(i,0,n)
		cin>>a[i];
	int down=0,ans=0,mihere=0;
	maxi[0]=1;
	fr(i,1,n) {
		maxi[i]=(maxi[i-1]-a[i-1])*2;
		maxi[i]=min(maxi[i],infl);
	}
	for(int i=n; i>=0; i--) {
		ans+=a[i];
		int mahere=down;
		ans+=mahere;
		mihere=(mihere+1)/2;
		mahere+=a[i];
		mihere+=a[i];
		trace(i,mihere,(1LL<<i),down);
		if(maxi[i]<mihere) {
			cout<<-1<<endl;
			return;
		}
		ans-=max(0LL,mahere-maxi[i]);
		mahere=min(mahere,maxi[i]);
		down=mahere;
	}
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 5180
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define int long long
#define fori(j,n) for(int i=j;i<n;i++)
#define forb(n,j) for(int i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define PI 3.141592653589793
#define M 1000000007
using namespace std;
int fast(int a,int b)
{
    int ans=1;
    a=a%M;
    if(a==0)
        return 0;
    while(b>0)
    {
        if(b&1)
        {
            ans=(ans*a)%M;
        }
        b>>=1;
        a=(a*a)%M;
    }
}
int h[100010];
int n;
int dp[100010];
int fun(int i)
{
    if(i==n)
        return 0;
    if(i>n)
        return INT_MAX;
    if(dp[i]!=-1)
        return dp[i];
    int left=abs(h[i]-h[i+1])+fun(i+1);
    int right=INT_MAX;
    if(i+2<=n)
        right=abs(h[i]-h[i+2])+fun(i+2);
    dp[i]=min(left,right);
    return min(left,right);
}
int32_t main()
{
    IOS;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    fori(1,n+1)
        cin>>h[i];
    cout<<fun(1);
    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        if(a >= b){
            System.out.println("delicious");
        }else if(b - a <= x){
            System.out.println("safe");
        }else{
            System.out.println("dangerous");
        }
    }
}

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

vector<int> vis;
vector<vector<int>> g;

int dfs(int x) {
  int ret = 1;
  vis[x] = 1;
  for (auto v : g[x]) {
    if (!vis[v]) {
      ret += dfs(v);
    }
  }
  return ret;
}

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

  int n, m;
  cin >> n >> m;
  
  g.resize(n);
  vis.resize(n, 0);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    
    g[u].push_back(v);
    g[v].push_back(u);
  }
  
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      ans = max(ans, dfs(i));
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 21068
using System;

namespace AtcoderProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var r = int.Parse(line[0]);
            var g = int.Parse(line[1]);
            var b = int.Parse(line[2]);
            var n = int.Parse(line[3]);

            var conb = 0;

            for(int i=0; i *b <n+1; i++)
            {
                conb += pair(r, g, n - b * i);
              
            }

            Console.WriteLine(conb);

        }

        static int pair(int r, int g, int n)
        {
            int conb = 0;
            for(int i=0; i*r< n+1; i++)
            {
                if ((n - r * i) % g == 0 ) {
                    conb++;
                } 
            }
            return conb;
        }
    }

}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
typedef long long ll;

int main(){

	int K, H, W, B, flag = 0, i, j, k, l, ans_0 = 0, ans_W = 0, len, max_i=0;
	double sum = 0.0;
	char N[101];
	long long dp[101][4][2] = {0};

	scanf("%s %d", N, &K);


	len = strlen(N);
//	printf("%d\n", len);


	dp[0][0][0] = 1;
	for (i = 0; i < len; i++){
		int temp = N[i] - '0';
		for (j = 0; j <= K; j++){
			for (k = 0; k < 2; k++){
				for (l = 0; l < 10; l++){ //桁だと10個の数字それぞれに対して判定するらしい
					int ni = i + 1, nj = j, nk = k;//i+1は次の遷移先 jは今までに非ゼロをj個使ってる仮定だから減ることはない、この桁で増えるのは高々1個なので++だけする　kは一致しているかしてないか
					if (l != 0) nj++;
					if (nj > K) continue;
					if (k == 0){
						if (l > temp) continue;
						if (l < temp) nk = 1;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}

		}
	}


	int ans = dp[len][K][0] + dp[len][K][1];

	printf("%lld\n", ans);


	return 0;

}
    


Measured memory_bytes: 256