akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int m;
	int b;
	int f;
	scanf("%d %d %d",&m,&f,&b);
	if((m+f)>=b)
	{
		if(b>=m)
		{
		printf("%d\n",b-m);
		}
		if(b<m)
		{
			printf("0\n");
		}
	}else{
		printf("NA\n");
	}
	return 0;
}


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

int n,s;
int ans;

void dfs(int sum,int flor,int last){
    if(sum>s)return ;
    
    if(flor==n){
        if(sum==s)ans++;
        return ;
    }
    rep(i,10){
        if(i<=last)continue;
        dfs(sum+i,flor+1,i);
    }
}


int main(){
    while(cin>>n>>s&&(n||s)){
        ans = 0;
        dfs(0,0,-1);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3060
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#include <tuple>
#include <queue>
#include <cassert>
#include <set>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define el '\n'
 

 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n,m,k;
	cin >>n>>m>>k;
	vector<vector<char> > gr(n, vector<char>(m));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> gr[i][j];
		}
	}


	ll sol = 0;

	for (int i = 0;  i < (1 << (n )); i++){
		for (int j = 0; j < (1 << (m )); j++){

			int l = 0;
			for (int x = 0; x < n; x++){
				for (int y = 0 ; y < m; y++){
					int X = 1 << x, Y = 1 << y;
					if (X & i ||  Y & j) continue;
					if (gr[x][y] == '#'){
						
						l++;
					}
				}
			}

			if (l == k){
				sol ++;
			}
		}
	}

	cout << sol<<el;
    return 0;
}

Measured memory_bytes: 3120
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	var xy = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
		xy[i] = new Array(W);
		for(var j = 0; j < W; j++){
			xy[i][j] = {
				x : (list[i][j] == ".") ? 1 : 0,
				y : (list[i][j] == ".") ? 1 : 0
			};
		}
	}
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			if(i == 0 && j == 0){continue;}
			if(j != 0){
				if(xy[i][j].x != 0){
					xy[i][j].x += xy[i][j - 1].x;
				}
			}
			if(i != 0){
				if(xy[i][j].y != 0){
					xy[i][j].y += xy[i - 1][j].y;
				}
			}
		}
	}
	for(var i = H - 1; i >= 0; i--){
		for(var j = W - 1; j >= 0; j--){
			if(list[i][j] == "#"){continue;}
			if(i - 1 != -1 && list[i - 1][j] == "."){
				xy[i - 1][j].y = xy[i][j].y;
			}
			if(j - 1 != -1 && list[i][j - 1] == "."){
				xy[i][j - 1].x = xy[i][j].x;
			}
		}
	}
	var max = 0;
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			max = Math.max(max, xy[i][j].x + xy[i][j].y - 1);
		}
	}
	myout(max);
}


Measured memory_bytes: 284692
import sys
L,R = map(int,input().split())
i = L
j = i+1
p =2019
min_ij = ((i%p)*(j%p))%p
for i in range(L,R):
  for j in range(i+1,R+1):
    if i % p == 0 or j %p == 0:
      print(0)
      sys.exit()
    if min_ij > ((i%p)*(j%p))%p:
      min_ij = ((i%p)*(j%p))%p

print(min_ij)
    
  



Measured memory_bytes: 3064
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include <map>
 
using namespace std;
 
void solve();
 
int main() {
	solve();
}
 
// ============= actual code starts here =================
 
const int limit = 100500 * 2;
int n;
int a[ limit ];

void solve() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[ i ]);
	}

	int mx = 0;
	long long ans = 0;
	for(int i = 0; i < n; i++) {
		mx = max(mx, a[ i ]);
		ans += (mx - a[ i ]);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 4596
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
//最大公約数
ll gcd(ll a, ll b){
  if(b == 0)return a;
  else return gcd(b, a % b);
}



int main(){
    ll n;
    cin >> n;
    vector<ll> a(5);
    ll m = INF * INF;
    rep(i, 5){
        cin >> a[i];
        chmin(m, a[i]);
    }
    ll res = (n + m - 1) / m + 4;
    cout << res << endl;
}





Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
#define R READ();
using namespace std;
typedef long long LL;
void READ()
{
    std::ios::sync_with_stdio(false);
//#ifdef ONLINE_JUDGE
//#else
   // freopen("555input.txt","r",stdin);
//    //freopen("555output.txt","w",stdout);
//#endif
}
#define N 100005
int ans,n,t,i,a[N],num;
int main()
{
    R
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=1,num=1;i<=n;i++)
    {
        if(a[i]!=a[i-1]){ans+=num%2;num=1;}
        else num++;

    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
using namespace std;
int ans = 0;
char c[100][100];
void judge(int i, int j) {
	char tmp = c[i][j];
	c[i][j] = 'X';
	if (i > 0&&c[i-1][j]==tmp)judge(i - 1, j);
	if (j > 0&&c[i][j-1]==tmp)judge(i, j - 1);
	if (i < 99&&c[i+1][j]==tmp)judge(i + 1, j);
	if (j < 99&&c[i][j+1]==tmp)judge(i, j + 1);
}
int main() {
	int h, w;
	do {
		ans = 0;
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++)
				c[i][j] = 'X';
		}
		cin >> h >> w;
		if (h == 0)break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++)
				cin >> c[i][j];
		}
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++)
				if (c[i][j] != 'X') { judge(i, j); ans++; }
		}
		cout << ans<<endl;
} while (1);
return 0;
	}

Measured memory_bytes: 1936
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, S: str):
    is_mid = True if S[A] == "-" else False
    is_num = (S[:A] + S[A + 1 :]).find("-") == -1
    print(YES if is_mid and is_num else NO)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(A, B, S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    int A;
    vector<int> score(N+1, K-Q);                  /*N+1とする・vector<int> scores(N + 1, K - Q);のような書き方が便利*/
    for(int i=0; i<Q; i++){
        cin >> A;                                 /*Aは1からNの値を代入する*/
        score[A]++;                               /*stray ‘\200’ in programやstray ‘\343’ in programは空白が原因*/
        
    }
    for(int i=1; i<N+1; i++){                       /*int i=1とする*/
        if(score[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int n, dp[3][100005], i, a[100005], b[100005], c[100005];
int main(){
	cin >> n;
	for (i = 0; i < n; ++i)cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0], dp[1][0] = b[0], dp[2][0] = c[0];
	for (i = 1; i < n; ++i){
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[i];
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b[i];
		dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c[i];
	}
	cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1]));
}

Measured memory_bytes: 2560
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            var min = 0;
            var max = 0;
            var memo = new int[8];
            Array.Sort(a);
            for (int j = 0; j <a.Length; j++)
            {
                for (int i = 0; i < 8; i++)
                {
                    if (i * 400 <= a[j] && a[j] < (i + 1) * 400 && memo[i] == 0) memo[i] = 1;
                }
                if (a[j] >= 3200)
                {
                    if (memo.Sum() == 0) min = 1;
                    else min = 0;
                    max++;
                }
            }
        
            WriteLine("{0} {1}", memo.Sum() + min, memo.Sum() + max);



            

            Console.Out.Flush();
        }
    }
}



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

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


Measured memory_bytes: 2620
import java.util.Scanner;

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

        String[] array = scanner.nextLine().split(" ");

        long A = Long.parseLong(array[0]);
        long B = Long.parseLong(array[1]);
        //long C = Long.parseLong(array[2]);
        long K = Long.parseLong(array[3]);

        if ((K & 1) == 0) {
            System.out.println(A - B);
        } else {
            System.out.println(B - A);
        }
    }
}

Measured memory_bytes: 23380
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100000;

int main(){
    int N;
    int H[MAX];

    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> H[i];
    }

    int cnt = 0;
    int ans = 0;

    for(int i = 1;i < N;i++){
        if(H[i - 1] >= H[i]){
            
            cnt++;
        }else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    ans = max(ans,cnt);

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
#include<iostream>
using namespace std; 
int main(){  
  int x,y;   
  while(1){
	  cin>>x>>y;
	 
	if     (x<y){cout<<x<<" "<<y<<endl; }   
		
	else if(x>y){cout<<y<<" "<<x<<endl; }
    
	else if(x==y&&x!=0) { cout<<x<<" "<<y<<endl;}
    
	else if(x==0&&y==0){break;} 
}  

return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(){
  int N,K,i,j,t=0;
  int p[1000];
  scanf("%d %d",&N,&K);
  for(i=0;i<N;i++){
    scanf("%d",&p[i]);
  }
  for(j=0;j<N-1;j++){
  for (i=0;i<N-1-j;i++){
            if(p[i]>p[i+1]){
                int temp = p[i];
                p[i]=p[i+1];
                p[i+1]=temp;
            }
   }
  }
  for(i=0;i<K;i++){
    t=t+p[i];
  }
  printf("%d",t);
  return 0;
}

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

int main() {

    ll N, K;
    cin >> N >> K;

    ll ans = N%K;

    if (ans > abs(ans-K)) {
        ans = abs(ans-K);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll N) {
  string s = to_string(N);
  bool pred = s.find('9') != s.npos;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


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

#define DEBUG(C) std::cerr << #C << " = " << C << std::endl;

const int MOD = (int)1e9 + 7;

/**
* Binary_Indexed_Tree(BIT) 2d by mod
* Fenwick Tree
* 0-indexed!!!
* O((log N)(log M))
*/
template<int mod>
class binary_indexed_tree_2d_by_mod {
private:
    int N;
    int M;
    std::vector<std::vector<int>> bit;

    void add(int &a, int b) {
        if (b < 0) b += mod;
        a += b;
        if (a >= mod) a -= mod;
    }

    int sum(int x, int y) {
        int res = 0;

        for (int i = x; i > 0; i -= i & (-i)) {
            for (int j = y; j > 0; j -= j & (-j)) {
                this->add(res, this->bit[i - 1][j - 1]);
            }
        }
        return res;
    }

public:
    binary_indexed_tree_2d_by_mod() {}
    binary_indexed_tree_2d_by_mod(int n, int m) : N(n + 2), M(m + 2), bit(n + 2, std::vector<int>(m + 2)) {}

    void add(int x, int y, long long val) {
        // for mod calc
        val %= mod;
        // for 0-indexed
        x++; y++;

        for (int i = x; i - 1 < N; i += i & (-i)) {
            for (int j = y; j - 1 < M; j += j & (-j)) {
                this->add(this->bit[i - 1][j - 1], val);
            }
        }
    }

    // [ (x1, y1), (x2, y2) )
    int sum(int x1, int y1, int x2, int y2) {

        int res = this->sum(x2, y2);
        add(res, -sum(x1, y2));
        add(res, -sum(x2, y1));
        add(res, sum(x1, y1));

        return res;
    }
};



const int MAX = 2e3 + 10;
int N, M;
binary_indexed_tree_2d_by_mod<MOD> bit;

int main(void) {
    std::cin >> N >> M;
    std::vector<int> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }
    std::vector<int> T(M);
    for (int i = 0; i < M; i++) {
        std::cin >> T[i];
    }
    bit = binary_indexed_tree_2d_by_mod<MOD>(N + 1, M + 1);

    bit.add(0, 0, 1);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (S[i] == T[j]) {
                bit.add(i + 1, j + 1, bit.sum(0, 0, i + 1, j + 1));
            }
        }
    }

    std::cout << bit.sum(0, 0, N + 1, M + 1) << std::endl;
}


Measured memory_bytes: 16000
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;
template <typename T>
T in(){
    T x;
    cin >> x;
    return x;
}

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

int digit(int n){
    int ans=0;
    while (n>0){
        ans+=n%10;
        n/=10;
    }
    return ans;
}

main(){
    string s=in<string>();
    int ans=0,n=s.size();
    for (int i=0;2*i<n;i++){
        if (s[i]!=s[n-i-1]) ans++;
    }
    out(ans);
}

Measured memory_bytes: 256
n=int(input())
xyh=sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[2])

for cx in range(0,101):
    for cy in range(0,101):
        flag=True
        h=abs(cx-xyh[0][0])+abs(cy-xyh[0][1])+xyh[0][2]
        for i in range(n):
            if max(h-abs(cx-xyh[i][0])-abs(cy-xyh[i][1]), 0)!=xyh[i][2]:
                flag=False
        if flag:
            print(cx,cy,h)
            exit()



Measured memory_bytes: 9180
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int y=2019,m=4,d=30;
	string s;
	cin>>s;int n=s.length();
	int yy=0,mm=0,dd=0;
	for(int i=0;i<4;i++)
	{
		yy=10*yy+(s[i]-'0');
	}
	for(int i=5;i<7;i++)
	{
		mm=10*mm+(s[i]-'0');
	}
	for(int i=8;i<n;i++)
	dd=10*dd+(s[i]-'0');
	bool late=1;
	if(yy<=y and mm<=m and dd<=d)
	{
		late=0;
	}
	
	if(late)puts("TBD");else puts("Heisei");
	
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

vector<vector<int>> G;
ll n, m, ans = 0;
ll dp[100100];

int f(int v) {
  if (dp[v] != -1) return dp[v];

  int res = 0;
  for (int u : G[v]) res = max(res, f(u) + 1);
  return dp[v] = res;
}

int main() {
  cin >> n >> m;
  G.assign(n, vector<int>());
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
  }

  rep(i, n) dp[i] = -1;
  int res = 0;
  rep(i, n) res = max(res, f(i));

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	
	if(a > b){
		cout << "a > b" << endl;
	}else if (a < b){
		cout << "a < b" << endl;
	}else{
		cout << "a == b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
n, m = (int(x) for x in input().split())
list_h = list(map(int, input().split()))
list_n =[[-1 for i in range(1)] for j in range(n)]
count=0
for i in range(m):
    a,b = (int(x) for x in input().split())
    if list_n[a-1]==-1:
        list_n[a-1]=b
    else:
        list_n[a-1].append(b)
    if list_n[b-1]==-1:
        list_n[b-1]=a
    else:
        list_n[b-1].append(a)
for i in range(n):
    boo = True
    h = list_h[i]
    for j in range(len(list_n[i])):
        if list_n[i][j]==-1:
            pass
        else:
            k = list_n[i][j]
            if h<=list_h[k-1]:
                boo=False
    if boo:
        count+=1
print(count)

Measured memory_bytes: 97188
#include<bits/stdc++.h>
#define int long long
#define vin vector<int>
#define vcn vector<char>
#define ver pair<int,int>
#define pb push_back
#define ld long double
#define x first
#define y second
#define blush fflush(stdout);fflush(stdin);
#define $(a) (int)a.size()
#define scanf ;
#define printf ;
using namespace std;
void i_love_misaka_mikoto();
int32_t main(){
    #ifdef RNS
        freopen("input.txt","r",stdin);
        #ifndef DBG
            freopen("output.txt","w",stdout);
        #endif
    #else
        ios_base::sync_with_stdio(false);
    #endif
    i_love_misaka_mikoto();
    #ifdef RNS
        cout<<'\n'<<(ld)clock()/CLOCKS_PER_SEC<<'\n';
    #endif
    return 0;
}
int sp[(int)1e5][3];
void i_love_misaka_mikoto(){
    int n;
    cin>>n;
    vin a(n), b(n), c(n);
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    sp[0][0]=a[0], sp[0][1]=b[0], sp[0][2]=c[0];
    for(int i=1;i<n;i++){
        sp[i][0]=max(sp[i-1][1], sp[i-1][2])+a[i];
        sp[i][1]=max(sp[i-1][0], sp[i-1][2])+b[i];
        sp[i][2]=max(sp[i-1][1], sp[i-1][0])+c[i];
    }
    cout<<max(max(sp[n-1][0], sp[n-1][1]), sp[n-1][2]);
}

Measured memory_bytes: 4992
N,Q = map(int,input().split())
Min_x = [-1 for _ in range(N)] #一番遠い位置にある黒(0index)
#Min_x[N-1] = -1
Min_y = [-1 for _ in range(N)] #一番遠い位置にある黒(0index)
#Min_y[N-1] = -1
black = (N-2)**2
a = N-2; b = N-2 #左上の四角の部分
for query in range(Q):
  #print(black)
  temp = list(map(int,input().split()))#1index #x-=1 #0index
  if temp[0] == 1: #上に置く
    w = temp[1]-1 #0index
    if w <= b:
      #左上の更新する四角の中の場合、更新前の値が裏返りに使われる。
      black -= a #一番遠い黒-1 (0行目にはない）裏返る。0indexなのでそのまま引いてよい。
      for yoko in range(w,b+1): #w~bまで
        Min_y[yoko] = a
      b = w-1
    else:
      #既に更新する四角から外れている場合には既存の値を入れる。
      black -= Min_y[w] #一番遠い黒-1 (0行目にはない）裏返る。0indexなのでそのまま引いてよい。
  else: #横に置く
    h = temp[1]-1 #0index
    if h <= a:
      #左上の更新する四角の中の場合、更新前の値が裏返りに使われる。
      black -= b #一番遠い黒-1 (0行目にはない）裏返る。0indexなのでそのまま引いてよい。
      #print(h,a)
      for tate in range(h,a+1): #w~bまで
        Min_x[tate] = b
      a = h-1
    else:
      #既に更新する四角から外れている場合には既存の値を入れる。
      black -= Min_x[h] #一番遠い黒-1 (0行目にはない）裏返る。0indexなのでそのまま引いてよい。      
  #print("x",Min_x)
  #print("y",Min_y)
  #print("black", black)
print(black)      

    

Measured memory_bytes: 100236
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	ll n, m, q;
	cin >> n >> m >> q;
	vector<vector<ll>> al(510, vector<ll>(510));
	vector<vector<ll>> sum(510, vector<ll>(510));
	rep(i, m) {
		ll l, r;
		cin >> l >> r;
		al[l][r] += 1;
	}
	repi(i, 1, 510) {
		repi(j, 1, 510) {
			sum[i][j] = al[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}
	vector<ll> ansl(q);
	rep(i, q) {
		ll ans = 0;
		ll l, r;
		cin >> l >> r;
		ans = sum[r][r] - sum[r][l - 1] - sum[l - 1][r] + sum[l - 1][l - 1];
		ansl[i] = ans;
	}
	rep(i, q) {
		cout << ansl[i] << endl;
	}
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}


Measured memory_bytes: 8180
# -*- coding: utf-8 -*-

# 標準入力
K, X = map(int, input().split())
#input_num_str= input()
#input_num = int(input())

# スペース区切りの整数の入力
#num_list = list(map(int,input().split()))

min = X - (K - 1)
max = X + (K - 1)
len = max - min +1

result = ''
for i in range(min,max + 1):
    result = result + str(i) + ' '

print(result)

Measured memory_bytes: 3060
# coding: utf-8
import queue
INF = 10000000

q = queue.PriorityQueue()

#初期化
G = []
kabe = []
H, W = map(int, input().split())

#入力
for i in range(10):
    G.append(list(map(int, input().split())))

for i in range(H):
    kabe.append(list(map(int, input().split())))

lenList = [INF for i in range(10)]

def bfs():
    global G
    global q
    global lenList
    
    x = q.get()
    #行ったことあるものは捨てる。
    while lenList[x[1]] != INF:
        return
    
    #間違いなく最短なので更新
    lenList[x[1]] = x[0]

    #行ったことないところをプッシュ
    for i in range(10):
        if lenList[i] == INF:
            q.put([x[0] + G[i][x[1]], i])

#初期値を入力して発火
q.put([0, 1])
while not(q.empty()):
    bfs()

sum = 0

for i in range(H):
    for j in range(W):
        if kabe[i][j] != -1:
            sum += lenList[kabe[i][j]]

print(sum)

Measured memory_bytes: 4464
#include<iostream>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
int main() {
	ll N;
	cin >> N;
	ll T[3010];
	ll sum = 0;
	ll ans = 1;
	for (ll i = 0; i<N; ++i) {
		cin >> T[i];
    }
  	for (ll i = 0; i<N; ++i) {
		sum+=T[i];
    }
  cout<<sum-N<<endl;
}
  	


Measured memory_bytes: 256
N = int(input())
A, B = (input().split())

S1=list(A)
S2=list(B)
C = [A] * (N*2)

for i in range(N*2):
	if (i+1)%2!=0:
		C[i] = A[i//2]
	else:
		C[i] = B[(i-1)//2]

print(''.join(C))


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
using namespace std;
int main(){
  vector<pair<long int ,long int> > v;

  int N;
  cin >> N;

  for(int i = 0; i < N; ++i){
    int a,b;
    cin >> a >> b;
    v.push_back(make_pair(b,a));
  }
  sort(v.begin(),v.end());

  int k = 0,t = 0;
  bool flag = true;

  for(int k = 0; k < N; ++k){
    t += v[k].second;
    if(t > v[k].first){
      flag = false;
      break;
    }
  }

  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
const long long N=1e6+10;
using namespace std;
long long a[N],f[N],ans=1000000000000+1,n,k;
bool cmp(long long x,long long y){
	return x>y;
}
bool check(long long x){
	long long sum=0;
	for(int i=1;i<=n;i++){
		long long now=a[i]*f[i];
		if(now>x){
			if((now-x)%f[i]==0)sum+=(now-x)/f[i];
			else{sum+=(now-x)/f[i]+1;}
			if(sum>k)return false;
		}
	}
	return true;
}
int main(){
	scanf("%lld%lld",&n,&k);
	long long s1=0,s2=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		s1=max(s1,a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&f[i]);
		s2=max(s2,f[i]);
	}
	sort(a+1,a+n+1);
	sort(f+1,f+n+1,cmp);
	long long l=0,r=1000000000000;
	while(l<=r){
		long long mid=(l+r)>>1;
		if(check(mid)){
			ans=min(mid,ans);
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 5888
N, M = map(int, input().split(" "))
X = [int(n) for n in input().split(" ")]

X = sorted(X)

if len(X) <= N:
	print(0)

else:
	l = []
	for n in range(len(X)):
		if n != 0:
			l.append(abs(X[n - 1] - X[n]))

	ans = 0
	l = sorted(l, reverse=False)
	for i in range(M - N):
		ans += l.pop(0)

	print(ans)

Measured memory_bytes: 13840
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

bool matchesACGT(char c) {
  bool res = false;
  char acgt[] = {'A', 'C', 'G', 'T'};
  rep(i, 4) if(c == acgt[i]) res = true;
  return res;
}

bool isACGT(string s, int pos, int len) {
  bool res = true;
  string subs = s.substr(pos, len);
  rep(i, len) {
    if(!matchesACGT(subs[i])) {
      res = false;
      break;
    }
  }

  return res;
}

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(int len = 0; len <= s.size(); len++)
    for(int pos = 0; pos <= s.size() - len; pos++)
      if(isACGT(s, pos, len)) ans = max(ans, len);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a(n+1);
  rep(i,n+1) cin>>a[i];
  vll t(n+1);
  t[n]=a[n];
  rep(i,n){
    t[n-i-1]+=t[n-i]+a[n-i-1];
  }
  ll ans=0;
  ll cu=1;
  rep(i,n+1){
    if(cu<a[i]){
      COUT(-1);
      return 0;
    }

    ans+=cu;
    cu-=a[i];
    if(i<n)cu=min(t[i+1],cu*2);
  }
  COUT(ans);
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, n1, n2, n3, n4;
  cin >> N ;
  
  n1 = N / 1000;
  n2 = (N % 1000)/100;
  n3 = (N % 100)/10;
  n4 = N % 10;
  
  if (((n1 == n2) && (n2 == n3)) || ((n2 == n3) && (n3 == n4))){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> f(n);
  for(int i=1;i<100;i++){
    for(int j=1;j<100;j++){
      for(int k=1;k<100;k++){
        int N=i*(i+j)+j*(j+k)+k*(k+i);
        if(N>n)
          break;
        else
        f[N-1]++;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << f.at(i) << endl;
  }
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(all(v));
	cout << v[0] * v[1] / 2 << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int max = 0;
        int tmp = 0;
        for(int i = 0;i<s.length();i++){
            if(s.charAt(i) == 'A' | s.charAt(i) == 'C' | s.charAt(i) == 'G' | s.charAt(i) == 'T'){
                tmp++;
                if(s.length()-1 == i){
                    max = Math.max(tmp,max);
                }
            }else{
                max = Math.max(tmp,max);
                tmp = 0;
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

template <typename T>
T chmax(T &a, const T &b) { return a = (a > b ? a : b); }
template <typename T>
T chmin(T &a, const T &b) { return a = (a < b ? a : b); }

int main()
{
    int m;
    cin >> m;
    vl d(m), c(m);
    rep(i, m)
    {
        cin >> d[i] >> c[i];
    }
    ll ans = 0, pre = -1;

    auto calcCnt1 = [&](ll num) {
        if (pre == -1)
            pre = num;
        else
        {
            ans++;
            pre += num;
            if (pre >= 10)
            {
                ++ans;
                pre = pre % 10 + 1;
            }
        }
    };

    stack<pll> st;
    repr(i, m) st.push(make_pair(d[i], c[i]));
    while (st.size() > 0)
    {
        auto p = st.top();
        st.pop();
        ll num = p.fi, cnt = p.se;
        // dump(num), dump(cnt), dumpL(pre);
        assert(num< 10);
        // if (num == 0)
        //     ans += cnt;
        // else
        {

            while (1)
            {
                assert(num < 10);
                if (cnt == 1)
                {
                    calcCnt1(num);
                    // dump(num), dump(cnt), dumpL(pre);
                    break;
                }
                else
                {
                    if (cnt & 1LL)
                    {
                        --cnt;
                        st.push(make_pair(num, 1));
                    }
                    cnt /= 2;
                    ans += cnt;
                    num += num;
                    if (num >= 10)
                    {
                        ans += cnt;
                        num = num % 10 + 1;
                    }
                }
            }
        }
    }
    dumpL(pre);
    assert(pre > 0 && pre < 10);
    cout << ans << endl;
    return 0;
}

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

int main(){
	int c, x, n; cin>>x>>n;
	vector<int> C(101+1, 0); // candidate:[0,101]
	rep(i, n){ int p; cin>>p; C[p] = 1; }
	rep(d, 100){
		c = x - d;
		if(!C[c]){ cout<<c<<endl; return 0; }
		c = x + d;
		if(!C[c]){ cout<<c<<endl; return 0; }
	}
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  vector<int> a(3);
  cin >> a;

  int k = in();
  sort(rall(a));
  while (k--) a[0] *= 2;

  cout << accumulate(all(a), 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 21;const ll inf = 1e16;
int n,a[N];ll f[N][N][150000];
int ch[150000][2],tot;Pii t[150000];map<Pii,int>Map;
void dfs(int dep, int x, int y){
	if(dep<=0)return;
	if(!Map.count(Pii(x,y))){Map[Pii(x,y)]=++tot;t[tot]=Pii(x,y);}
	else return;
	int tmp=Map[Pii(x,y)];
	dfs(dep-1,x,x+y);dfs(dep-1,x+y,y);
	ch[tmp][0]=Map[Pii(x,x+y)];ch[tmp][1]=Map[Pii(x+y,y)];
}
ll qry(int l, int r, int u){
	if(l>r)return 0;if(f[l][r][u]<inf)return f[l][r][u];
	assert(u);ll res=inf;
	rep(i,l,r)umin(res,1LL*(t[u].fi+t[u].se)*a[i]+qry(l,i-1,ch[u][0])+qry(i+1,r,ch[u][1]));
	return f[l][r][u]=res;
}
int main() {
	read(n);dfs(n-3,1,2);dfs(n-3,2,1);cerr<<tot<<endl;
	rep(i,1,n)read(a[i]);
	rep(i,0,N-1)rep(j,0,N-1)rep(k,0,tot)f[i][j][k]=inf;
	ll res=inf;
	rep(i,2,n-1)umin(res,a[1]+a[n]+a[i]*2LL+qry(2,i-1,Map[Pii(1,2)])+qry(i+1,n-1,Map[Pii(2,1)]));
	if(n==2)res=a[1]+a[2];
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 525952
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
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; }

int main(){
  char a[4];
  rep(i,4) cin>>a[i];

  bool flag=false;
  rep(i,3){
    if(a[i+1]==a[i]) flag=true;
  }

  if(flag) cout<<"Bad";
  else cout<<"Good";
  cout<<endl;
}

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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	int n;
	scanf("%d",&n);
	pair<ii,ii> p[n];
	for(int i=0;i<n;i++){
		scanf("%lld%lld%lld",&p[i].fi.se,&p[i].se.fi,&p[i].se.se);
		p[i].fi.fi=p[i].fi.se+p[i].se.fi;
	}
	ll dp[20005];memset(dp,0,sizeof(dp));
	ll ans=0;
	sort(p,p+n);
	for(int i=0;i<n;i++){
		for(int j=p[i].fi.fi;j>=p[i].fi.se;j--){
			dp[j]=max(dp[j],dp[j-p[i].fi.se]+p[i].se.se);
			ans=max(ans,dp[j]);
		}
	}
	printf("%lld",ans);
}


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

#define MAX 100

void trace(int *a, int n)
{
     int i;
     for (i = 0; i < n - 1; i++)
         printf("%d ", a[i]);
     printf("%d\n", a[i]);
      
}

void insertion_sort(int *a, int n)
{
     int i, j, v;
     for (i = 1; i < n; i++) {
         v = a[i];
         j = i - 1;
         trace(a, n);
         while (j >= 0 && a[j] > v) {
               a[j+1] = a[j];
               j--;
         }
         a[j+1] = v;
     }
     trace(a, n);
}

int main(int argc, char *argv[])
{
	int i, n, a[MAX];

	scanf("%d", &n);
  
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    insertion_sort(a, n);

    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, c, b, ans;
int a;

int main() {
    rep(0,5) {
        scanf(" %d", &a);
        if (a == 0) break;
    }

    printf("%d\n", i+1);
}

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

using namespace std;


int main()
{
    //freopen("dulieu","r",stdin);
    string s;
    cin>>s;
    string key=" keyence ";
    int i,j,n=s.length();
    //cout <<s<<key<<endl;
    if (n<7)
    {
        cout << "NO";
    }
    else
    {
        for (i=1; i<=8; i++)
        {
            if (s[i-1]!=key[i]) break;
        }
        for (j=7; j>=0; j--)
        {
            //cout << "SS "<<key[j]<<s[n-8+j]<<endl;
            if (key[j] != s[n-8+j]) break;
        }
        //cout <<i<< ' '<<j<<endl;
        cout<< (i>=8 || j<=0 || j<=i-1 ? "YES" : "NO");
    }


    return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<int>v[2009];
int dis[2009];
int a[2009];
bool vs[2009];
void bfs(int x)
{
    queue<int>q;
    q.push(x);
    dis[x]=0;
    vs[x]=1;
    while(!q.empty())
    {
        int a=q.front();
        q.pop();
        for(int i=0; i<v[a].size(); i++)
        {
            int gg=v[a][i];
            if(vs[gg]==0)
            {
                dis[gg]=dis[a]+1;
                q.push(gg);
                vs[gg]=1;
            }
        }

    }

}
int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=2; i<=n; i++)
    {
        v[i].pb(i-1);
        v[i-1].pb(i);
    }
    v[x].pb(y);
    v[y].pb(x);
    for(int i=1; i<=n; i++)
    {
        MEM(dis,0);
        MEM(vs,0);
        bfs(i);
//        cout<<i<<"...\n";
//        for(int j=1;j<=n;j++)
//            cout<<dis[j]<<" ";
//        cout<<endl;
        for(int j=0; j<=n; j++)
            a[dis[j]]++;
    }
    for(int i=1;i<n;i++)
        cout<<(a[i]+1)/2<<"\n";
}


Measured memory_bytes: 384