akhauriyash/Code-Regression huggingface dataset:
open Printf open Scanf
open Array

let divisors n = (* O(sqrt n) *)
  let rec f0 i a =
    if i*i > n then a
    else if i*i = n && n mod i = 0 then i::a
    else if n mod i = 0 then f0 (i+1) (i::(n/i)::a)
    else f0 (i+1) a in f0 1 []

let factors n = (* O(sqrt n) *)
  let m = ref n in
  let tbl = Hashtbl.create ~random:true 30000 in
  for i=2 to 2 + (int_of_float @@ sqrt @@ float_of_int @@ n) do
    if !m mod i = 0 then (
      let k = ref 0 in
      while !m mod i = 0 do
        k := !k + 1; m := !m / i;
      done;
      Hashtbl.add tbl i !k;
    )
  done;
  if !m>1 then (Hashtbl.add tbl !m 1);
  let res = make (Hashtbl.length tbl) (0,0) in
  ignore @@ Hashtbl.fold (fun p k idx -> res.(idx) <- (p,k); idx+1) tbl 0;
  res

let () = scanf " %d" @@ fun n ->
  let a = divisors n in
  print_int @@
    List.fold_left (fun sum v ->
      let m = v - 1 in
      if m > 0 && n / m = n mod m then (
        sum + m
      ) else sum
    ) 0 a




Measured memory_bytes: 4480
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // get value from StandardIn
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    String ans = "";

    if(a<b){
      for(int i=0;i<b;i++){
        System.out.print(a);
      }
    }else{
      for(int i=0;i<a;i++){
        System.out.print(b);
      }
    }
    System.out.println("");
  }
}

Measured memory_bytes: 20692
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
#import bisect# lower_bound etc
#import numpy as np
def run():
    S,T = read().split()
    if len(S) == len(T) - 1 and S == T[:-1]:
        print('Yes')
    else:
        print('No')
if __name__ == "__main__":
    run()

Measured memory_bytes: 9108
/* In the name of God */

#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Dec cout<<fixed<< setprecision
#define endl "\n"
#define nlp printf("\n")
#define nl cout << "\n"
#define MP(make_pair)
#define SZ(x) (int) x.size()
#define tc() int t; cin >> t ; while (t--)
#define debug(x) cerr << "### " << #x << " is : " << x << " ###" << endl
#define clr(a) memset(a , 0 , sizeof a)
#define endl "\n"
#define bit(i , x) ((x >> i) & 1)
#define all(v) v.begin() , v.end()
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<int> VI ;
typedef vector<pii> VPI;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }
inline int in(){int32_t x ; scanf ("%d" , &x) ; return x ; }
inline ll lin(){ll x ; scanf ("%I64d" , &x) ; return x ; }
inline void out(int x){printf("%d " , x) ; }
inline void lout(ll x){printf("%I64d " , x) ; }

const int MOD = 1e9 + 7 ;
const ld EPS = 1e-9 ;
const int INF = 1e9 + 10 ;
const ll LINF = 1e18 ;
const int N = 1e3 + 10 ;
const int maxn = 1e4 + 10 ;
const int MAXN = 1e5 + 10 ;
const int MN = 1e6 + 10 ;
inline int powmod(int x , int y){ ll res = 1 , a = x ; while(y){if(y&1) res = (res*a)%MOD ;  a = (a*a)%MOD ; y >>= 1 ;} return res ; }

int n , a[2*MAXN] , sum , cursum , res = LINF ;

int32_t main (){
	IOS() ;
	cin >> n ;
	for(int i=0 ; i < n ; i++)
		cin >> a[i] , sum += a[i] ;
	for(int i=0 ; i < n-1 ; i++){
		cursum += a[i] ;
		smin(res , abs(cursum - (sum-cursum))) ;
	}
	cout << res ;
}


Measured memory_bytes: 1792
import math
x = int(input())
ans = 0
for b in range(1, int(math.sqrt(x))+1):
    p = 1
    if b != 1:
        while b**p <= x:
            p += 1
    if b**(p-1) > ans:
        ans = b**(p-1)
print(ans)

Measured memory_bytes: 3060
using System;
using System.Linq;

namespace A.Day_of_Takahashi
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = ab[0];
            int b = ab[1];

            Console.WriteLine(b >= a ? a : a - 1);
        }
    }
}


Measured memory_bytes: 11220
using System;
using System.Collections.Generic;
using System.Linq;

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

            Console.WriteLine((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    double x, y;
    cin >> x >> y;
    double m = (y - 2*x)/2.0;
    double l = x - m;
    int mm = m;
    int lll = l;
    // outline(lll);
    // outline(mm);
    int X = x, Y = y;
    if(lll >= 0 && mm >= 0 && lll + mm == X && 2*lll + 4*mm == Y)
    {
        outline("Yes");
        return 0;
    }
    outline("No")
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n+1],b[n];
    rep(i,n+1)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll cnt=0;
    if(a[0]<=b[0]){
        cnt=a[0];
        b[0]-=a[0];
    }
    else{
        cnt=b[0];
        b[0]=0;
    }
    for(int i=1;i<n+1;i++){
        if(a[i]<=b[i-1]){
            cnt+=a[i];
            a[i]=0;
        }
        else {
            cnt+=b[i-1];
            a[i]-=b[i-1];
        }
        if(a[i]<=b[i]){
            cnt+=a[i];
            b[i]-=a[i];
        }
        else {
            cnt+=b[i];
            b[i]=0;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
timeline=[[0,0,0]]

for i in range(n):
	temp=list(input().rstrip().split())
	temp2=[]
	for element in temp:
		temp2.append(int(element))
	timeline.append(temp2)


i=0
flag=True
output="Yes"

while i<n and flag:
	dif=[timeline[i+1][0]-timeline[i][0],timeline[i+1][1]-timeline[i][1],timeline[i+1][2]-timeline[i][2]]
	if dif[0]<abs(dif[1])+abs(dif[2]) or (dif[0]-abs(dif[1])-abs(dif[2]))%2 ==1 :
		flag=False
		output="No"
	i+=1

print(output)

Measured memory_bytes: 21156
//C - Multiple Gift
#include<iostream>

using namespace std;

typedef long long ll;

int main(){
    ll x,y,cnt=1;

    cin>>x>>y;
    while(1){
        x=x*2;
        if(x>y){ break; }
        cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
    ll h;
    cin >> h;
    ll ans=1;
    ll count=1;
    while(h>1){
        count*=2;
        ans+=count;
        h=h/2;
    }
    cout << ans << endl;
}

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

int main(void)
{
    int n;
    cin >> n;

    if (n < 10)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        for (int i = 2; i < 10; i++)
        {
            if (n % i == 0)
            { //warikireru
                if ((n / i) < 10)
                {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        s: String,
    }

    //tabで移動
    if s == "ABC" {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2112
from collections import Counter
N = str(input())
#各桁の和を計算するためリストに各桁を格納
str_integer = list(N)
#総和の初期値を0に設定
total_num = 0
for i in str_integer:
  total_num += int(i)

if int(N) % total_num == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

static class CodeJam
{
    static IEnumerable<long> Solve(int X, int Y, int Z, int K, long[] A, long[] B, long[] C)
    {
        Comparison<long> greater = (a, b) => b.CompareTo(a);
        Array.Sort(A, greater);
        Array.Sort(B, greater);
        Array.Sort(C, greater);

        var ans = new List<long>();
        for (int i = 0; i < X; ++i)
        {
            for (int j = 0; j < Y && i * j < K; ++j)
            {
                for (int k = 0; k < Z && i * j * k < K; ++k)
                {
                    ans.Add(A[i] + B[j] + C[k]);
                }
            }
        }
        ans.Sort(greater);
        return ans.Take(K);
    }

    static void Main(string[] args)
    {
        int[] V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        long[] A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long[] B = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long[] C = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var ans = Solve(V[0], V[1], V[2], V[3], A, B, C);
        foreach (long n in ans) { Console.WriteLine(n); }
    }
}


Measured memory_bytes: 50996
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = list(input())
L = len(S)
if L%2 == 1:
	if S[0] == S[-1]:
		print('Second')
	else:
		print('First')
else:
	if S[0] != S[-1]:
		print('Second')
	else:
		print('First')


Measured memory_bytes: 5228
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "OK":"NG"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K,A,B;
	string s;
	while(cin>>K>>A>>B) {
		ll ans=0;
		RANGE(i, A, B+1) if(i%K==0) ans=1;
		cout<<YN(ans)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3052
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/VPC/OUPC/2489

#include <bits/stdc++.h>

using namespace std;

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

    vector<int> vt;
    for (int i = 1; i <= 10001; ++i) {
        string s = to_string(i);
        string t = s;
        reverse(t.begin(), t.end());

        if (s == t) vt.emplace_back(i);
    }

    auto itr = lower_bound(vt.begin(), vt.end(), n);
    int ans1 = *itr;
    int ans2 = *(itr - 1);
    if (ans1 - n < n - ans2) {
        cout << ans1 << endl;
    } else {
        cout << ans2 << endl;
    }
    return 0;
}

/*
 * 100000に近い回文数として100001がある。
 *
 */


Measured memory_bytes: 3276
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int out = N / 1.08;
    int x;
    while(true){
        if ((int)(out * 1.08) < N){
            out++;
        }else if((int)(out * 1.08) == N){
            cout << out << endl;
            break;
        }else{
            cout << ":(" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {
    private static final BufferedReader READER = new BufferedReader(new InputStreamReader(System.in));

    private static int getInt() {
        try {
            return Integer.parseInt(READER.readLine());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static int[] getIntArr(int n) {
        int[] ans = new int[n];

        StringTokenizer stringTokenizer = null;
        try {
            stringTokenizer = new StringTokenizer(READER.readLine(), " ");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < n && stringTokenizer.hasMoreTokens(); i++) {
            ans[i] = Integer.parseInt(stringTokenizer.nextToken());
        }

        return ans;
    }

    private static int solve() {
        int n = getInt();
        int[][] matrix = new int[n][3];
        for (int i = 0; i < n; i++) {
            matrix[i] = getIntArr(3);
        }
        return solveInternal(n, matrix);
    }

    private static int solveInternal(int n, int[][] matrix) {
        int[][] dp = new int[n][3];
        dp[0] = matrix[0].clone();

        for (int i = 1; i < n; i++) {
            dp[i][0] = matrix[i][0] + Math.max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = matrix[i][1] + Math.max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = matrix[i][2] + Math.max(dp[i - 1][0], dp[i - 1][1]);
        }

        return IntStream.of(dp[n - 1]).max().getAsInt();
    }

    public static void main(String... args) {
        System.out.println(solve());
//        System.out.println(
//                solveInternal(7, new int[][]{{6, 7, 8},
//                        {8, 8, 3},
//                        {2, 5, 2},
//                        {7, 8, 6},
//                        {4, 6, 8},
//                        {2, 3, 4},
//                        {7, 5, 1}}));
    }
}

Measured memory_bytes: 50848
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    T = mod
    mod *= 2
    c = 0
    b = np.sort(B % mod)
    a = A % mod
    L1, R1, L2, R2 = (np.searchsorted(b, x - a).sum() for x in (T, 2*T, 3*T, 4*T))
    c += R1 - L1
    c += R2 - L2

    if c % 2:
        ans += T

print(ans)


Measured memory_bytes: 55324
#include<iostream>
#include<stdlib.h>
using namespace std;


bool linear_search(int *seq, int n, int key)
{
	seq[n] = key;
	int i = 0;
	while(seq[i] != key)
	{
		i++;
	}
	
	return i != n;
}



int main()
{
	int seq[10000+1];
	int n;
	cin >> n;
	int i = 0;
	for(i; i < n; i++)
	{
		cin >> seq[i];
	}
	
	int q;
	cin >> q;
	

	int num = 0;
	int key = 0;
	for(i = 0; i < q; i++)
	{
		cin >> key;
		if(linear_search(seq, n, key)) num += 1;
	}
	
	cout << num << endl;
//	system("pause");
	return 0;
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int f(int index, int num) {
    rep(i, index) {
        num /= 10;
    }
    return num % 10;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int ans = 0;
    REP(i, A, B) {
        if(f(0, i) == f(4, i) && f(1, i) == f(3, i)) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
 while(1){
 cin >> IN;
 if(IN == 0)break;
 IN = 1000 - IN;
 while(IN / 500){IN -= 500; answer++;}
 while(IN / 100){IN -= 100; answer++;}
 while(IN / 50){IN -= 50; answer++;}
 while(IN / 10){IN -= 10; answer++;}
 while(IN / 5){IN -= 5; answer++;}
 while(IN / 1){IN -= 1; answer++;}
 cout << answer <<endl;
 answer = 0;
 }
 return 0;
}



Measured memory_bytes: 3092
use std::io::*;
use std::str::FromStr;

fn main() {
    let x: i32 = read();
    let a: i32 =  read();
    
    let output: i32 = if x < a {
         0
    } else {
         10
    };

    println!("{}", output);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 A;
  long double B;
    cin >> A >> B;
  i64 b = B * 100.0 + 0.001;
  i64 ans = (A * b) / 100ll;
    cout << ans << endl;
}


Measured memory_bytes: 3720
import java.util.*;

class Main{
    public Main(){
        Scanner SC = new Scanner(System.in);

        String S = SC.next();

        if(S.equals("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }

    }

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


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

#include <iostream>
using namespace std;
// Nodeクラス
class Node{
public:
    Node* prev; // 前のノードへのポインタ
    Node* next; // 次のノードへのポインタ
    int data; // データ
    Node(){prev = 0; next = 0; data = 0;}
};
// Listクラス
class List{
public:
    Node head; // ヘッドノード（ダミー）
    Node* btn;
    List(){head.prev = &head; head.next = &head; head.data =-1;} int append(int nd); // 追加 
    int del(int a); // 削除
    bool search(int d); // 探索
};
// appendメソッド（追加）
int List::append(int nd){
    Node* p = new Node();
    if(p==0) 
        return -1; // メモリ確保エラー
    Node* q = head.prev;
    Node* r = &head;
    p->prev = q;
    p->next = r;
    p->data = nd;
    q->next = p;
    r->prev = p;
    return 0; // 正常終了
}
// delメソッド（削除）
int List::del(int a){
    if(a%2==0){ // 偶数 
        for(int i=0; i<a; i++){ 
            btn = btn->next;
            if(btn==&head){ 
                btn = btn->next; 
            } 
        }
    } else{ // 奇数 
        for(int i=0; i<a; i++){ 
            btn = btn->prev;
            if(btn==&head){    
                btn = btn->prev; 
            } 
        }
    }
    Node* p = btn;
    btn = btn->next;
    if(btn==&head){ 
        btn = btn->next;
    }
    Node* q = p->prev;
    Node* r = p->next;
    q->next = r;   
    r->prev = q;
    delete p;
    return 0; // 正常終了
}
// searchメソッド（探索）
bool List::search(int d){
    for(Node* p=head.next; p!=&head; p=p->next){ 
        if(p->data==d) 
        return true; // 見つかった
    }
    return false; // 見つからなかった
}
// main関数
int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    List L;
    for(int i=0; i<N; i++){ 
        L.append(i);
    }
    L.btn = L.head.next;
    for(int i=0; i<M; i++){    
        int a; 
        cin >> a;
        L.del(a);
    }
    for(int i=0; i<Q; i++){ 
        int q; 
        cin >> q;
        if(L.search(q)){ 
            cout << 1 << endl; 
        } 
        else{ 
            cout << 0 << endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}

int main(){
  int N;
  cin >> N;
  vi x(N);
  rep(i,N) cin>> x.at(i);
  ll ans = 1000000;
  for(int i = 1; i < 101; i++){
    ll sum = 0;
    rep(j,N){
      sum += pow((x.at(j)-i),2);
    }
    chmin(ans, sum);
  }

  cout << ans << endl;


}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
    int a,b,c,d,e;cin>>a>>b>>c>>d>>e;int max=50000;int A=0;
    if(max>a){max=a;}if(max>b){max=b;}if(max>c){max=c;}A=max;
    if(d>e){A+=e;}else{A+=d;}cout<<A-50<<endl;
    return 0;
}


Measured memory_bytes: 3084
#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(){
    ll n;
    cin >> n;
    vector <ll> a(n+1);
    rep(i,n+1){
        cin >> a[i];
    }

    vector <ll> ma(n+2);
    ma[0]=1;
    ll ans;
    ans=0;
    
    

    
    vector <ll> mi(n+1);
    mi[n]=a[n];
    rep(i,n){
        mi[n-i-1]=mi[n-i]+a[n-i-1];
    }

    //rep(i,n+1){
      //  cout << ma[i] << " " << mi[i] << endl;
    //}

    int k=0;
    ll ans2;
    ans2=0;
    rep(i,n+1){
        //cout << ma[i] << " " << mi[i] << endl;
        
        if(ma[i]>=mi[i] and k==0){
            k=1;
            //k2=i;
            
        }
        if((ma[i]-a[i])<=0 and i!=n and k==0){
            ans=-1;
            break;
        }

        if(i==n and k==0){
        if(ma[n]<a[n]){
        ans=-1;
         }
            }

        if(k==0){
        ma[i+1]=(ma[i]-a[i])*2;
        }
        //if(ma[i]>2*mi[i] and k2==i){
          //      ans2-=(ma[i]/2-mi[i]);
            //    k=2;
            //}
        if(k==0){
            ans2+=ma[i];
        }
        else{
            ans2+=mi[i];
        }
    }

    
    
    if(ans==0){
    cout << ans2 << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

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

int main()
{
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int start = max(A,C);
  int end = min(B,D);
  int ans = end - start;
  ans = max(0,ans);
  
  cout << ans << endl;
}

Measured memory_bytes: 3576
sx, sy, tx, ty = map(int,input().split())

ans = ""

#1周目
ans += (ty-sy)*"U" + (tx-sx)*"R" + (ty-sy)*"D" + (tx-sx)*"L"

#2周目
ans += "L" + (ty-sy+1)*"U" + (tx-sx+1)*"R" + "DR" + (ty-sy+1)*"D" + (tx-sx+1)*"L" + "U"

print(ans)



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


int main(){
    
    string str;
    
    while(1){
        int count = 0;
        
        cin >>str;
        if(str=="-"){
            break;
        }
        cin>>count;
        for(int i =0;i<count;i++){
            int num = 0;
            cin >> num;
            str+=str.substr(0,num);
            str=str.erase(0,num);
        }
        cout<<str<<endl;
        
    }
    
   
    
  return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>
int main(void){
  int j;
  int N;
  scanf("%d",&N);
  
  int a[N+1];
  
  for(j=0;j<N;j++){
    scanf("%d",&a[j]);
  }
  
  int ct=0;
  int A=a[0];
  
  for(j=0;j<N;j++){
    while(a[j]%2==0){
      ct++;
      a[j]=a[j]/2;
    }
    
    if(ct<A)A=ct;
    else{}
    
    ct=0;
  }
  
  printf("%d",A);
  
  return 0;
}
      
      
  

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string S;
    cin >> S;
    if(S=="SSS"){
        cout << 0 << endl;
    }else if(S=="SSR"||S=="SRS"||S=="RSS"||S=="RSR"){
        cout << 1 << endl;
    }else if(S=="RRR"){
        cout << 3 << endl;
    }else{
        cout << 2 << endl;
    }
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    if ( n >= 100)
    {
        n = n % 100;
    }
    if ( n >= 10)
    {
        n = n % 10;
    }
    if ( n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
    {
        cout <<"hon" << endl;
    }else if ( n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
        cout << "pon" << endl;
    }else if (n % 10 == 3){
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>

using namespace std;

int xPos[100];
int yPos[100];
int main() {
	int n, m, x, y;
	scanf("%d %d %d %d", &n, &m, &x, &y);
	for(int i = 0; i < n; i++) scanf("%d", &xPos[i]);
	for(int i = 0; i < m; i++) scanf("%d", &yPos[i]);

	sort(xPos, xPos + n);
	sort(yPos, yPos + m);

	int z = -1;
	for(int i = xPos[n - 1] + 1; i <= yPos[0]; i++) {
		if(x < i && i <= y) {
			z = i;
			break;
		}
	}

	printf(z == -1 ? "War" : "No War");
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  int nums[x];
  for(int i=0;i<x;i++){
    scanf("%d",&nums[i]);
  }
  int min=nums[0];
  int sum=0;
  for(int i=0;i<x;i++){
  	if(min>nums[i]){
    	min=nums[i];
    }
    sum+=nums[i];
  }
  int res=x+(y-sum)/min;
  printf("%d",res);
  
  
  
  
  
  
  
  
 return 0; 
}

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

int main() {
  int N; string S; cin >> N >> S;
  int x =0, maxX =0;
  for (int i =0; i<N; i++) {
    if (S[i] == 'I') x++;
    else x--;
    maxX = max(maxX,x);
  }
  cout << maxX << endl;
}

Measured memory_bytes: 3624
S = [n == "1" for n in input().strip()]
sum_odd = sum(S[::2])
sum_even = sum(S[1::2])

if sum_odd > sum_even:
  print((len(S[::2]) - sum_odd) + sum_even)
else:
  print((len(S[1::2]) - sum_even) + sum_odd)

Measured memory_bytes: 4252
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define pi pair<ll,ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " <<a << endl;
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("D:\\input.txt", "r", stdin);
	freopen("D:\\output.txt", "w", stdout);
#endif
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		string s;
		cin >> s;

		vi a(n, -1);
		// bool ans = false;
		rep(i, 0, 2)
		{
			rep(j, 0, 2)
			{
				ll z, y;
				s[0] == 'o' ? z = 0 : z = 1;
				a[0] = i, a[1] = j;
				a[n - 1] = (a[0] ^ a[1]) ^ z;
				// cout << a[n - 1];
				rep(k, 1, n - 2)
				{
					ll z;
					s[k] == 'o' ? z = 0 : z = 1;
					a[k + 1] = ((z ^ a[k]) ^ a[k - 1]);
					// cout << a[k + 1] << endl;
				}
				// ll z;
				s[n - 2] == 'o' ? z = 0 : z = 1;
				s[n - 1] == 'o' ? y = 0 : y = 1;
				if (a[n - 1] == a[n - 2]^z ^ a[n - 3] and a[0] == a[n - 2] ^ y ^ a[n - 1]) {
					rep(l, 0, n)
					a[l] == 0 ? cout << 'S' : cout << 'W';
					return 0;
				}
			}
		}
		cout << -1;
	}
	return 0;
}

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

void push(int st[], int& top, int x) {
    // topを加算してからその位置へ挿入
    top++;
    st[top] = x;
}

int pop(int st[], int& top) {
    // topを減算してからtopが指していた要素を返す
    top--;
    return st[top + 1];
}

int main() {
    int a, b, top = 0, st[1000];
    string str;

    while (cin >> str) {
        if (str == "+") {
            a = pop(st, top);
            b = pop(st, top);
            push(st, top, a + b);
        } else if (str == "-") {
            b = pop(st, top);
            a = pop(st, top);
            push(st, top, a - b);
        } else if (str == "*") {
            a = pop(st, top);
            b = pop(st, top);
            push(st, top, a * b);
        } else {
            push(st, top, stoi(str));
        }

        if (getchar() == '\n') {
            cout << pop(st, top) << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

int a,b;

int main(){
	scanf("%d%d", &a, &b);
	if(a <= 0 && 0 <= b)
	return 0 * printf("Zero\n");
	int neg = 0;
	if(b <= 0)
	neg = b - a + 1;
	if(neg % 2 == 0)
	printf("Positive\n");
	else
	printf("Negative\n");
}


Measured memory_bytes: 256
a, b, c = list(map(int, input().split()))
if a == b:
  if a!=c and b!=c:
    print('Yes')
  else:
    print('No')
elif a == c:
  if a!=b and b!=c:
    print('Yes')
  else:
    print('No')
elif b == c:
  if a!=b and a!=c:
    print('Yes')
  else:
    print('No')
else:
  print('No')


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

const int MAX = 200000;
int main() {
	int H, W, N, diff = 0;
	static pair<int, int> point[MAX];
	cin >> H >> W >> N;
	for (int i = 0;i < N;++ i) cin >> point[i].first >> point[i].second;
	sort(point, point+N); // X昇順、同値ならY昇順
	for (int i = 0;i < N;++ i) {
		if (point[i].first - point[i].second - diff > 0) H = min(H, point[i].first - 1); // この障害物を使って邪魔する
		else if (point[i].first - point[i].second - diff == 0) ++ diff; // 青木君が移動できないので、上を抜けるしかない
	}
	cout << H;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、高橋君は常に行動をしなくてはならない(高橋君が行動しなければ青木君が行動しないで終了するので)
よって、高橋君は常時動くものとして考える
後は、青木君は高橋君が動いた時に邪魔できる最適な位置に移動したいだけ
よって、x>yとなる障害物のうち最も近いもののところまで移動させて後は無行動でおｋ
ただ、注意として青木君が移動させられない場合があるので、その時は流石に……ねぇ？
*/

Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
ab = list(map(int,read().split()))

links = [[] for _ in range(n)]
it = iter(ab)
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

root = 0
parent = [-2] * n
parent[root] = -1
ts = [root]
stack = [root]
while(stack):
    next = []
    while(stack):
        i = stack.pop()
        for j in links[i]:
            if(parent[j] != -2):
                continue
            ts.append(j)
            next.append(j)
            parent[j] = i
    stack = next[::]

root = ts[-1]
parent = [-2] * n
parent[root] = -1
ts = [root]
stack = [root]
while(stack):
    next = []
    while(stack):
        i = stack.pop()
        for j in links[i]:
            if(parent[j] != -2):
                continue
            ts.append(j)
            next.append(j)
            parent[j] = i
    stack = next[::]

ts = ts[::-1]
nums = [0] * n
for i in ts:
    cnt_0 = 0
    for j in links[i]:
        if(j == parent[i]):
            continue
        if(nums[j] == 0):
            cnt_0 += 1
        else:
            nums[i] += nums[j]
    nums[i] += max(0,cnt_0-1)

ans = nums[root]
if(len(links[root])==1):
    ans += 1

print(ans)

Measured memory_bytes: 125592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
int main(){
  ll N; cin>>N;
  vpii A(N); REP(i,N) cin>>A[i].first>>A[i].second;
  {
    auto comp=[](pii a,pii b){
      // if(a.first==b.first) return a.second<b.second;
      // return a.first>b.first;
      if(a.first+a.second==b.first+b.second) return a.first>b.first;
      return a.first+a.second>b.first+b.second;
    };
    sort(ALL(A),comp);
  }
  vvi dp(N,vi(N+1,-INF));
  REP(i,N) dp[i][0]=INF;
  dp[0][1]=A[0].first;
  FOR(i,1,N) for(ll j=i+1;j>0;j--) {
    dp[i][j]=max(dp[i-1][j],min(dp[i-1][j-1]-A[i].second,A[i].first));
  }
  ll ans=0;
  REP(i,N+1) {
    if(dp[N-1][i]>=0) ans=i;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 195840
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a < b&&b < c)
		puts("Yes");
	else
		puts("No");

	return 0;
}
	


Measured memory_bytes: 2624
n = gets.chomp.to_i
s_arr = n.times.map{gets.chomp.split("").sort.join("")}

hash = {}
s_arr.each do |s|
  hash[s] ||= 0
  hash[s] += 1
end

count = 0
hash.each do |s, c|
  next if c <= 1
  count += ((c * (c-1)) / 2)
end

puts count


Measured memory_bytes: 32636
import os,sys
from io import BytesIO, IOBase

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

def gcd(x,y):
    while(y):
        x,y=y,x%y
    return x
    

mod=(10**9)+7

import math 
        
for i in range(1):
    h=ii()
    a=math.log(h,2)
    a=int(a)
    a+=1
    ans=pow(2,a)
    ans-=1 
    print(ans)

Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>

#define put(x, y, z) (abacus[(x)][(y)] = z)

char abacus[8][6];

int main(){
  int n, i, j, a, f = 0;
  while(scanf("%d", &n) != EOF){
    for(i = 0;i < 8;i++) for(j = 0;j < 5;j++) put(i, j, '*');
    for(i = 0;i < 5;i++) put(2, i, '=');
    for(i = 0;i < 5; i++){
      a = n % 10;
      n /= 10;
      if(a < 5) put(1, 4 - i, ' ');
      else if(a >= 5){
	put(0, 4 - i, ' ');
	a -= 5;
      }

      put(3 + a, 4 - i, ' ');
    }
    if(f) puts("");
    for(i = 0; i < 8;i++) puts(abacus[i]);
    f = 1;
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;
    int N = S.length();
    int ans = N;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) chmin(ans, max(i + 1, N - i - 1));
    }

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

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
    char ch;

    FOR(i,0,3){
        cin >> ch;
        if(ch == '1')cout << '9';
        else cout << '1';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  int N;
  vector<int> A;
  cin >> N;
  A.resize(N);
  for(int i=0;i<N;i++) {
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  int ansA=0,ansB=0;
  for(int i= N-1;i>=0;i-=2) {
    ansA += A[i];
  }
  for(int i= N-2;i>=0;i-=2) {
    ansB += A[i];
  }
  cout << abs(ansA-ansB) << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        aa: [usize; n+1],
    }

    let mut vertices = vec![];
    let mut sum_a = aa.iter().sum::<usize>();
    vertices.push(1);

    for a in aa {
        sum_a -= a;
        let last = *vertices.last().unwrap();
        if last < a {
            println!("-1");
            return;
        }
        let val = std::cmp::min((last-a) * 2, sum_a);
        vertices.push(val);

    }

    let ans = vertices.iter().sum::<usize>();
    println!("{}", ans);
}


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

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> as(n), rs(n), ls(n);
	for (int i = 0; i < n; i++)
	{
		cin >> as[i];
	}
	ls[0] = as[0];
	for (int i = 1; i < n; i++)
	{
		ls[i] = __gcd(ls[i-1], as[i]);
	}
	rs[n-1] = as[n-1];
	for (int i = n-2; i >= 0; i--)
	{
		rs[i] = __gcd(rs[i+1], as[i]);
	}
	int ans = max(ls[n-2], rs[1]);
	for (int i = 0; i < n-2; i++)
	{
		ans = max(ans, __gcd(ls[i], rs[i+2]));
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1408
//============================================================================
// Name        : ProjG.cpp
// Author      : Yong Kiat
// Version     :
// Copyright   : By Algotae.
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>

using namespace std;

int n, x, k, dp[100001];
vector<int> a;

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

    cin >> n >> k;
    for (int i = 0; i < n && cin >> x; i++) {
        a.push_back(x);
    }

    fill(dp, dp + n, 1e9);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; i - j >= 0 && j <= k; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));
        }
    }

    cout << dp[n - 1];

    return 0;
}


Measured memory_bytes: 1144
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;
const int INF=1e9;

int N;
vector<int> nb[MAX];
int fe[MAX];
int sn[MAX];


int main(){
	cin>>N;
	rep(i,N){
		int a,b;
		cin>>a>>b;
		nb[a].push_back(b);
		nb[b].push_back(a);
	}
	
	
	//bfsでfeの最小手数をカウント
	rep1(i,N)fe[i]=INF;
	queue<int> q1;
	q1.push(1);
	fe[1]=0;
	while(!q1.empty()){
		int v=q1.front();
		q1.pop();
		int l=nb[v].size();
		rep(j,l){
			int w=nb[v][j];
			if(fe[w]==INF){
				fe[w]=fe[v]+1;
				q1.push(w);
			}
		}
	}
	//bfsでsnの最小手数をカウント
	rep1(i,N)sn[i]=INF;
	queue<int> q2;
	q2.push(N);
	sn[N]=0;
		while(!q2.empty()){
		int v=q2.front();
		q2.pop();
		int l=nb[v].size();
		rep(j,l){
			int w=nb[v][j];
			if(sn[w]==INF){
				sn[w]=sn[v]+1;
				q2.push(w);
			}
		}
	}
//	rep1(i,N)cout<<fe[i]<<" ";
//  	cout<<endl;
//	rep1(i,N)cout<<sn[i]<<" ";
//  	cout<<endl;
  
	int wfe=0,wsn=0;
	rep1(i,N){
		if(fe[i]<=sn[i])wfe++;
		else wsn++;
	}
	if(wfe>wsn)cout<<"Fennec";
	else cout<<"Snuke";
}

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

typedef long long int ll;

int main()
{
	ios::sync_with_stdio(0);
	string s,t;
	cin >> s >> t;
	ll n = s.size(),i,j;
	ll m = t.size();
	ll dp[n+1][m+1];
	for(i=0;i<=m;i++)
	dp[0][i]=0;
	for(i=0;i<=n;i++)
	dp[i][0]=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}	
	string ans="";
	i=n;
	j=m;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;
			j--;
		}
		else
		{
			if(dp[i][j]==dp[i-1][j])
				i--;
			else
				j--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 70656
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>

using namespace std;
int main(void)
{
	int cnt = 0;
	string moji;
	cin>>moji;
	int kaisu;
	int mojisu = moji.size();
	string ring;
	scanf("%d",&kaisu);
	for(int i = 0;i <kaisu;i++)
	{
		cin>>ring;
		int rings = ring.size();
		ring += ring;

		for(int j = 0;j < rings;j++)
		{
			string check = ring.substr(j,mojisu);
			if(check == moji)
			{
				cnt += 1;
				break;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+10,M=1e6;
const ll mod=998244353;
ll quick_mul(ll a,ll k)
{
	ll ans=1;
	while(k)
	{
		if(k&1)ans=ans*a%mod;
		a=a*a%mod;
		k>>=1;
	}return ans;
}
ll inv(ll a){return quick_mul(a,mod-2);}
int n;
int a[N],t[N];
ll f1[N],f2[N];
int miu[N];
int z[N],p;
bool vis[N];
void Sieve()
{
	miu[1]=1;
	for(int i=2;i<=M;i++)
	{
		if(!vis[i])z[++p]=i,miu[i]=-1;
		for(int j=1;j<=p&&i*z[j]<=M;j++)
		{
			vis[i*z[j]]=1;
			if(i%z[j]==0)break;
			miu[i*z[j]]=-miu[i];
		}
	}
	for(int i=1;i<=M;i++)
	{
		ll invd=inv(1ll*i);
		for(int j=i;j<=M;j+=i)
		{
			f1[i]=(f1[i]+t[j])%mod;
			f2[j]=(f2[j]+miu[j/i]*invd%mod+mod)%mod;
		}		
	}
}
int main()
{
	int maxx=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		t[a[i]]=(t[a[i]]+a[i])%mod;
		maxx=max(maxx,a[i]);
	}
	Sieve();
	ll ans=0;
	for(int i=1;i<=maxx;i++)
	ans=(ans+f1[i]*f1[i]%mod*f2[i]%mod)%mod;
	ans=((ans-f1[1])%mod+mod)%mod;
	printf("%lld",ans*inv(2ll)%mod);
}

Measured memory_bytes: 28160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;


int main(){

    ll n,b=1e18;
    cin>>n;
    ll a[n+5];
    bool flag=false;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==0){
            flag=true;
        }
    }
    if(flag){
        cout<<0<<endl;
        return 0;
    }

    ll m=1;
    for(int i=0; i<n; i++){
        if(m>(b/a[i])){
            flag=true;
            break;
        }
        else
            m*=a[i];
    }
    if(flag)
        cout<<-1<<endl;
    else
        cout<<m<<endl;


}


Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(){

	//ply.erase(find(ply.begin(),ply.end(),3));
	int m,n;
	while(cin>>n>>m&&!(n==0&&m==0)){
		vector<int> ply;
		for(int i = 0; i < n; i++)
			ply.push_back(i);
		int tern=0;
		bool f=false;
		for(int i = 1; i <= m; i++){
			string str;
			cin>>str;
			if(ply.size()==1)
				continue;
			if(i%3==0&i%5==0){
				if(str=="FizzBuzz"){
					tern++;
					tern%=ply.size();
				}
				else{
					ply.erase(find(ply.begin(),ply.end(),ply[tern]));
					if(tern==ply.size()){
						tern=0;
					}
				}
			}
			else if(i%3==0){
				if(str=="Fizz"){
					tern++;
					tern%=ply.size();
				}
				else{
					ply.erase(find(ply.begin(),ply.end(),ply[tern]));
					if(tern==ply.size()){
						tern=0;
					}
				}
			}
			else if(i%5==0){
				if(str=="Buzz"){
					tern++;
					tern%=ply.size();
				}
				else{
					ply.erase(find(ply.begin(),ply.end(),ply[tern]));
					if(tern==ply.size()){
						tern=0;
					}
				}
			}
			else{
				int num=atoi(str.c_str());
				if(num==i){
					tern++;
					tern%=ply.size();
				}
				else{
					ply.erase(find(ply.begin(),ply.end(),ply[tern]));
					if(tern==ply.size()){
						tern=0;
					}
				}
			}
		}

		for(int i = 0; i < ply.size(); i++){
			cout<<ply[i]+1;
			if(i!=ply.size()-1)
				cout<<" ";
			else
				cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 948
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll MAXN = 1e5+2;
vector<bool> used(MAXN,false);

int main(){
    int n; cin >> n;
    int cur = 0;
    int MAX = 0;
    int prev = 0;
    for(int i = 1; i <= n; i++){
        int x; cin >> x;
        if(prev >= x)
        cur++;
        else{
            MAX = max(MAX,cur);
            cur = 0;
        }
        prev = x;
    }
    cout << max(cur,MAX) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int d;
int main(){
  cin >> d;
  if(d==25) cout << "Christmas" << endl;
  else if(d==24) cout << "Christmas Eve" << endl;
  else if(d==23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
  return 0;
  }

Measured memory_bytes: 256