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

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

//primitive data types
typedef long long ll;

//pair
typedef pair<ll,ll> pll;
typedef pair<string,ll> psl;
#define mp(x,y) make_pair(x,y)
#define f first
#define s second

//vector
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
#define pb(x) push_back(x)

//control statements
#define fori(i,start,end) for(ll i = start ; i <= end ; i++)
#define ford(i,start,end) for(ll i = start ; i >= end ; i--)

const ll INF = 1e18L;

void solve(){
  ll N,W;
  cin>>N>>W;
  vpll items(N, {0,0});
  ll max_val = 0;
  for(auto &item : items){
    cin>>item.f>>item.s;
    max_val += item.s;
  }
  vll dp(max_val + 1, INF);
  dp[0] = 0;
  fori(item, 0, N-1){
    ford(v, max_val, items[item].s){
        dp[v] = min(dp[v], dp[v - items[item].s] + items[item].f);
    }
  }
  ford(i, max_val, 0){
    if(dp[i] <= W){
      cout<<i;
      return;
    }
  }
}

int main(){
  fastIO();
  ll t = 1;
  //cin>>t;
  while(t--){
    solve();
    cout<<"\n";
  }
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        String s = nextString(sc);
        int festIndex = s.lastIndexOf("FESTIVAL");

        out(s.substring(0, festIndex));
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    string s;
    cin >> s;
    if ('a' <= s[0] && s[0] <= 'z') {
        cout << 'a' << endl;
        return;
    }

    if ('A' <= s[0] && s[0] <= 'Z') {
        cout << 'A' << endl;
        return;
    }
}

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

Measured memory_bytes: 3620
package main

import (
	"fmt"
)

func main() {

	// 読み込み数取得
	var n int
	var s string
	fmt.Scan(&n, &s)

	count := 0

	for i := 0; i < (n - 2); i++ {
		if s[i:(i+3)] == "ABC" {
			count++
		}
	}
	fmt.Printf("%d\n", count)

}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int n;  scanf("%d", &n);
  int a[200001];
  long long int count[200001] = {0};
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    count[a[i]]++;
  }
  long long int sum = 0;
  for(int i=1; i<=n; i++){
    if(count[i] < 2)  continue;
    sum = sum + count[i] * (count[i] - 1) / 2;
  }

  for(int i=0; i<n; i++){
    printf("%lld\n", sum - count[a[i]] + 1);
  }
  return 0;
}


Measured memory_bytes: 4864
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for i in range(q)]

from itertools import combinations_with_replacement as comb_rplc
cmb = comb_rplc(range(1,m+1),n)
result = 0
for A in cmb:
  tmp = 0
  for a,b,c,d in abcd:
    if A[b-1] - A[a-1] == c:
      tmp += d
  result = max(tmp, result)
print(result)

Measured memory_bytes: 9144
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N, M int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &M)

	xs := make([]int, M)
	for i := 0; i < M; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &xs[i])
	}

	sort.Sort(sort.IntSlice(xs))
	ds := make([]int, M-1)
	for i := 0; i < M-1; i++ {
		ds[i] = xs[i+1] - xs[i]
	}
	sort.Sort(sort.IntSlice(ds))

	ans := 0
	for i := 0; i < M-1-(N-1); i++ {
		ans = ans + ds[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 173, task a, 2020/08/12
//ms,
/*
*/

int main(void){
  int64_t N;
  cin >>N;
  int64_t ans = N;

  for(int64_t i=1;i*i<=N;i++){
    if(N%i != 0) continue;
    int64_t j= N/i;
    ans = min(ans, i+j-2);
  }
  cout <<ans;

  return 0;
}
/*
*/


Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

class Util{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int N = ri();
		int[] AArray = ria();

		BigInteger ans = 0;
		for (int i = 1; i < N; i++)
		{
			if(AArray[i] < AArray[i - 1]) {
				ans += AArray[i - 1] - AArray[i];
				AArray[i] = AArray[i - 1];
			}
		}

		Console.WriteLine(ans);
		Console.ReadLine();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
    static int[] generateNums(int num, int N){return Enumerable.Repeat(num, N).ToArray();}
    static int[] generateSuretsu(int N){return Enumerable.Range(0, N).ToArray();}
}

public static class Combination {
	//使い方:int[][] Is = Combination.Enumerate(nums, k, withRepetition:false).ToArray();
    public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) {
        if (k == 1) {
            foreach (var item in items)
                yield return new T[] { item };
            yield break;
        }
        foreach (var item in items) {
            var leftside = new T[] { item };

            // item よりも前のものを除く （順列と組み合わせの違い)
            // 重複を許さないので、unusedから item そのものも取り除く
            var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

            foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
                yield return leftside.Concat(rightside).ToArray();
            }
        }
    }
}


Measured memory_bytes: 55664
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int sum[11][1001];
int n,k,m;
int query(int x1,int y1,int x2,int y2){
	return sum[x2][y2]+sum[x1-1][y1-1]-sum[x2][y1-1]-sum[x1-1][y2];
}
bool sat[11];
int res=INF;
void calc(){
	vector<mp> bo;
	int ll=1;
	int tmp=0;
	rb(i,1,m){
		int las=1;
		rb(j,1,n){
			
			if(j!=1&&sat[j]){
				if(query(las,i,j-1,i)>k) return;
				las=j;
			}
		}
		if(query(las,i,n,i)>k) return;
		
	}
	rb(i,1,n){
		tmp+=sat[i];
	}
//	cout<<"!"<<endl;
	rb(i,1,m){
		int las=1;
		int ok=1;
		rb(j,1,n){
			if(j!=1&&sat[j]){
				if(query(las,ll,j-1,i)>k) ok=0;
				las=j;
			}
		}
		if(query(las,ll,n,i)>k) ok=0;
		if(ok==0){
			ll=i;
			tmp++;
		}
	}
//	cout<<tmp
	res=min(res,tmp);
}
void dfs(int now)
{
	if(now>n){
		calc();
		return;
	}
	sat[now]=1;
	dfs(now+1);
	sat[now]=0;
	dfs(now+1);
}
int main(){
	fastio;
		cin>>n>>m>>k;
		char c[11][1001];
		rb(i,1,n)
			rb(j,1,m)
				cin>>c[i][j],sum[i][j]=-sum[i-1][j-1]+c[i][j]-'0'+sum[i-1][j]+sum[i][j-1];
	dfs(1);	
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
import sys
l, r = map(int, input().split())
x = []

# 出力
mod = 2019
if r-l>=673:
    print(0)
    sys.exit()

for i in range(l,r+1):
    for j in range(i+1,r+1):
        # print(i,j,(i*j)%2019)
        if mod > (i*j)%2019:
            mod = (i*j)%2019
print(mod)


Measured memory_bytes: 3060
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
const int INF = 1e9;
const int MOD = 1e9+7;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vb prime(55556, true); prime[0] = prime[1] = false;
    for(int i = 2; i*i <= 55555; i++)
    {
        if(prime[i])
        {
            for(int j = i*2; j <= 55555; j += i) prime[j] = false;
        }
    }
    vi ans;
    for(int i = 2; i <= 55555; i++)
    {
        if(prime[i] && i % 10 == 1) ans.push_back(i);
    }
    REP(i, N) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 256
#!/usr/bin/perl

$line = 0;
while (<>) {
    if ($line == 0) {
        ($n) = split /\s+/, $_;
    } else {
        @a = split /\s+/, $_;
    }
    $line++;
}

foreach (@a) {
    $total += $_;
}

$f = $a[0];
$b = $total - $a[0];
$sub = abs($b - $f);
$min = $sub;
foreach $i (1 .. $n - 2) {
    $f += $a[$i];
    $b -= $a[$i];
    $sub = abs($b - $f);
    if ($sub < $min) {
        $min = $sub;
    }
}

print "$min\n";


Measured memory_bytes: 33228
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { n, k };
    if 2 * k <= n + 1 {
        let mut v = vec![];
        let m = if n % 2 == 1 { n } else { n - 1 };
        if n % 2 == 0 {
            let a = k;
            let b = k + 2 * n - 1;
            v.push((a + b, a, b));
        }
        let mut j = 0;
        for i in 0..m {
            let a = k + n - 1 - i;
            let b = k + n + j;
            v.push((a + b, a, b));
            j = (j + 2) % m;
        }
        v.sort();
        for i in 0..n {
            println!("{} {} {}", v[i].1, v[i].2, k + n * 2 + i);
        }
    } else {
        println!("{}", -1);
    }
}


Measured memory_bytes: 11640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
int main() {
	ll a, b,ans=0;
	cin >> a >> b;
	for (int i = 1; i <= b - a; ++i)ans += i;
	cout << (ans - b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
class graph
{
	public:
		vector<int> v[1010];
		int match[1010];
		bool vis[1010];
		bool dfs(int np)
		{
			for(auto &x:v[np])
			{
				if(!vis[x])
				{
					vis[x]=1;
					if(!match[x]||dfs(match[x]))
					{
						match[x]=np;
						return 1;
					}
				}
			}
			return 0;
		}
}G;
vector<int> prime;
bool flag[10000010];
void init()
{
	flag[1]=1;
	for(int i=2;i<=10000000;i++)
	{
		if(!flag[i])prime.push_back(i);
		for(int j=0;j<prime.size()&&i*prime[j]<=10000000;j++)
		{
			flag[i*prime[j]]=1;
			if(i%prime[j]==0)break;
		}
	}
}
vector<int> v1,v2;
int col[10000010],m2[1010];
int main()
{
//	freopen("c.in","r",stdin);
	init();
	scanf("%d",&n);
	v1.push_back(0);v2.push_back(0);
	for(int i=1,ti;i<=n;i++)
	{
		scanf("%d",&ti);
		col[ti]=1;
	}
	for(int i=1;i<=10000001;i++)
	{
		if(col[i]!=col[i-1])
		{
			if(i&1)v1.push_back(i);
			else v2.push_back(i);
		}
	}
	for(int i=1;i<v1.size();i++)
	{
		for(int j=1;j<v2.size();j++)
		{
			if(!flag[abs(v2[j]-v1[i])])G.v[i].push_back(j);
		}
	}
	for(int i=1;i<v1.size();i++)
	{
		memset(G.vis,0,sizeof(G.vis));
		G.dfs(i);
	}
	int cnt1=0,cnt2=0,ans=0;
	for(int i=1;i<v2.size();i++)
	{
		if(G.match[i])m2[G.match[i]]=i,ans++;
		else cnt2++;
	}
	for(int i=1;i<v1.size();i++)
	{
		if(!m2[i])cnt1++;
	}
	ans+=(cnt1/2)*2;ans+=(cnt2/2)*2;
	cnt1%=2;cnt2%=2;
	if(cnt1&&cnt2)ans+=3;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 51308
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node(i);

    int M = scanner.nextInt();
    for (int i = 0; i < M; i++) {
      int u = scanner.nextInt() - 1;
      int v = scanner.nextInt() - 1;
      nodes[u].adjacents.add(nodes[v]);
    }
    int S = scanner.nextInt() - 1;
    int T = scanner.nextInt() - 1;

    int shortest = bfs(N, nodes, S, T);
    System.out.println(shortest >= 0 ? shortest / 3 : -1);
  }

  private static int bfs(int N, Node[] nodes, int s, int t) {
    int[][] dist = new int[N][3];
    boolean[][] visited = new boolean[N][3];
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) dist[i][j] = -1;
    Queue<Pair<Node, Integer>> queue = new LinkedList<>();
    queue.add(new Pair<>(nodes[s], 0));
    dist[s][0] = 0;
    visited[s][0] = true;
    while (!queue.isEmpty()) {
      Pair<Node, Integer> p = queue.poll();
      Node n = p.first;
      int r = p.second;
      int rn = (r + 1) % 3;
      for (Node a : n.adjacents) {
        if (!visited[a.id][rn]) {
          dist[a.id][rn] = dist[n.id][r] + 1;
          visited[a.id][rn] = true;
          queue.add(new Pair<>(a, rn));
        }
      }
    }
    return dist[t][0];
  }

  private static class Node {
    private final int id;
    List<Node> adjacents = new ArrayList<>();
    Node(int id) {
      this.id = id;
    }
  }
  
  private static class Pair<F, S> {
    private final F first;
    private final S second;
    
    public Pair(F f, S s) {
      this.first = f;
      this.second = s;
    }
  }
}


Measured memory_bytes: 105384
#include<stdio.h>
//#include <queue>
//#include <cstdio>
//using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	int map[n];
	for(int i=0;i<n;i++){
		int ai;
		scanf("%d", &ai);
		map[i]=ai;
	}
	int max=0, min=0, maxi=0, mini=0;
	for(int i=0;i<n;i++){
		if(max<map[i]){
			max=map[i];
			maxi=i;
		}
		if(min>map[i]){
			min=map[i];
			mini=i;
		}
	}
	bool c;
	if(max+min>0){
		c=true;
	}else{
		c=false;
	}
	printf("%d\n", 2*n-1);
	if(c){
		for(int i=0;i<n;i++){
			printf("%d %d\n", maxi+1, i+1);
		}
		for(int i=0;i<n-1;i++){
			printf("%d %d\n", i+1, i+2);
		}
	}else{
		for(int i=0;i<n;i++){
			printf("%d %d\n", mini+1, i+1);
		}
		for(int i=0;i<n-1;i++){
			printf("%d %d\n", n-i, n-i-1);
		}
	}
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 

using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define vi vector<int> 
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}

const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;

void solve() {
 	int n; cin >> n;
 	vi a(n + 2), pg(n + 2), sg(n + 2);
	for (int i = 1; i <= n; ++i) 
		cin >> a[i];

 	for (int i = 1; i <= n; ++i) {
 	 	pg[i] = __gcd(pg[i - 1], a[i]);
 	 	sg[n - i + 1] = __gcd(sg[n - i + 2], a[n - i + 1]);
 	}

 	int ans = 0;
 	for (int i = 1; i <= n; ++i) {
 	 	int cur = __gcd(pg[i - 1], sg[i + 1]);
 	 	ans = max(cur, ans);
 	}

 	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
//




//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vector<int> vec(n) ;
  REP(i,n){
    cin >> vec.at(i) ;
  }
  bool f = true ;
  REP(i,n){
    if(vec.at(i)==1){
      f = false ;
    }
  }
  if(f){
    cout << -1 <<endl ;
    return 0 ;
  }
    
  int cnt = 1 ;
  REP(i,n){
    if(vec.at(i)==cnt){
      cnt++ ;
    }
  }
  
  cout << n-(cnt-1) <<endl ;
    
  
  
  
  return 0 ;
}



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

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int ans = 0;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int total = i*500 + j*100 + k*50;
                if (total == x) ++ans;
            }
        }
    } 

    cout << ans << endl;
}

Measured memory_bytes: 3148
#include<iostream>
using namespace std;
int main()
{
	int x,a,b,c;
	cin >> x;
	a = x / 3600;
	x = x % 3600;
	b = x / 60;
	x = x % 60;
	c = x;
	cout << a <<":"<<b<<":"<<c<< endl;
	return 0;
}

Measured memory_bytes: 1168
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val inputs = readLine()!!.split(" ").map { it.toInt() }

    var cnt = 0
    for (v in inputs) {
        var tmp = v

        while (tmp % 2 == 0) {
            tmp /= 2
            cnt += 1
        }
    }

    println(cnt)
}

Measured memory_bytes: 42168
#include <iostream>
using namespace std;
int main(void){
    int S,h,m,s;
    std::cin >> S;
    h=S/3600;
    S%=3600;
    m=S/60;
    S%=60;
    s=S;
    std::cout << h<<":"<<m<<":"<<s<< std::endl;
}



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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// ??????10??????
		 int debt = 100000;

		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		// n??±??????
		int n = Integer.parseInt(br.readLine());

		// n??±????????????????????§??°?????????
		for (int i = 0; i < n; i++ ){
			// ??????5
			debt *= 1.05;

			// 1000?????????????????????
			if (debt % 1000 > 0) {
				debt = debt - (debt % 1000) + 1000;
			}
		}

		System.out.println(debt);
	}
}

Measured memory_bytes: 24212
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n,w;
        cin>>n>>w;
        ll dp[100005];
        REP(i,0,100005) dp[i]=1e18;
        dp[0]=0;
        REP(i,0,n)
        {
            ll t1,t2;
            cin>>t1>>t2;
            REPI(j,0,100005)
            {
                if(j+t2<100005)
                {
                    dp[j+t2]=min(dp[j+t2],dp[j]+t1);
                }
            }
        }
        ll ans=0;
        REPI(i,0,100005) 
        {
            if(dp[i]<=w)
            {
                ans=i;
                break;
            }
        }
        cout<<ans;
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int N, X;
    int l[101];
    int i;

    scanf("%d", &N);
    scanf("%d", &X);

    for(i=1; i<=N; i++){
        scanf("%d", &l[i]);
    }
    int D, B=0;
    for(i=2; i<=N+1; i++){
        D = D + l[i-1];
        if(D <= X){
            B++;
        }
    }
    B++;
    printf("%d", B);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int sum1,n,x;
void search(int sum,int count,int num){
    if(sum == x && count == 3)
        sum1++;
    if(sum >= x || count >= 3 || num >=n+1)
        return;
    search(sum+num,count+1,num+1);
    search(sum,count,num+1);
}
int main(void){
    for(;sum1=0,scanf("%d %d",&n,&x),n+x!=0;printf("%d\n",sum1))
        search(0,0,1);
    return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,m;
	ll a[114514]={};
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll l,r;
		cin>>l>>r;
		 a[l]++;
		 a[r+1]--;
	}
	for(int i=1;i<=n;i++)a[i]+=a[i-1];
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==m)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> Point;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, PP> PPP;
typedef pair<double, Point> P2;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

double dis(Point p1, Point p2){
	return sqrt((p1.real() - p2.real())*(p1.real()-p2.real()) + (p1.imag() - p2.imag())*(p1.imag() - p2.imag()));
}

vector<PP> G[20];
int nextv[20];
int res;
vector<int> best;

void dfs(int v, int state, int cost, vector<int>& li){
	bool canmove = false;
	for(int i = 0; i < (int)G[v].size(); i++){
		int e = G[v][i].first;
		int next = G[v][i].second.first;
		int d = G[v][i].second.second;
		if(state & 1 << e) continue;
		vector<int> vi = li;
		vi.push_back(next);
		canmove = true;
		dfs(next, state | 1 << e, cost + d, vi);
	}

	if(!canmove){
		if(res < cost){
			res = cost;
			best = li;
		}else if(res == cost && best > li){
			best = li;
		}
	}
}

int main(){
	int ns, nl;
	while(cin >> ns >> nl && (ns || nl)){
		int c = 0;
		for(int i = 0; i < nl; i++){
			int s1, s2, d1;
			cin >> s1 >> s2 >> d1;
			G[s1].push_back(PP(c, P(s2, d1)));
			G[s2].push_back(PP(c++, P(s1, d1)));
		}
		res = -1;
		best.clear();
		for(int i = 1; i <= ns; i++){
			memset(nextv, -1, sizeof(nextv));
			vector<int> vi;
			vi.push_back(i);
			dfs(i, 0, 0, vi);
		}
		for(int i = 0; i < 20; i++) G[i].clear();
		cout << res << endl;
		for(int i = 0; i < (int)best.size(); i++){
			if(i != 0) cout << " ";
			cout << best[i] ;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int k,pw[10];
char s[5005];
vector <int> num;

int main(){
	scanf("%s", s);
	
	int l = strlen(s);
	
	scanf("%d", &k);
	
	pw[0] = 1;
	for(int i = 1; i <= 5; i++)
	pw[i] = pw[i - 1] * 27;
	
	for(int i = 0; i < l; i++){
		int cur = 0;
		
		for(int j = 0; j < 5; j++){
			if(i + j >= l) continue;
			cur += pw[4 - j] * (s[i + j] - 'a' + 1);
			num.push_back(cur);
		}
	}
	
	sort(num.begin(), num.end());
	num.resize(unique(num.begin(), num.end()) - num.begin());
	
	int tar = num[k - 1];
	
	vector <int> ans;
	
	while(tar){
		ans.push_back(tar % 27);
		tar /= 27;
	}
	
	reverse(ans.begin(), ans.end());
	
	for(int i = 0; i < ans.size(); i++){
		if(ans[i] == 0) continue;
		printf("%c", 'a' + ans[i] - 1);
	}
	
	printf("\n");
}


Measured memory_bytes: 512
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	x,y = map(int,input().split())	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# 3
# hoge
# foo
# bar
# n=int(input())
# string_list=[input() for i in range(n)]
# N, M = map(int,input().split())

# P, Y = [], []
# for _ in range(M):
#     P_i, Y_i = = map(int,input().split())
#     P.append(P_i)
#     Y.append(Y_i)

N, Time = map(int,input().split())

cs, ts = [], []
for _ in range(N):
    c, t = map(int,input().split())
    cs.append(c)
    ts.append(t)

ans_c = 9999
ans = None
for ind, (c, t) in enumerate(zip(cs, ts)):
    if c<ans_c and t<=Time:
        ans_c = c
        ans = ind

if ans is None:
    print("TLE")
else:
    print(ans_c)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>

int main(){
  int n;
  bool crct = true;
  scanf("%d",&n);
  std::vector<long> h = std::vector<long>(n+1);

  for(int i=0;i<n;i++){
    std::cin >> h[i];
  }

  h[n] = 2000000000;

  for(int i=0;i<n;i++){
    crct = h[i+1] >= h[i];
    if(!crct) break;
    h[i+1] = h[i+1] - (!(h[i]==h[i+1]));
  }

  if(crct){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


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

int main() {
  int N;
  int N_digit;
  int i=1;
  int ten_sq=10;
  int f,N_buff;
  int fX_buff=0;
  cin >> N ;
  while(N>=ten_sq){
    ten_sq*=10;
    i++;
  }
  N_digit=i;
    N_buff=N;
  for(int j=1;j<N_digit+1;j++){
    int Digit=1;
    for(int i=1;i<N_digit-j+1;i++){
      Digit*=10;
    }
    fX_buff+=N_buff/Digit;
    N_buff-=Digit*(N_buff/Digit);
  //        cout <<"fX_buff: "<< fX_buff <<endl; 
    //      cout <<"N_buff: "<< N_buff <<endl; 
  }
  f=N%fX_buff;
  if(f==0){
  cout << "Yes" <<endl;  
  }else{
    cout << "No" <<endl;  
  }
  // ここにプログラムを追記
  
}



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

signed main()
{
    int n, m, i;
    cin >> n;
    vector<int> a(n);
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    cin >> m;
    vector<int> b(m);
    for (i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    cout << lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()) << endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
char name[15];
int N;
map<string, int> mp;
map<string, int>::iterator iter; 
vector<string> vec;
bool cmp(const string a, const string b){
	return a < b;
}
int main(){
	cin >> N;
	int maxn = 0;
	for(int i = 0 ; i < N ; i++){
		cin >> name;
		mp[name]++;
		maxn = max(maxn, mp[name]);
	}
	for(iter = mp.begin() ; iter != mp.end() ; iter++)
		if(iter->second == maxn)
			vec.push_back(iter->first);
	//printf("%d\n", vec.size());
	sort(vec.begin(), vec.end(), cmp);
	for(int i = 0 ; i < vec.size() ; i++)
		cout << vec[i] << "\n";
	
} 

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

int main(){
    long int d,n;
    int s=1;
    cin >> d >> n;
if(n==100) {
    for(int i = 0;i<d;i++)
    {
        s*=100;
    }
    cout << s*101;
}
else cout << pow(100,d)*n;
}

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

int a[200010];

int main() {
	string s;
	cin >> s;
	string t = "";
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != 'x') t += s[i];
	}
	int m = t.size();
	bool ok = true;
	for (int i = 0; i < m; i++) {
		if (t[i] != t[m - i - 1]) ok = false;
	}
	if (!ok) {
		cout << -1 << endl;
	}
	else {
		int ans = 0;
		int p = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'x') {
				a[p]++;
			}
			else {
				p++;
			}
		}
		p++;
		for (int i = 0; i < p / 2; i++) {
			ans += abs(a[i] - a[p - i - 1]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>

int main()
{
  int i,j,mn;
  char b[1024];
  fgets(b,1024,stdin);
  mn = 10000;
  for(i = 0; isdigit(b[i]) && isdigit(b[i+1]) && isdigit(b[i+2]); i++){
    j = 753 - ( 100 * ((int)(b[i] - '0')) + 10 * ((int)(b[i+1] - '0')) + (int)(b[i+2]-'0') );
    if( j < 0 ) j = - j;
    if( j < mn ) mn = j;
  }
  printf("%d\n",mn);
  return EXIT_SUCCESS;

}



Measured memory_bytes: 128
import sys
import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    print(a[n-1]-a[0])
    return

if __name__=='__main__':
    main()


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

ll dp[100005];

int main() {
	int n, W;
	scanf("%d%d", &n, &W);
	for (int i=1 ; i<=100000 ; i++) dp[i] = INF;
	for (int i=0 ; i<n ; i++) {
		int w, v;
		scanf("%d%d", &w, &v);
		for (int i=100000 ; i>=v ; i--) {
			dp[i] = min(dp[i], dp[i-v]+w);
		}
	}
	int sol = 0;
	for (int i=0 ; i<=100000 ; i++) {
		if (dp[i] <= W) sol = i;
	}
	printf("%d\n", sol);
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    long long sum = A[N - 1];
    for (int i = N - 2; i > (N - 2 - (N - 2) / 2); --i) {
        sum += A[i] * 2;
    }
    if ((N - 2) % 2 == 1) {
        sum += A[N - 2 - (N - 2) / 2];
    }
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 4780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		digitNumber();
	}
	
	public static void digitNumber(){
		Scanner sc = new Scanner(System.in);
		int a,b,c;

		while(sc.hasNext()){
			a = sc.nextInt();
			b = sc.nextInt();
			c = a + b;
			String str = String.valueOf(c);
			System.out.println(str.length());
			
		}

	}

}

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<bool>> c(w, vector<bool>(h, true));
  while (n--) {
    int x, y, a;
    cin >> x >> y >> a;
    x--, y--;
    if (a == 1) {
      for (int i = 0; i <= x; i++) {
        for (int j = 0; j < h; j++) {
          c[i][j] = false;
        }
      }
    } else if (a == 2) {
      for (int i = x + 1; i < w; i++) {
        for (int j = 0; j < h; j++) {
          c[i][j] = false;
        }
      }
    } else if (a == 3) {
      for (int i = 0; i < w; i++) {
        for (int j = 0; j <= y; j++) {
          c[i][j] = false;
        }
      }
    } else {
      for (int i = 0; i < w; i++) {
        for (int j = y + 1; j < h; j++) {
          c[i][j] = false;
        }
      }
    }
    debug(c);
  }
  int ans = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      ans += c[i][j];
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
      if(N>=K){Console.WriteLine("10");}else{Console.WriteLine("0");}
                   // Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}

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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;

    int n;
    cin>>n;

    vector<int> memo(n+1);
    vector<int> a(n+1);
    memo[0]=1;
    rep(i,n+1){
        cin>>a[i];
        if(n==0&&a[i]!=1){
            cout<<-1<<endl;
            return 0;
        }
        if(i){
            memo[i]=min(memo[i-1]*2,1000000000000000ll);
        }
        memo[i]-=a[i];
        if(memo[i]<0){
            cout<<-1<<endl;
            return 0;
        }
    }

    int cnt=a[n],ans=a[n];
    rep(i,1,n+1){
        cnt=min(memo[n-i],cnt);
        ans+=cnt+a[n-i];
        cnt+=a[n-i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4784
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct edge { int to, cost; };
int V;
vector<edge> G[2000];
int d[2000]; int era[2000] = {};
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, (int)MOD);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < (int)G[v].size(); i++) {
			edge e = G[v][i];
			if (era[e.to])continue;
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main() {
	cin >> V; int k; cin >> k;
	int le; int ri;
	rep(i, V - 1) {
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back({ b,1 });
		G[b].push_back({ a,1 });
	}
	int out = (int)MOD;
	rep(i, V) {
		rep(j, V) {
			era[j] = 0;
		}
		dijkstra(i);
		int chk = -1;
		rep(j, V) {
			if (d[j] == k) {
				chk = j;
			}
			else if (d[j] > k)era[j] = 1;
		}
		if (chk == -1)continue;
		dijkstra(chk);
		int csum = 0;
		rep(j, V) {
			if (d[j] <= k)csum++;
		}
		out = min(out, V - csum);
	}
	if (out == (int)MOD) {
		out = 0;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 384
package main

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

func main() {
	s := IOInitialize()
	x1 := Int(s)
	y1 := Int(s)
	x2 := Int(s)
	y2 := Int(s)
	x3 := (y1 - y2) + x2
	y3 := -(x1 - x2) + y2
	x4 := -(y2 - y1) + x1
	y4 := (x2 - x1) + y1
	fmt.Println(x3, y3, x4, y4)
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}

func String(s *bufio.Scanner) string {
	if !s.Scan() {
		panic("scan error")
	}

	return s.Text()
}

func scanNums(s *bufio.Scanner, len int) (nums []int) {
	for i := 0; i < len; i++ {
		num := Int(s)
		nums = append(nums, num)
	}
	return
}

func scanstrings(s *bufio.Scanner, len int) (strs []string) {
	for i := 0; i < len; i++ {
		str := String(s)
		strs = append(strs, str)
	}
	return
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
 
#define MAXN 100000
const int M[15]={0,1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int N,MaxD;
int dp[MAXN+5];
 
int main(){
    scanf("%d",&N);
    memset(dp,0x3f,sizeof dp);
    dp[0]=0;
    for(int i=1;i<=12;i++)
        for(int j=M[i];j<=N;j++)
            dp[j]=min(dp[j],dp[j-M[i]]+1);
    printf("%d",dp[N]);
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)

using namespace std;
typedef long long int ll;
const int INF = 100000000;
bool next(vector<int> &use){
    int n = use.size();
    int p=1;
    for(int i=0;i<n;i++){
        use[i]+=p;
        if(use[i]>=4){
            use[i]-=4;
            p=1;
        }else{
            p=0;
        }
    }
    return p==0;
}

int main(){

    int N,A[3],l[1000];
    cin>>N>>A[0]>>A[1]>>A[2];
    for(int i =0;i<N;i++){
        cin>>l[i];
    }
    int ans = INF;
    vector<int> use(N,0);
    do{
//        rep(i,N){
//            cout<<use[i];
//        }cout<<endl;
        int nA[3]={0,0,0};
        int useflag = 0;
        int usecount = 0;
        for(int i = 0;i < N;i++){
            if(use[i]<3){
                nA[use[i]]+=l[i];
                useflag |= (1<<use[i]);
                usecount++;
            }
        }
        if(useflag!=7)continue;
        int temp = (usecount-3)*10;
        for(int i = 0;i < 3;i++){
            temp += abs(A[i]-nA[i]);
        }
        ans = min(ans,temp);
    }while(next(use));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
 
    int H, W;
 
    cin >> H >> W;
 
    while (H != 0 && W != 0)
    {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
 
    return 0;
} 
    


Measured memory_bytes: 3104
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;

	n %= 10;

	if(n == 3) cout << "bon";
	else if(n==0||n==1||n==6||n==8) cout << "pon";
	else cout << "hon";
	
	return 0;
}


Measured memory_bytes: 3588
my ($s) = split(/\s+/, <>);

my $a = substr($s, 0, 2);
my $b = substr($s, 2, 2);

if (1<=$a && $a<=12) {
    if (1<=$b && $b<=12) {
	print "AMBIGUOUS\n";
    } else {
	print "MMYY\n";
    }
} else {
    if (1<=$b && $b<=12) {
	print "YYMM\n";
    } else {
	print "NA\n";
    }
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=0&&b<=0||a<=0&&b>=0)
        cout<<"Zero";
    else
        if(a>0&&b>0)
            cout<<"Positive";
        else
            if((int)abs(a-b)%2!=0)
                cout<<"Positive";
            else
                cout<<"Negative";
    return 0;
}

Measured memory_bytes: 256
/**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-11@16:33

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;

int main(void){


        while(1){

                int sum = 1;
                int n=0;
                int a=1, b=2, c=3;
                int tmp = 0;
                        
                cin >> n;
                if(n == 0)break;
                
                vector <string> direction(n);
                
                for(int i=0; i<n; i++){
                        
                        cin >> direction[i];                        

                }
                
                for(int i=0; i<n; i++){

                   
                        if(direction[i] == "North"){
                                
                                tmp = a;
                                a = b;
                                b = 7 - tmp;
                                sum = sum + a;
                        }else if(direction[i] == "East"){

                                tmp = a;
                                a = 7 - c;
                                c = tmp;
                                sum = sum + a;
                        }else if(direction[i] == "West"){

                                tmp = a;
                                a = c;
                                c = 7 -tmp;   
                                sum = sum + a;                             

                        }else if(direction[i] == "South"){

                                tmp = a;
                                a = 7 - b;
                                b = tmp;
                                sum = sum + a;
                        }else if(direction[i] == "Right"){

                                tmp = b;
                                b = c;
                                c = 7 - tmp;                                
                                sum = sum + a;
                        }else if(direction[i] == "Left"){

                                tmp = c;
                                c = b;
                                b = 7 - tmp;                                
                                sum = sum + a;
                        }

                }

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


}

Measured memory_bytes: 1492