akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();

        int ans = (a - 1) * (b - 1);
        System.out.println(ans);
    }

}


Measured memory_bytes: 21716
#include<stdio.h>
int main(void){
int x,y,z,p;
scanf("%d",&p);
  x=p/3600;
  y=(p-3600*x)/60;
  z=p-3600*x-60*y;
printf("%d:%d:%d\n",x,y,z);




 return 0;
}

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


int main(){
    int N;
    cin >> N;
    int res = 0;


    for(int i=1; i<=N; i+=2){
        int num=0;
        for(int j=1; j<=i; j++){
            if (i%j ==0){
                num++;
            }
        }
        if(num==8){
            res++;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
A, B, M = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
r = min(a) + min(b)
for i in range(M):
  x, y, c = [int(x) for x in input().split(' ')]
  r = min(r, a[x-1] + b[y-1] - c)
print(r)

Measured memory_bytes: 70084
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	string s;
	scans(s);
	map<char, int> a;
	for (auto aa : s)a[aa]++;
	printf("%d\n", min(a['1'], a['0']) * 2);

	Please AC;
}


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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int main() {
	speed;
	int k, x;
	cin >> k >> x;
	vector<int>a(2*k-1);
	a[k-1] = x;

	for (int i = 1; i< k; i++) {
		a[k-1 - i] = x - i;
		a[k-1 + i] = x + i;
	}

	for (auto b : a) {
		cout << b << " ";
	}
	ed;
	return 0;
}


Measured memory_bytes: 256
require 'pp'

n = gets.to_i

d = gets.split.map(&:to_i)

if d[0] != 0
  p 0
  exit
end

if d[1..-1].any?{|dd|dd == 0}
  p 0
  exit
end

d2 = d[1..-1]

d3 = d2.group_by{|x|x}.map{|k,v|[k,v.size]}.sort_by{|x|x[0]}
#[距離, 個数]
# p d3
if d3[-1][0] > d3.size
  p 0
  exit
end
# p d3
ans = 1
(d3.size-1).times do |i|
  ans *= d3[i][1] ** d3[i+1][1]
  ans = ans % 998244353
end
p ans % 998244353
# 2 0 24


Measured memory_bytes: 29816
#import math
import fractions as math

N = int(input())
A = list(map(int, input().split()))

gcd_l, gcd_r = [0], [0]

for l, r in [(A[i], A[N-i-1]) for i in range(N)]:
    gcd_l.append(math.gcd(gcd_l[-1], l))
    gcd_r.append(math.gcd(gcd_r[-1], r))
gcd_r.reverse()

gcd_nums = [gcd_l[-1]] + [math.gcd(gcd_l[i], gcd_r[i+1]) for i in range(N)]
print(max(gcd_nums))

Measured memory_bytes: 19224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int calc = N % 1000;
        int readyMoney = 0;
        if (calc == 0) {
            readyMoney = 1000 * (N / 1000);
        } else {
            readyMoney = 1000 * (N / 1000 + 1);
        }
        int change = readyMoney - N;
        System.out.println(change);
    }
}

Measured memory_bytes: 35568
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val nodes = Array(n) { Node() }
    for (i in 0 until n - 1) {
        val u = sc.nextInt() - 1
        val v = sc.nextInt() - 1
        val w = sc.nextInt()
        if (w % 2 == 0) {
            nodes[u].even.add(nodes[v])
            nodes[v].even.add(nodes[u])
        } else {
            nodes[u].odd.add(nodes[v])
            nodes[v].odd.add(nodes[u])
        }
    }
    nodes[0].dfs(0)
    println(nodes.map { it.color }.joinToString("\n"))
}

class Node {
    var color = 0
    var decided = false
    val even = ArrayList<Node>()
    val odd = ArrayList<Node>()
    fun dfs(color: Int) {
        this.color = color
        this.decided = true
        even.forEach {
            if (!it.decided) it.dfs(color)
        }
        odd.forEach {
            if (!it.decided) it.dfs(1 - color)
        }
    }
}


Measured memory_bytes: 129552
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 1; i <= (ll)c; i++)
#define ll long long
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
const int inf = 1000000000; // 10^9

int main(){
    double r, pi;
    cin >> r;

    pi = 3.1415926535;
    cout << r * 2 * pi << endl;

    return 0;
}

Measured memory_bytes: 3784
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 3000005;
const int maxm = maxn*2;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

char s[100];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>(s+1);
    int n = strlen(s+1);
    ll ans = 0;
    for(int len = 1;len <= n;len++) {
        for(int i = 1;i + len - 1<=n;i++) {
            int j = i + len - 1;
            ll x = 0;
            for(int k = i;k<=j;k++) x = x*10 + s[k] - '0';
            ll num = max(0,n-j-1) + max(0,i-2);
            ans += 1ll*x*(1<<num);
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split('\n');

  N = parseInt(input[0], 10);
  A = input[1].split(' ');

  var S = Array(N + 1);
  for(var x = 0; x < N; x++) {
    S[A[x]] = x + 1;
  }
  S.shift();

  for(var x = 0; x < N; x++) {
    console.log(S[x]);
  }


}
Main(require('fs').readFileSync('/dev/stdin', 'utf-8'));


Measured memory_bytes: 34976
#include <iostream>

using namespace std;

int main(void){
    int p,q,r;
    cin >> p >> q >> r;
    if(p < q){
        if(q < r){
            cout << p + q << endl;
        }else{
            cout << p + r << endl;
        }
    }else{
        if(p < r){
            cout << p + q << endl;
        }else{
            cout << r + q << endl;
        }
    }
}

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


public class Program{
    public static void Main(){
        TextReader reader;
        string filename="";
        if(filename.Length!=0){
            reader = new StreamReader(filename);
        }else{
            reader = Console.In;
        }
        //どの文字がいくつあるかを毎回最小で更新
        var n = int.Parse(reader.ReadLine());
        //最初に一文読み込んでこいつをもとにして探索
        var BigList = new Dictionary<char, int>();
        var firstLine = reader.ReadLine();
        foreach(var c in firstLine){
            if(BigList.ContainsKey(c)){
                BigList[c]++;
            }else{
                BigList[c] = 1;
            }
        }
        //次から読み込まれる文で、最初に読み込まれた文字とすべての文字が一致しない場合は脈なしでエンド
        //一致したものがあればその個数を出し、既に読み込まれている文字の該当する文字の個数とを比較して小さいほうで更新
        var flag = true;
        for(int i=0; i<n-1; i++){
            var tempList = new Dictionary<char, int>();
            var line = reader.ReadLine().ToCharArray();
            if(line.Any(c=>BigList.ContainsKey(c))){
                foreach(var ele in line){
                    if(BigList.ContainsKey(ele)){
                        var num = line.Where(c=>c==ele).Count();
                        tempList[ele] = Math.Min(num, BigList[ele]);
                    }
                }
            }else{
                //脈なし
                flag = false;
                break;  
            }
            //今の文字列に含まれる文字と最初に取っている文字との積集合
            var nexKey = BigList.Keys.Intersect(tempList.Keys);
            var nexDict = new Dictionary<char, int>();
            foreach(var yo in nexKey){
                nexDict[yo] = tempList[yo];
            }
            BigList = new Dictionary<char, int>(nexDict);
        } 
        string ans = "";
        foreach(var key in BigList.Keys.OrderBy(o=>o).ToArray()){
            for(int i=0; i<BigList[key]; i++){
                ans+=key;
            }
        }        
        if(flag){
            Console.WriteLine(ans);
        }else{
            Console.WriteLine();
        }
    }

}


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

using namespace std;

const int MAX_N = 1e6 + 10;

list<char> S;
char A = 'A', B = 'B', C = 'C';
int cntA, cntB, cntC;

void init() {
    char t[MAX_N]; scanf("%s", t);
    S.insert(S.end(), t, t + strlen(t));
    char last = 0;
    for (list<char>::iterator i = S.begin(), j; i != S.end(); i = j) {
        j = next(i);
        if (*i == last) S.erase(i);
        else last = *i;
    }
}

void dump() {
    for (char ch : S)
        printf("%c", ch);
    printf("\n");
}

void solve() {
    for (char ch : S) {
        if (ch == A) cntA++;
        if (ch == B) cntB++;
        if (ch == C) cntC++;
    }

    if (!cntA || !cntB || !cntC) {
        printf("\n");
        return;
    }

    if (cntB < cntA) swap(A, B), swap(cntA, cntB);
    if (cntC < cntA) swap(A, C), swap(cntA, cntC);
    int fB = 0, gB = 0, fC = 0, gC = 0;
    int segB = 0, segC = 0;
    bool first = true;
    for (char ch : S) {
        if (ch == A) {
            if (segB) fB++;
            if (segC) fC++;
            if (!first) {
                if (segB == 1 && segC == 0) gB++;
                if (segC == 1 && segB == 0) gC++;
            } else first = false;
            segB = segC = 0;
        }
        if (ch == B) segB++;
        if (ch == C) segC++;
    }
    if (segB) fB++;
    if (segC) fC++;

    if (gB > fC) {
        swap(B, C);
        swap(cntB, cntC);
        swap(fB, fC);
        swap(gB, gC);
    }

    if (gC > fB) {
        int delta = gC - fB;
        for (list<char>::iterator i = S.begin(); delta && i != S.end(); i++) {
            while (delta && *i == C && i != S.begin() && *prev(i) == A && next(i) != S.end() && *next(i) == A) {
                if (i != S.begin()) {
                    S.erase(prev(i));
                    if (i != S.begin() && *prev(i) == C)
                        S.erase(prev(i));
                } else {
                    S.erase(next(i));
                    if (next(i) != S.end() && *next(i) == C)
                        S.erase(next(i));
                }

                delta--;
            }
        }
    }

    cntA = cntB = cntC = 0;
    fB = fC = gB = gC = 0;

    for (char ch : S) {
        if (ch == A) cntA++;
        if (ch == B) cntB++;
        if (ch == C) cntC++;
    }

    if (cntB > cntC) {
        swap(B, C);
        swap(cntB, cntC);
    }

    for (list<char>::iterator i = S.begin(), j; cntB < cntC && i != S.end(); i = j) {
        j = next(i);
        if (*i == C && (i == S.begin() || next(i) == S.end() || *prev(i) != *next(i))) {
            cntC--;
            S.erase(i);
        }
    }

    for (list<char>::iterator i = S.begin(), j; cntA < cntB; i = j) {
        j = next(i);
        if (j == S.end()) continue;
        if ((*i == B || *j == B) && (*i == C || *j == C) && (i == S.begin() || next(j) == S.end() || *prev(i) != *next(j))) {
            j = next(j);
            S.erase(next(i));
            S.erase(i);
            cntB--;
            cntC--;
        }
    }

    for (char ch : S)
        printf("%c", ch);
    printf("\n");
 }

int main() {
    init();
    solve();
}


Measured memory_bytes: 33408
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 13052
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int check[1000001];
    for(int i = 1; i < 1000001; i++) check[i] = 1;
    int count = 0;
    for(int j = 0; j < n; j++){
        if(j > 0 && a[j] == a[j-1]){
            if(check[a[j]] == 1){
                check[a[j]] = 0;
                count--;
            }
        }
        if(check[a[j]] == 0) continue;
        count += check[a[j]];
        for(int i = a[j]*2; i <= 1000000; i+=a[j]){
            check[i] = 0;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 8012
#include <iostream>
using namespace std;
#define MAX 100

int selectionSort(int a[], int n){
    int sw = 0;
    for(int i = 0; i < n - 1; i++){
        int minj = i;
        for(int j = i + 1; j < n; j++){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        if(a[i] > a[minj]){
            swap(a[i], a[minj]);
            sw++;
        }
    }
    return sw;
}

int main(){
    int n;
    cin >> n;
    int a[MAX];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int sw = selectionSort(a, n);
    for(int i = 0; i < n; i++){
        cout << a[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;
    cout << sw << endl;
    return 0;
}



Measured memory_bytes: 3096
n=int(input())
s=list(input())
hantei=0
m=int(n/2)
if n%2==0:
	for i in range(m):
		if s[i]!=s[i+m]:
			hantei=1
			break
else:
	hantei=1
if hantei==0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
N = int(input())
(a,w,t,r) = (0,0,0,0)
for i in range(N):
  s = input()
  if s == 'AC':
    a += 1
  elif s == 'WA':
    w += 1
  elif s == 'TLE':
    t += 1
  elif s == 'RE':
    r += 1
    
print('AC x '+str(a))
print('WA x '+str(w))
print('TLE x '+str(t))
print( 'RE x '+str(r))

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

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int m = 1_000_000_007;
        int N = sc.nextInt();
        long[] A = new long[(int) N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }
        long res = 0;
        for (int d = 0; d < 60; d++) {
            long n0 = 0, n1 = 0;
            for (int i = 0; i < N; i++) {
                if ((A[i] & (1L << d)) != 0) {
                    n1++;
                } else {
                    n0++;
                }
            }
            long tmp = (1L << d) % m;
            long n = n0 * n1 % m;
            tmp = tmp * n;
            res += tmp % m;
            res %= m;
        }
        out.println(res);
        out.flush();
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 30132
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;

double f(double x){
    return 32*pow(x, 4)+192*pow(x, 3)+444*pow(x, 2)+468*x+190;
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<int, int>> v(N);
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        v[i] = make_pair(a, b);
    }
    sort(v.begin(), v.end());
    priority_queue<int> pq;
    int idx = 0;
    int d = 1;
    ll ans = 0;
    while(d <= M){
        while(idx < N && v[idx].first <= d){
            pq.push(v[idx].second);
            idx++;
        }
        if(!(pq.empty())){
            ans += pq.top();
            pq.pop();
        }
        d++;
    }
    cout << ans << endl;
}



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

int a, b, c;

int main () {
	cin >> a >> b >> c;
	if ((a==b)&&(b==c)&&(a==c)){
		cout << "Yes" << endl;
	}else if ((c>=a)&&(c<b)){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#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;
    vector<int> s(M), c(M);
    rep(i,M) {
        cin >> s.at(i) >> c.at(i);
        --s.at(i);
    }
    string ans;
    bool exist = true;
    vector<int> num(N, -1);
    rep(i,M) {
        if (num.at(s.at(i)) != -1 && num.at(s.at(i)) != c.at(i)) {
            exist = false;
            break;
        } else {
            num.at(s.at(i)) = c.at(i);
        }
    }
    if (exist == true) {
        rep(i,N) {
            if (i != 0 || (i == 0 && N == 1)) {
                if (num.at(i) == -1) {
                    ans.push_back('0');
                } else {
                    ans.push_back('0' + num.at(i));
                }
            } else {
                if (num.at(0) == 0) {
                    exist = false;
                    break;
                } else if (num.at(0) == -1) {
                    ans.push_back('1');
                } else {
                    ans.push_back('0' + num.at(0));
                }
            }
        }
    }
    if (exist == false) ans = "-1";
    cout << ans << endl;
}


Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    int ans=0;
    for(auto ch:s)if(ch=='2') ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define pp pair<int,int>
#define N 200007 // check
#define K 13
using namespace std;

int n;

int tab[N];
int rev[N];

int pref[N];

int best = 1e17;

int get(int a, int b) {
    return pref[b+1]-pref[a];
}

int minimal(int a, int b) {
    int l = a; int p = b;
    while(p-l > 4) {
        int s = (l+p)/2;
        if(get(a,s)*2 <= get(a,b)) {
            l = s;
        } else {
            p = s;
        }
    }
    int res = 1e17;
    for(int i = l; i <= min(p+1,b-1); ++i) {
        res = min(res, abs(get(a,i)-get(i+1,b)));
    }
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> tab[i];
    pref[0] = 0;
    for(int i = 1; i <= n; ++i) pref[i] = pref[i-1] + tab[i-1];

    for(int i = 0; i < n-1; ++i) {
        int a = abs((get(0,i)-minimal(0,i))/2 + minimal(0,i) - (get(i+1,n-1)-minimal(i+1,n-1))/2);
        int b = abs((get(i+1,n-1)-minimal(i+1,n-1))/2 + minimal(i+1,n-1) - (get(0,i)-minimal(0,i))/2);
        int c = minimal(0,i);
        int d = minimal(i+1,n-1);
        best = min(best, max(max(a,b),max(c,d)));
    }
    cout << best << endl;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    // dp[i][j][exact/smaller] := 上からi桁目を見たときのj個0でない数字が含まれている0より大きい数の数
    vector<VVL> dp(n+1, VVL(10, VL(2,0)));
    dp[0][0][0] = 1;
    rep(i, 1, n+1){
        // smaller -> smaller
        rep(j, 0, k+1){
            dp[i][j+1][1] += 9*dp[i-1][j][1];
            dp[i][j][1] += dp[i-1][j][1];
        }
        // exact -> smaller
        rep(j, 0, k+1){
            if(s[i-1] != '0'){
                dp[i][j+1][1] += (s[i-1]-'0'-1) * dp[i-1][j][0];
                dp[i][j][1] += dp[i-1][j][0];
            }
        }
        // exact -> exact
        rep(j, 0, k+1){
            if(s[i-1] == '0') dp[i][j][0] = dp[i-1][j][0];
            else dp[i][j+1][0] = dp[i-1][j][0];
        }
    }
    cout << dp[n][k][0] + dp[n][k][1] << endl;
    return 0;
}

Measured memory_bytes: 256
// OURL: https://atcoder.jp/contests/abc137/tasks/abc137_b
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x,k;
  cin >> k>>x;
  RREP(i,x-k+1,x+k) {
    cout << i << ' ';
  }
  cout << endl;
  return 0;
}




Measured memory_bytes: 256
A, B = map(int, input().split())
# print(A, B)

if B == 1:
    print(0)
    exit()

if B <= A:
    print(1)
    exit()

count = 1
remain = B - A
while True:
    if remain <= 0:
        print(count)
        break
    count += 1
    remain -= (A - 1)


Measured memory_bytes: 38256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, p[128];
	while (~scanf("%d", &n))
	{
		rep (i, n)
			scanf("%d", p + i);
		sort(p, p + n);
		int sum[128];
		sum[0] = 0;
		rep (i, n)
			sum[i + 1] = sum[i] + p[i];
		printf("%d\n", accumulate(sum, sum + (n + 1), 0));
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>

#define ll long long

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

    // 試すのはAとBだけでよい
    ll ans = 0;
    for(int i = 1; i <= N; i++) {
        ans += (N-1) / i;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#define MAXN 210
#define INF 0x3f3f3f3f

using namespace std;

int main()
{
    int x, a, b;
    while(cin>>x>>a>>b)
    {
        x -= a;
        x = x - x / b * b;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int a, b;
  cin >> a >> b;

  int ans = 2 * max(a, b) - (a != b);
  cout << ans << endl;

  return 0;
}


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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("c.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n;
    cin >> n;

    vector<int> d(n);
    rep(i, n) cin >> d[i];

    sort(d.begin(), d.end());

    if (d[n/2-1] == d[n/2])
    {
        cout << 0;
    }
    else
    {
        cout << d[n/2]- d[n/2-1];
    }

    return 0;
}


Measured memory_bytes: 640
def reachable?(v, g)
  #p [:reachable?, v, g]
  que = [0]
  v.each do |d|
    #p [d, que]
    que2 = {}
    que.each do |x|
      que2[x+d] = true
      que2[x-d] = true
    end
    que = que2.keys
  end
  #p [que]
  
  que.include?(g)
end


dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]

s = gets.chomp
gx, gy = gets.split.map(&:to_i)

xs = [0]
ys = []
o = 0
s.each_char do |c|
  #p [[xs, ys, o], c]
  if c == 'F'
    ((o%2 == 0) ? xs : ys)[-1] += 1
  else
    o = 1-o
    ((o%2 == 0) ? xs : ys) << 0
  end
end

#p [xs, ys, o]
gx -= xs.shift
#p [xs, ys, o]
puts (reachable?(xs, gx) && reachable?(ys, gy)) ? 'Yes' : 'No'


Measured memory_bytes: 88316
#d
#the niumbers of evens is important
#the point is, there is no influence to odd/even if you divide them by odd numbers.
#You should do simulation only in the case where there is one odd over 3 and even numbers of even numbers

from fractions import gcd

def count(a):
    odd, even = 0,0
    for x in a:
        if x % 2 == 1: odd = odd + 1
        else: even = even + 1
    return odd,even

def deal(n,a):
    odd,even = count(a)
    if even == 0:
        return False
    if even % 2 == 1:
        return True
    if odd > 1:
        return False
    
    #the case where there is one odd (over 3) and even numbers of even numbers
    #calculate gcd by step by step
    #if you write g = 1, it is a lie.
    if a[0] % 2 == 0:
        g = a[0]
    else:
        g = a[1]
        
    for i in range(0,n):
        if a[i] % 2 == 1:
            if a[i] == 1: 
                return False
            a[i]  -= 1
        g = gcd(a[i], g)
    return not deal(n,list(map(lambda x: x//g,a)))

n = int(input())
a = [int(i) for i in input().split()]
if deal(n,a):
    print('First')
else:
    print('Second')


Measured memory_bytes: 90412
n , m = (int(a) for a in input().split())
ans = [0]*n
ng = [0]*n
NG = 0
for i in range(m) :
    p,s = input().split()
    p = int(p)
    if s == "AC" :
        if ans[p-1] == 0 :
            NG += ng[p-1]
            ans[p-1] = 1
    else :
        if ans[p-1] == 0 :
            ng[p-1] += 1

print(ans.count(1) , NG)

Measured memory_bytes: 10244
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    bool ok = true;
    for(int i=0; i<N; i++) {
        int A; cin >> A;
        if(A % 2 == 1) continue;
        bool ok2 = false;
        ok2 |= (A % 3 == 0);
        ok2 |= (A % 5 == 0);
        ok &= ok2;
    }
    cout << (ok ? "APPROVED" : "DENIED") << endl;
    return 0;
}


Measured memory_bytes: 256
def factorial(n):
  ans = 1
  for i in range(n):
    ans *= i+1
    ans %= mod
  return ans


mod = 998244353
n = int(input())
s = input()
ans = 1
r,g,b = 0,0,0
rg,rb,gb = 0,0,0
for i in s:
  if i == "R":
    if gb > 0:
      ans *= gb
      gb -= 1
    elif g > 0:
      ans *= g
      g -= 1
      rg += 1
    elif b > 0:
      ans *= b
      b -= 1
      rb += 1
    else:
      r += 1
  elif i == "G":
    if rb > 0:
      ans *= rb
      rb -= 1
    elif r > 0:
      ans *= r
      r -= 1
      rg += 1
    elif b > 0:
      ans *= b
      b -= 1
      gb += 1
    else:
      g += 1
  elif i == "B":
    if rg > 0:
      ans *= rg
      rg -= 1
    elif r > 0:
      ans *= r
      r -= 1
      rb += 1
    elif g > 0:
      ans *= g
      g -= 1
      gb += 1
    else:
      b += 1
  ans %= mod
print((factorial(n) * ans) % mod)

Measured memory_bytes: 49192
s=list(input())
num=(len(s)-2)//2
def moji(s): #偶文字列か調べる
    c=0
    half=len(s)//2
    for i in range(half):
        if s[i]!=s[i+half]:
            c=1
            break
    return c

exit=0
for i in range(num):
    del s[-1]
    del s[-1]
    check=moji(s)
    if check==0: #偶文字列の場合
        exit=1
        break
print(len(s) if exit==1 else 1)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append("x");
        }
        System.out.println(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 21844
n = int(input())
a = list(map(int,input().split()))

s = 0
count1 = 0
for i in range(n):
    s+=a[i]
    if i%2==1:
        if s<=0:
            count1 += -s + 1
            s = 1
    else:
        if s>=0:
            count1 += s + 1
            s = -1

s = 0
count2 = 0
for i in range(n):
    s+=a[i]
    if i%2==0:
        if s<=0:
            count2 += -s + 1
            s = 1
    else:
        if s>=0:
            count2 += s + 1
            s = -1

print(min(count1,count2))

Measured memory_bytes: 63088
#include <bits/stdc++.h>
using namespace std;
int occur( vector< int> v, int b){
    int c=0;
        for(int i=0;i<v.size();i++){
            if (b==v[i]) c++;
        }
        return c;
    }
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector< int> v;
	set<int > s;
	int l;
	cin >> l;
	vector<int > vi;

	for(int i=0;i<l;i++){
        int a;
        cin >>  a;
        v.push_back(a);
        s.insert(a);
	}

	for(auto it=s.begin();it!=s.end();it++) vi.push_back(*it);
	if (s.size()<=2) {cout << 0; return 0;}
	int c=0;
	auto it=s.begin();
	for(int i=2;i<s.size();i++){
        for(int j=1;j<i;j++){
            for(int k=0;k<j;k++){

                if (vi[i]+vi[j]>vi[k] && vi[k]+vi[j]>vi[i] && vi[i]+vi[k]>vi[j]){
                    int ci=occur(v,vi[i]);
                     int ck=occur(v,vi[k]);
                     int cj=occur(v,vi[j]);
                    c=c+ci*cj*ck;
                }
            }
        }
	}
	cout << c;
	return 0;
}


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

using namespace std;

int main(){
    string S;
    //Sを定義
    cin >> S;
    //標準入力
    string ans = "yes";
    //出力用の文字列変数ansを定義
    for(int i = 0; i < S.length()-1; i++){
        for(int  j = i + 1; j < S.length(); j++){
        if(S[i] == S[j]){
                ans = "no"; 
                //被ったのでnoに書き換え
            } 
        }
    }
    cout << ans << endl; 
    //結果を出力
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int n, cnt = 0;
	cin>>n;
	vector<int> vect(n+1);
	set<int> st;
	for(int i=1; i<=n; i++)
		cin>>vect[i];
	int start = 1;
	while(!st.count(start) && start!=2)
	{
		st.insert(start);
		start = vect[start];
		cnt++;
	}
	if(start==2)
		cout<<cnt<<"\n";
	else
		cout<<"-1\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 8188
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

long long gcd2(long long a, long long b) {
  if (b == 0) {
    return a;
  }

  return gcd2(b, a % b);
}

long long gcd3(long long a, long long b, long long c) {
  // if (c == 0) {
  //   return gcd2(a, b);
  // }

  return gcd2(gcd2(a, b), gcd2(a, c));
}

int main() {
  int K;
  scanf("%d", &K);

  long long sum = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        int g = gcd3(i, j, k);
        // cout << "i: " << i << ", j: " << j << ", k: " << k << " -> " << g << endl;
        sum += g;
      }
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3256
N = int(input())

if (N % 10 == 2 or N % 10 == 4 or N % 10 == 5 or N % 10 == 7 or N % 10 == 9):
  print('hon')
elif (N % 10 == 0 or N % 10 == 1 or N % 10 == 6 or N % 10 == 8):
  print('pon')
elif (N % 10 == 3):
  print('bon')


Measured memory_bytes: 9180
#include <stdio.h>

int main(void)
{
	int i;
	char cl[10][16];
	int gozen;
	int gogo;
	int sum[9];
	int rieki[9];
	
	for (i = 0;i < 9; i++){
		scanf("%s %d %d", &cl[i], &gozen, &gogo);
		sum[i] = gozen + gogo;
		rieki[i] = (gozen * 200) + (gogo * 300);
	}
	
	for (i = 0; i < 9; i++){
		printf("%s %d %d\n", cl[i], sum[i], rieki[i]);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  ll M;  
  IN(N);
  IN(M);

  PRINT((N<=M)?"unsafe":"safe");

}


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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}



int main(){
  ll n;
  int ans = 0;
  cin>>n;
  vector<ll> v(n);
  map<ll, vector<pair<ll, ll>>> m;
  for(int i=0; i<n; i++) {
    cin>>v[i];
    for(int j=0; j<v[i]; j++) {
      ll x, y;
      cin>>x>>y;
      m[i].push_back(make_pair(x-1, y));
    }
  }
  for(int b = 0; b < (1<<n); ++b) {
    set<int> t;
    set<int> f;
    for(int i=0; i<n; ++i) {
      if(b&(1<<i)) {
	t.insert(i);
      } else {
	f.insert(i);
      }
    }
    bool flag=true;
    for(auto i: t) {
      for(auto x: m[i]) {
	if((x.second and t.find(x.first)==t.end()) or
	   (!x.second and f.find(x.first)==f.end())) {
	  flag=false;
	  break;
	}
      }
      if(!flag)
	break;
    }
    if(flag) {
      ans = max((int)ans, (int)t.size());
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,X;
void input(){
    fast_io();
    cin >> N >> X;
}

vector<ll> sizeBurger,patty;
ll dfs(ll L, ll x){
    if(x<=L) return 0;
    if(sizeBurger[L]==x) return patty[L];
    else if(sizeBurger[L]<x) return 0;
    if(x<=sizeBurger[L-1]+1) return dfs(L-1,x-1);
    else if(x==sizeBurger[L-1]+2) return 1+patty[L-1];
    else if(x<=2*sizeBurger[L-1]+2) return 1+patty[L-1]+dfs(L-1,x-2-sizeBurger[L-1]);
    else return 1+2*patty[L-1];
}

int solve(){
    sizeBurger.assign(N+1,0),patty.assign(N+1,0);
    sizeBurger[0] = 1;
    patty[0] = 1;
    for (int i = 0; i < N; i++)
    {
        sizeBurger[i+1] = 3+2*sizeBurger[i];
        patty[i+1] = 1+2*patty[i];
    }
    cout << dfs(N,X) << endl;

    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const long double eps=1e-7;
const ll mod=1e6+3;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	int t=0,m=n;
	while(n){
		t+=n%10;
		n/=10;
	}
	if(m%t==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt() + sc.nextInt() - sc.nextInt() - sc.nextInt();
      if(a == 0)
        System.out.println("Balanced");
      else if (a > 0)
       System.out.println("Left");
      else
        System.out.println("Right");
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
map<string,int> mapping;
string s;
int n;
int main(){
  cin>>n;
  while(n--){
     cin>>s;
     mapping[s]++;
  }
  cout<<"AC x "<<mapping["AC"]<<'\n';
  cout<<"WA x "<<mapping["WA"]<<'\n';
  cout<<"TLE x "<<mapping["TLE"]<<'\n';
  cout<<"RE x "<<mapping["RE"]<<'\n';
}


Measured memory_bytes: 3588
// myfirstatcoder.cpp : アプリケーションのエントリ ポイントを定義します。

#include "bits/stdc++.h"
#define rep(i,cc,n) for(int i=cc;i<(n);++i)
#define drep(i,cc,n) for(int i=cc;i>(n);--i)
#define llrep(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;
	switch (N % 10)
	{
	case 0:
		cout << "pon" << endl;		break;
	case 1:
		cout << "pon" << endl;		break;
	case 2:
		cout << "hon" << endl;		break;
	case 3:
		cout << "bon" << endl;		break;
	case 4:
		cout << "hon" << endl;		break;
	case 5:
		cout << "hon" << endl;		break;
	case 6:
		cout << "pon" << endl;		break;
	case 7:
		cout << "hon" << endl;		break;
	case 8:
		cout << "pon" << endl;
		break;
	case 9:
		cout << "hon" << endl;
		break;
	default:
		break;
	}
}

/*
ライブラリ
・string
::::str.at(0)
::::str.length()
::::str.pop_back();
・vector<int>
::::vector<int> a(n,-1);
::::vector<int> s;  s.push_back()
::::vector<vector<int>> A(N,vector<int>(M));  A[i][j] = i;
・map<string,int>
・sort(a.begin(),a.end());

関数
・rep_2(i,0,1<<n) … ２のN乗ループ
・while(node[v] == -1) … ノードの探索と生成
・gcd(int, int) … 最大公約数 int
・find_string(str, str) … 文字列検索 bool
*/

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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

		int i;
		String n;
		double avg,a,sum1,sum2;
		//double[] x = new double[1000 + 1];

		while(true){
			sum1=0;
			sum2=0;
			a=0;
			n=br.readLine();
			if(n.equals("0"))break;
			int num=Integer.parseInt(n);

			String c=br.readLine();
			String b[]=c.split(" ");
			double d=0,sum=0;
			double e[]=new double[num];

			for(i=0;i<num;i++){

				e[i] = Double.parseDouble( b[i] );

				sum1+=e[i];
			}
			avg=sum1/num;
			for(i=0;i<num;i++){

				sum2+= (Math.pow((e[i]-avg),2)/num);
			}
			a=Math.sqrt(sum2);
			System.out.printf(a + "\n" );
		}

	}
}

Measured memory_bytes: 26340
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll s,w;
     cin>>s>>w;
     if(w>=s)
     {
         cout<<"unsafe"<<endl;
     }
     else
     {
         cout<<"safe"<<endl;
     }
}


Measured memory_bytes: 3636
from numpy import*
from scipy.sparse import*
(n,m),*p=[map(int,o.split())for o in open(0)]
e=array([(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]]).T
print("YNEOS"[1in csgraph.connected_components(csr_matrix(((e[2],e[:2])),[n+m]*2))[1][:n]::2])

Measured memory_bytes: 61152
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	x = getlist()
	y = getlist()
	X = 0
	Y = 0
	for i in range(N - 1):
		X += ((x[i + 1] - x[i]) * (i + 1) * (N - i - 1)) % con
		X %= con
	for i in range(M - 1):
		Y += ((y[i + 1] - y[i]) * (i + 1) * (M - i - 1)) % con
		Y %= con
	print(X * Y % con)


if __name__ == '__main__':
	main()

Measured memory_bytes: 17376