akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

const lint mod = 1e9 + 7;

lint powmod(long x, long n){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

vector<lint> fact;
vector<lint> revfact;

void setfact(int n){
  fact.resize(n+1); revfact.resize(n+1);
  fact[0] = 1;
  rep(i, n) fact[i+1] = fact[i] * (i+1) % mod;
  
  revfact[n] = powmod(fact[n], mod-2);
  for(int i=n-1; i>=0; i--) revfact[i] = revfact[i+1] * (i+1) % mod;
}

lint getC(int n, int r){
    if(n < r) return 0;
  return fact[n] * revfact[r] % mod * revfact[n-r] % mod;
}

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    setfact(2019);
    For(i, 1, k+1){
        if(i == 1) printf("%d\n", n-k+1);
        else if(i > n-k+1) printf("0\n");
        else{
            lint ans = 0;
            rep(l, n-k+1) ans = (ans + (l+1) * getC(n-k-l-1, i-2) % mod) % mod;
            printf("%lld\n", ans * getC(k-1, i-1) % mod);
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
    int n,t,a;
    cin >> n >> t >> a;
    int h[1010];
    for (int i=0;i<n;++i) cin >> h[i];
    
    for (int i=0;i<n;++i) {
        h[i] = 1000*t - 6*h[i] - 1000*a;
        if (h[i] < 0) h[i] = -h[i];
    }
    int index = 0;
    for (int i=1;i<n;++i){
        if (h[index] > h[i]) index = i;
    }
    cout << index+1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    int c, a, n, ans = 0;
    cin >> c >> a >> n;
    while(c > 0 && a > 0 && n > 0)
    {
      c--; a--; n--;
      ans++;
    }
    while(c > 1 && a > 0)
    {
      c -= 2; a--;
      ans++;
    }
    ans += c / 3;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int w,h;cin >> h >> w;

    char c[101][101];

    for(int i=0 ; i<h ; i++){
        for(int j=0 ; j<w ; j++){
            cin >> c[j][i];
        }
    }

    for(int i=0 ; i<h ; i++){
        for(int j=0 ; j<w ; j++){
            cout <<c[j][i];
        }
        cout << endl;
        for(int j=0 ; j<w ; j++){
            cout <<c[j][i];
        }
        cout << endl;
    }
}

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

#include <math.h>
#include <stdlib.h>


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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m; cin >> n >> m;
    string s; cin >> s;

    vector<int> path;

    int pos = n;
    while(pos > 0){
        bool check = false;
        for(int i = m; i > 0; i--){
            if(pos - i < 0) continue;
            if(s[pos-i] == '1') continue;
            pos = pos - i;
            path.push_back(i);
            check = true;
            break;
        }
        if(!check){
            cout << -1 << endl;
            return 0;
        }
    }

    int l = path.size();
    cout << path[l-1];
    for(int i = l-2; i >= 0; i--){
        cout << " " << path[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1096
import collections
N=int(input())
a=0
list1 = list(map(int, input().split()))
c = collections.Counter(list1)
for i in range(N):
    a+=int(c[i+1]*(c[i+1]-1)/2)
for i in range(N):
    if c[list1[i]]!=0:
        print(a-c[list1[i]]+1)
    else:
        print(a)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (int)(n); (i) += (step))
#define ROF(i, a, n, step) for (int (i) = (a); (i) >= (int)(n); (i) += (step))
#define FOREACH(it, v) for (auto (it) : (v))

using namespace std;

typedef unsigned long long ull;
typedef long long ll ;
typedef long double ld;
typedef pair <int, int> pii;

template <class T>
const bool is_impar(const T &x) {return (bool) (x & 1);}

int n, m, nrfin;
vector <pii> v;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    v.resize(m);
    FOR (i, 0, m, 1)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), [] (pii a, pii b) -> int {
        if (a.first != b.first)
            return a.first < b.first;
        return a.second < b.second;
         });
    int start, finish;
    start = v[0].first;
    finish = v[0].second;
    FOR (i, 1, m, 1) {
        if (finish <= v[i].first) {
            start = v[i].first;
            finish = v[i].second;
            nrfin++;
        }
        else
            start = max(start, v[i].first),
            finish = min(finish, v[i].second);
    }
    nrfin++;
    cout << nrfin << '\n';
}

Measured memory_bytes: 1024
n = int(input())
s = [input()for _ in range(n)]

for i in range(n):
    s[i] = ''.join(sorted(s[i]))

s.sort()

ans = 0
count = 0

for i in range(1, n):
    if count == 0:
        if s[i] == s[i-1]:
            count = 2
    else:
        if s[i] == s[i-1]:
            count += 1
        else:
            ans += count * (count - 1) // 2
            count = 0

ans += count * (count - 1) // 2

print(ans)

Measured memory_bytes: 10584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
bool check(string s)
{
    for(int i = 1; i < s.size(); i++)
        if(s[i] != s[i - 1])
            return 0;
    return 1;
}
int res = maxn;
//rffffffffffffffff
int main()
{
    string s;
    cin >> s;
    for(int i = 'a'; i <= 'z'; i++)
    {
        string s1 = s;
        while(!check(s1))
        {
            string s2;
            for(int j = 0; j < s1.size() - 1; j++)
            {
                if(s1[j] == i || s1[j + 1] == i)
                    s2 += (char)i;
                else
                    s2 += s1[j];
            }
            s1 = s2;
        }
        res = min(res , (int)s.size() - (int)s1.size());
    }
    cout << res;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    rep(i, n) cin >> a[i];
    int b[100010];
    rep(i, n) b[a[i]] = i + 1;
    REP(i, 1, n) {
        if(i != 1) cout << " ";
        cout << b[i];
    }
    cout << endl;



    return 0;
}


Measured memory_bytes: 4340
import sys

X="X"
N="0123456789"
for s0 in sys.stdin:
  s=s0[:-1]
  i=s.find("+")
  j=s.find("=")
  x=[s[:i],s[i+1:j],s[j+1:]]
  f=0
  for e in x:
    if e[0]==X and len(e)>1: f=1; break
  a="NA"
  for c in N[f:]:
    b=s.replace(X,c)
    if eval(b[:j])==eval(b[j+1:]): a=c; break
  print a

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

int gcd(int a,int b,int c){
    int result=0;
    int min=a;

    //search min 
    if(a>b){
        min=b;
    }
    if(min>c){
        min=c;
    }

    for(int x=1;x<=min;x++){
        if(a%x==0 &&b%x==0 && c%x==0){
            result=x;
        }
    }

    return result;
}


int main(){
    int k;
    cin >> k;
    unsigned int sum=0;

    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int L=1;L<=k;L++){
                sum = sum + gcd(i,j,L);
            }

        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define N 200050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
using namespace std;
int x,y,a,b,c;
int rap[N],gap[N],cap[N];
vector< int > ar;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;i++)
        cin>>rap[i];
    for(int i=0;i<b;i++)
        cin>>gap[i];
    for(int i=0;i<c;i++)
        cin>>cap[i];
    sort(rap,rap+a); sort(gap,gap+b); sort(cap,cap+c);
    reverse(rap,rap+a); reverse(gap,gap+b); reverse(cap,cap+c);
    for(int i=0;i<x;i++)
        ar.pb(rap[i]);
    for(int i=0;i<y;i++)
        ar.pb(gap[i]);
    sort(all(ar));
    int sum = 0;
    for(int i=0;i<sz(ar);i++)
        sum += ar[i];
    int cur =0;
    int g =0;
    int ans = sum;
    for(int i=0;i<sz(ar);i++){
        if(i>=c)break;
        g -= ar[i];
        g += cap[i];
        ans= max(ans , sum +g);
    }
    cout<<ans;
        return 0;
}


Measured memory_bytes: 5748
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from heapq import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l) + 1
	d = dict(Counter(l))
	for i in range(1,n+1):
		if(i in d):
			print(d[i])
		else:
			print(0)

	

N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)



Measured memory_bytes: 166676
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力

n,m,x,y = map(int, input().split())
xlist = [int(i) for i in input().split()]
ylist = [int(i) for i in input().split()]
#for num in range(1,m):
#    ylist+=[int(input())]

xlist.append(x)
ylist.append(y)

maxnum=max(xlist)
minnum=min(ylist)
# for num in range(0,n):
    #print("{}".format(xlist[num]))
# for num in range(0,m):
    #print("{}".format(ylist[num]))
#print("{} {}".format(a+b+c, s))
if maxnum<minnum:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main() {
	long long n,d,cnt=0;
	vector<long long> a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d;
		a.push_back(d);
	}

	for (int i = 0; i < n; i++) {
		cnt += a[i] / 2;
		if (i != n - 1) {
			if (a[i] % 2 == 1) {
				if (a[i + 1] > 0) {
					cnt++;
					a[i + 1]--;
				}
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;


int main(){
    int n;
    cin >> n;
    if(n < 0 || n > 100) return -1;
    int a[n];
    for(int i =0 ;i < n ; i++){
        cin >> a[i];
    }

//    output
    for(int i = 0; i < n-1 ; i ++){
        cout << a[n-i-1] << " ";
    }
    cout << a[0];
    cout << endl;

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> fees(4);
  for (int i = 0; i < 4; i++) {cin >> fees.at(i);}
  int ans = 0;
  ans += min(fees.at(0), fees.at(1));
  ans += min(fees.at(2), fees.at(3));
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	if len(res)==0:
		res = [n]
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	data = [2]
	#data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	ans = [x for x in data if x!=0]
	#ans = data[:]
	return ans

n = readInt()
a = readInts()
a.sort()

#max_a = 10**6
max_a = a[-1]
ans = [0]*(max_a+1)

for i in a:
	if ans[i]!=2:
		ans[i]+=1
for i in set(a):
	if ans[i]<=2:
		for j in range(i*2,len(ans),i):
			ans[j]=3

print(ans.count(1))

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B;
    cin >> A >> B;
    
    if(A >= 13){
        cout << B << endl; 
    }else if(A < 13 && A >= 6){
        cout << B / 2 << endl;
    }else{
        cout << 0 << endl;
    }


}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  long N, M;
  cin >> N >> M;

  long minL = 0;
  long maxR = N+1;

  rep (i, M) {
    long L, R;
    cin >> L >> R;
    minL = max(minL, L);
    maxR = min(maxR, R);
  }

  cout << max(0l, (maxR - minL + 1)) << endl;

  return 0;
}


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

#define INF 9000000000000;
#define int long long
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;

class SegmentTree {
private:
	int n;
	vector<int> node;
public:
	SegmentTree (vector<int> v) {
		int sz = v.size();
		n = 1;while(n < sz) n *= 2;
		node.resize(2*n-1, -1);
		for (int i = 0;i < sz;i++) {node[i+n-1] = v[i];}
		for (int i = n-2;i >= 0;i--) node[i] = max(node[2*i+1], node[2*i+2]);
	}

	int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		//要求区間と対象区間が交わらない
		if (r <= a || b <= l) return -1;
		//要求区間と対象区間を完全に被覆
		if (a <= l && r <= b) return node[k];
		int vl = getmax(a,b,2*k+1,l,(l+r)/2);
		int vr = getmax(a,b,2*k+2,(l+r)/2,r);
		return max(vl,vr);
	}
};

signed main() {
	int a[5];
	int k;
	REP (i,5) cin >> a[i];
	cin >> k;
	REP (i,5) {
		REP (j,5) {
			if (a[j] - a[i] > k) {cout << ":(" << endl;return 0;}
		}
	}
	cout << "Yay!" << endl;
}

Measured memory_bytes: 256
package main

// https://atcoder.jp/contests/abc083/tasks/abc083_b

import (
	"fmt"
)

func main() {
	var n, a, b int

	//
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)

	var ans = 0

	for i := 1; i <= n; i++ {
		sum := 0
		for num := i; num > 0; num /= 10 {
			sum += num % 10
		}
		if sum >= a && sum <= b {
			ans += i
		}
	}
	fmt.Printf("%v\n", ans)
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
    int x,y;
    while(1){
        scanf("%d",&x);
        scanf("%d",&y);
        if(x==0&&y==0) break;
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                if(i==0||i==x-1||j==0||j==y-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<int> vec;
	for(int i=0;i<n*2;i++)
	{
		int x; cin>>x; vec.pb(x);
	}
	sort(vec.rbegin(),vec.rend());
	ld ans=0;
	for(int i=0;i<2*n;i++)
	{
		ans+=ld(vec[i])*ld(2*n-1-i)/ld(2*n-1);
	}
	cout<<fixed<<setprecision(15)<<ans<<'\n';
}


Measured memory_bytes: 1400
import java.util.*;
public class Main {
    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        new Main();
    }
    public Main() {
    	new B().doIt();
    }
    
    class B{
    	int m,p;
    	boolean[] prime;
    	int N;
    	void solve(){
    		ArrayList<Integer> pp = new ArrayList<Integer>();
    		for(int i=m+1;pp.size()<200&&i<N;i++)if(prime[i])pp.add(i);
    		ArrayList<Integer> list = new ArrayList<Integer>();
    		for(int i=0;i<pp.size();i++)for(int s=i;s>=0;s--)list.add(pp.get(i)+pp.get(s));
    		Collections.sort(list);
//    		System.out.println(list);
    		System.out.println(list.get(p-1));
    	}
    	
    	void doIt(){
    		N = 102000;
    		prime = new boolean[N];
    		Arrays.fill(prime, true);prime[0]=false;prime[1]=false;
    		for(int i=0;i<N;i++)if(prime[i])for(int s=i+i;s<N;s+=i)prime[s]=false;
    		while(in.hasNext()){
    			m = in.nextInt();
    			p = in.nextInt();
    			if(m+p==-2)break;
    			solve();
    		}
    	}
    }
    
}

Measured memory_bytes: 167404
n,a,b = gets.split.map(&:to_i)
if (a-b).abs%2 == 0
  puts ((a-b).abs)/2
else
  x = [([a,b].max)-1,n-([a,b].max)+1+((a-b).abs-1)/2].min
  y = [n-([a,b].min),([a,b].min)+((a-b).abs-1)/2].min
  puts [x,y].min
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  s += s;
  for(int i = 0; i < t.length(); ++i){
    int failed = 0;
    for(int q = 0; q < t.length(); ++q){
      if(s[i+q] != t[q]){
        failed = 1;
        break;
      }
    }
    if(failed == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
t = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
x,flag,ans,mod = [[t[0],t[0]]]+[[1,1] for _ in range(n-1)],True,1,10**9+7
if max(t)!=max(a): flag = False
for i in range(1,n):
	if t[i-1]<t[i]: x[i] = [t[i],t[i]]
	else: x[i][0] = t[i]
if x[-1][0]<a[-1]: flag = False
else:
	x[-1] = [a[-1],a[-1]]
	for i in range(n-2,0,-1):
		if a[i]>a[i+1]:
			if x[i][0]>=a[i]: x[i]=[a[i],a[i]]
			else: flag = False
		else:
			if x[i][0]>=a[i]: x[i][0]=a[i]
			else: pass
if flag:
	for i,j in x: ans = (ans*(i-j+1))%mod
else: ans = 0
print(ans)

Measured memory_bytes: 22432
require 'set'

N, M = gets.split.map(&:to_i)
ab_list = M.times.map { gets.split.map(&:to_i) }
$graph = Array.new(N).tap do |g|
  g.size.times { |i| g[i] = [] }
  ab_list.each do |(a, b)|
    g[a - 1].push(b - 1)
    g[b - 1].push(a - 1)
  end
end

def dfs(i, used = Set.new)
  used.add(i)
  return 1 if used.size == N
  count =
    $graph[i]
    .reject { |e| used.include?(e) }
    .map do |e|
      c = dfs(e, used)
      used.delete(e)
      c
    end.reduce(0, &:+)
  count
end

puts(dfs(0))


Measured memory_bytes: 1916
#include <stdio.h>
#include <string.h>
char m[5001][5001];
int p[3000][2];
int main()
{
  int n,h,i,j,x1,y1,x2,y2,dx,dy,s,ms;
  for(;;){
    scanf("%d",&n);
    if(n==0) break;
    memset(m,0,sizeof(m));
    memset(p,0,sizeof(p));
    for(h=0;h<n;h++){
      scanf("%d%d",&i,&j);
      m[i][j] = 1;
      p[h][0] = i;
      p[h][1] = j;
    }
    ms = 0;
    for(i=0;i<n-1;i++){
      for(j=i+1;j<n;j++){
	if((p[i][0]+p[i][1]+p[j][0]-p[j][1]) % 2 == 0
	   && (p[i][0]+p[i][1]-p[j][0]+p[j][1]) % 2 == 0
	   && (p[i][0]-p[i][1]+p[j][0]+p[j][1]) % 2 == 0
	   && (-p[i][0]+p[i][1]+p[j][0]+p[j][1]) % 2 == 0){
	  x1 = (p[i][0]+p[i][1]+p[j][0]-p[j][1]) / 2;
	  y1 = (-p[i][0]+p[i][1]+p[j][0]+p[j][1]) / 2; 
	  x2 = (p[i][0]-p[i][1]+p[j][0]+p[j][1]) / 2;
	  y2 = (p[i][0]+p[i][1]-p[j][0]+p[j][1]) / 2;
	  if(0<=x1 && x1<=5000 && 0<=y1 && y1<=5000
	     && 0<x2 && x2<=5000 && 0<=y2 && y2<=5000
	     && m[x1][y1] == 1 && m[x2][y2] == 1){
	    dx = x1 - p[i][0];
	    dy = y1 - p[i][1];
	    s = dx*dx + dy*dy;
	    if(ms<s) ms = s;
	  }
	}
      }
    }
    printf("%d\n",ms);
  }
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> P(N,0);
    for(int i=0;i<N;i++){
        cin>>P[i]
    ;}
    int min=N+1;
    int counter=0;
    for(int i=0;i<N;i++){
        if(min>P[i]){
            counter++;
            min=P[i];
        }
       
    ;} cout<<counter<<endl;
    return 0;
}  


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;
#define len(n) (int)n.length()
#define dump cout
#define pb push_back
#define ll long long

bool isStable(vector<int> orinum, vector<char> orist, vector<int> num, vector<char> st)
{
	vector<char> ar_orist[10];
	vector<char> ar_st[10];
	
	int n = orinum.size();
	for (int i = 0; i < n; i++) {
	    ar_orist[orinum[i]].pb(orist[i]);
		ar_st[num[i]].pb(st[i]);
	}
	
	for (int i = 0; i < 10; i++) {
	    if (ar_orist[i].size() > 0)
		{
			for (int k = 0; k < ar_orist[i].size(); k++) {
			    if (ar_orist[i][k] != ar_st[i][k])
				{
					return false;
				}
			}
			
		}
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	vector<char> s;
	vector<int> num;
	for (int i = 0; i < n; i++) {
	    string tmp;
		cin >> tmp;
		s.pb(tmp[0]); num.pb(atoi(&tmp[1]));
	}

	// bubble	
	vector<char> sb(s);
	vector<int> numb(num);
	
	bool flag = true;
	for (int k = 0; flag; k++) {
		flag = false;
		for (int i = n-1; i >= k+1; i--) {

			if (numb[i] < numb[i-1])
			{
				flag = true;
				int tmp = numb[i];
				numb[i] = numb[i-1];
				numb[i-1] = tmp;
				
				char stmp = sb[i];
				sb[i] = sb[i-1];
				sb[i-1] = stmp;
			}
		}
	}

	
	// select	
	vector<char> ss(s);
	vector<int> nums(num);
	
	for (int i = 0; i < n; i++) {
		int min_i = i;
	    for (int k = i; k < n; k++) {
	        if(nums[min_i] > nums[k])
			{
				min_i = k;
			}
	    }
		int tmp = nums[min_i];
		nums[min_i] = nums[i];
		nums[i] = tmp;
		
		char stmp = ss[min_i];
		ss[min_i] = ss[i];
		ss[i] = stmp;
	    
	}
	
	for (int i = 0; i < n-1; i++) {
	    cout << sb[i] << numb[i] << " ";
	}
	cout << sb[n-1] << numb[n-1] << endl;
	cout << (isStable(num, s, numb, sb) ? "Stable" : "Not stable") << endl;
	
	for (int i = 0; i < n-1; i++) {
	    cout << ss[i] << nums[i] << " ";
	}
	cout << ss[n-1] << nums[n-1] << endl;
	cout << (isStable(num, s, nums, ss) ? "Stable" : "Not stable") << endl;

	
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // 2 3 5 7 11 13 17 19 23 29 31 37
    vector<int> primenum(11,1);
    vector<int> prime={2,3,5,7,11,13,17,19,23,29,31};
    vector<int> otnum;
    vector<int> otprime;
    int num;
    cin>>num;
    while(num>1){
        int tmp=num;
        for(int i=0;i<11;i++){
            while(1){
                if(tmp%prime[i]!=0){
                    break;
                }else{
                    primenum[i]++;
                    tmp/=prime[i];
                }
            }
        }
        if(tmp!=1){
            auto result=find(otprime.begin(),otprime.end(),tmp);
            if(result==otprime.end()){
                otprime.push_back(tmp);
                otnum.push_back(1);
            }else{
                otnum[result-otprime.begin()]++;
            }
        }
        num--;
    }
    long long int ans=1;
    for(int i=0;i<11;i++){
       // cout<<prime[i]<<":"<<primenum[i]<<endl;
        ans*=primenum[i];
        ans%=1000000007;
        
    }
    for(auto i:otnum){
        ans*=i+1;
        ans%=1000000007;
        //cout<<i<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
//
int main(){
  long long K;
  long long A[100000];
  cin>>K;
  FOR(i,0,K){
    cin>>A[i];
  }
  long long L=2,R=2;
  ROF(i,0,K){
    if(R/A[i]-(L-1)/A[i]==0){
      cout<<-1<<endl;
      return 0;
    }
    L=((L+A[i]-1)/A[i])*A[i];
    R=(R/A[i])*A[i]+A[i]-1;
  }
  cout<<L<<" "<<R<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
#define N 100005
#define ll long long
#define MOD 1000000007
ll x,y;
map<ll,bool> vis;
ll p[N];
int pn;
vector<ll>st;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
void sieve(ll n)
{
	for(ll i=2;i<=n;i++)
	{
		if(!vis[i])
			p[++pn]=i;
		for(int j=1;j<=pn&&p[j]*i<=n;j++)
		{
			vis[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}
bool is_prime(ll x)
{
	if(x==1) return 0;
	if(x==2||x==3) return 1;
	if(x%6!=1&&x%6!=5) return 0;
	int s=sqrt(x);
	for(int i=5;i<=s;i+=6)
		if(x%i==0||x%(i+2)==0)
			return 0;
	return 1;
}
int solve(ll n)
{
	int ans=1;
	if(n==1) return 1;
	ll i=0;
	while(i<n)
	{
		if(is_prime(n))
		{
			st.push_back(n);
			if(vis[n]==0)ans++;
			vis[n]=1;
			return ans;
		}
		for(int i=2;i<n;i++)
		{
			if(n%i==0)
			{
				st.push_back(i);
				if(vis[i]==0)ans++;
				vis[i]=1;
				n/=i;
				break;
			}
		}
	}
	st.push_back(n);
	if(vis[n]==0)ans++;
	vis[n]=1;
	return ans;
}
int main()
{
	scanf("%lld %lld",&x,&y);
	ll d=gcd(x,y);
	//printf("%lld\n",gcd(max(x,y),min(x,y)));
	//printf("%lld\n",d);
	//sieve(d);
	/*if(d%2==0) ans++;
	while(d%2==0)
		d/=2;
	for(int i=3;i*i<=d;i+=2)
		if(d%i==0)
		{
			ans++;
			while(d%i==0)
				d/=i;
		}
	if(d!=1) ans++;*/
	//for(int i=1;i<=pn;i++)
	//	if(d%p[i]==0) ans++;
	printf("%d\n",solve(d));
	return 0;
}

Measured memory_bytes: 256
local s = io.read("*n")
local t = {}
t[s] = 1
local p = 1
local cur = s
while true do
  p = p + 1
  local nxt = cur % 2 == 0 and cur // 2 or 3 * cur + 1
  if t[nxt] then
    print(p)
    break
  else
    t[nxt] = p
  end
  cur = nxt
end


Measured memory_bytes: 888
n, m = map(int, input().split())
needs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
usable = {}
for a in map(int, input().split()):
    na = needs[a]
    if na in usable:
        usable[na] = max(usable[na], a)
    else:
        usable[na] = a
use_keys = sorted(usable.keys())

dp = [-9] * (n + 1)
dp[0] = 0
for d in range(2, min(8, n + 1)):
    for u in use_keys:
        du = d - u
        if du < 0:
            break
        dp[d] = max(dp[d], dp[du] + 1)
for d in range(8, n + 1):
    for u in use_keys:
        dp[d] = max(dp[d], dp[d - u] + 1)

ans = ''
remain = n
rk = [(str(a), needs[a]) for a in sorted(usable.values(), reverse=True)]
for d in range(dp[n] - 1, -1, -1):
    for a, na in rk:
        ra = remain - na
        if ra < 0:
            continue
        if dp[ra] == d:
            ans += a
            remain = ra
            break

print(ans)


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

int dp[30][20][200];
int main() {
	int N, K, S;
	while (scanf("%d%d%d", &N, &K, &S), N) {
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i <= N; i++)dp[i][0][0] = 1;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 0; k <= S; k++) {
					if (k < i)dp[i][j][k] = dp[i - 1][j][k];
					else dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - i];
				}
			}
		}
		printf("%d\n", dp[N][K][S]);
	}
}

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

using namespace std;

void Main() {
    int X, A, B;
    cin >> X >> A >> B;
    if (B - A <= 0) {
        cout << "delicious" << endl;
    }
    else if (B - A <= X) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int ans = 200;
    for (char i = 'a'; i <= 'z'; i++) {
        int t = -1, cnt = 0;
        for (int j = 0; j < s.size(); j++) {
            if (s[j] == i) {
                t = max(t, cnt);
                cnt = 0;
            }
            else cnt++;
        }
        t = max(t, cnt);
        ans = min(ans, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n, *A = map(int, open(0).read().split())

a0 = Counter(A[::2]).most_common(2)
a1 = Counter(A[1::2]).most_common(2)

count = n
if a0[0][0] == a1[0][0]:
    if len(a0) == len(a1) == 1:
        count -= n//2
    elif len(a0) < len(a1):
        count -= n//2 - a1[1][1]
    elif len(a0) > len(a1):
        count -= n//2 - a0[1][1]
    else:
        count -= max(a0[1][1] + a1[0][1], a0[0][1] + a1[1][1])
else:
    count -= a0[0][1] + a1[0][1]
print(count)


Measured memory_bytes: 15528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n){
      cin>>a[i];
      sum+=a[i];
    }
    vector<ll> ret=divisor(sum);
    sort(begin(ret),end(ret),greater<ll>());
    rep(i,len(ret)){
      ll now=ret[i];
      if(now==1){
        cout<<now<<endl;
        return 0;
      }
      vector<ll> cnt;
      rep(j,n){
        if(a[j]%now==0) continue;
        cnt.push_back(a[j]%now);
      }
      sort(begin(cnt),end(cnt));
      ll m=len(cnt);
      //cout<<now<<endl;
      vector<ll> l(m,0);
      l[0]=cnt[0];
      FOR(j,1,m){
        l[j]=l[j-1]+cnt[j];
      }
      //cout_vec(l);
      rep(j,m){
        if(l[j]==(now*(m-1-j)-(l[m-1]-l[j]))&&l[j]<=k){
          cout<<now<<endl;
          return 0;
        }
      }
    }
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

D = defaultdict(int)
for a in A:
    D[a] += 1

ans_base = 0
for v in D.values():
    ans_base += v * (v - 1) // 2

for a in A:
    if D[a] > 1:
        print(ans_base - (D[a] * (D[a] - 1) // 2) + ((D[a] - 1) * (D[a] - 2) // 2))
    else:
        print(ans_base)


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

vector<vi> st;
void build(vi& v, int id, int l, int r) {
	if (l == r) st[id] = {v[l]};
	else {
		int mid = avg(l, r);
		build(v, id << 1, l, mid);
		build(v, id << 1 | 1, mid + 1, r);
		st[id].resize(r - l + 1);
		merge(iter(st[id << 1]), iter(st[id << 1 | 1]), st[id].begin());
	}
}
void init(vi& v) {
	int n = v.size();
	st.resize(4 * n + 10);
	build(v, 1, 0, n - 1);
}

int query(int id, int l, int r, int a, int b, int val) {
	if (r < a or l > b) return 0;
	if (a <= l and r <= b) {
		return lower_bound(iter(st[id]), val) - st[id].begin();
	}
	int mid = avg(l, r);
	return query(id << 1, l, mid, a, b, val) + query(id << 1 | 1, mid + 1, r, a, b, val);
}

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

	int n, q;
	cin >> n >> q;
	vi c(n), last(n + 1, -1), a(n);
	loop(n) {
		cin >> c[i];
		a[i] = last[c[i]];
		last[c[i]] = i;
	}
	init(a);
	int l, r;
	loop(q) {
		cin >> l >> r;
		cout << query(1, 0, n - 1, l - 1, r - 1, l - 1) << endl;
	}
	return 0;
}



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

using namespace std;

#define inf 1ll<<60
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;


int main(){
	int n, k;
	cin >> n >> k;
	vector<llong> ki;
	for(int i = 0; i < n; i++){
		llong in;
		cin >> in;
		ki.pb(in);
	}

	sort(ki.begin(), ki.end());
	llong ans = inf;
	for(int i = 0; i < ki.size()-k+1; i++){
		// cout << ki[i] << " " << ki[i+k-1] << endl;
		ans = min(ans, ki[i+k-1] - ki[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

const ll MOD = 1e9 + 7;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}


void __sol(){
    ll n; cin >>n;
    vector<int> v;
  //  n--;
    while(n>0){
        n--;
        v.eb(n%26);
        n/=26;
    }
    reverse(all(v));
    for(auto &i:v) cout << char('a'+i) ;
}


int main(){
    fastio
    ll tc=1;// cin >> tc;
    while(tc--) __sol();
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

    int N;		cin >> N;
  	V B(N - 1);		VECCIN(B);
  	int ans = B[0];
  	for(int i = 1 ; i < N - 1 ; i++)
      	ans += min(B[i - 1] , B[i]);

  	ans += B[N - 2];
  	SCOUT(ans) << endl;
  
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int a,b,c,d,i,j,k;
int req[20005],up[20005],down[20005],target[20005];
int main(){
	scanf("%d",&a);
	for (i=1;i<=a;i++) {
		scanf("%d",&c);
		req[c]=i;
	}
	for (i=1;i<=a;i++) target[i]=1000000000-a+req[i];
	up[1]=1;
	down[1]=target[1]-up[1];
	for (i=2;i<=a;i++){
		down[i]=down[i-1]-1;
		up[i]=target[i]-down[i];
		if (up[i]<=up[i-1]){
			c=up[i-1]-up[i]+1;
			up[i]+=c;
			down[i]-=c;
		}
	}
	for (i=1;i<=a-1;i++)  printf("%d ",up[i]);
	printf("%d\n",up[a]);
	for (i=1;i<=a-1;i++)  printf("%d ",down[i]);
	printf("%d\n",down[a]);
}

Measured memory_bytes: 896
n = int(input())
a = list(map(int, input().split()))
print(' '.join(map(str, a)))
for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
    print(' '.join(map(str, a)))


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

int main(){

    int a, b, c, d, i;
    d = 0;

    cin >> a >> b;

    if(b>9){
        if(b==100){
            c = a*1000 + b;
            for(i = 1; i <318; i++){
            if(i*i==c){
                d = 1;
            }
        }
        }
        else{
             c = a*100 + b;
            for(i = 1; i <318; i++){
            if(i*i==c){
                d = 1;
            }
        }
        }
    }
    else{
        c = a*10 + b;
        for(i = 1; i <318; i++){
            if(i*i==c){
                d = 1;
            }
        }
    }
    if(d==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int d=-2000000000;
	for(int i=0; i<n; i++)  cin>>a[i];
	int mi=a[0];
	for(int i=1; i<n; i++){
	    d=max(a[i]-mi, d);
	    if(mi>a[i]) mi=a[i];
	}
	cout<<d<<endl;
	return 0;
}


Measured memory_bytes: 3868
import java.util.Scanner

import scala.collection.mutable

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */
object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val M = sc.nextInt

  val valCountMap = mutable.Map[Int, Int]().withDefaultValue(0)
  val modValMap = Array.fill(M)(mutable.Set[Int]())
  val modCountMap = Array.fill(M)(0)

  for(i <- 0 until N) {
    val n = sc.nextInt
    val m = n % M
    valCountMap.+=((n, valCountMap(n) + 1))
    modValMap(m).+=(n)
    modCountMap(m) += 1
  }

  var count = modCountMap(0) / 2
  for(i <- 1 to ((M - 1) / 2)) {
    val j = M - i
    val (sId, lId) = if(modCountMap(i) < modCountMap(j)) {
      (i, j)
    } else {
      (j, i)
    }

    val countDif = modCountMap(lId) - modCountMap(sId)
    val maxPairNum = countDif / 2

    val pairNum = modValMap(lId).foldLeft(0){case(s, x) => s + valCountMap(x) / 2}

    count += modCountMap(sId) + math.min(maxPairNum, pairNum)
  }

  if(M % 2 == 0) count += modCountMap(M / 2) / 2

  println(count)
}

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

const int MAXH = 800;
const int MAXW = 800;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

template< class T1, class T2 >
int upmin( T1 &x, T2 v ) {
  if( x <= v ) return 0;
  x = v;
  return 1;
}

int H, W, K;
string G[ MAXH ];
int sx, sy;
int dp[ MAXH ][ MAXW ];

signed main() {
  ios::sync_with_stdio( 0 );
  cin >> H >> W >> K;
  for( int i = 0; i < H; ++i ) {
    cin >> G[ i ];
    for( int j = 0; j < W; ++j ) {
      if( G[ i ][ j ] == 'S' ) {
        sx = i;
        sy = j;
      }
    }
  }
  memset( dp, 0x3f, sizeof( dp ) );
  dp[ sx ][ sy ] = 0;
  queue< pair< int, int > > que;
  que.emplace( sx, sy );
  while( not que.empty() ) {
    int x, y;
    tie( x, y ) = que.front();
    que.pop();
    if( dp[ x ][ y ] == K ) break;
    for( int di = 0; di < 4; ++di ) {
      int nx = x + dx[ di ];
      int ny = y + dy[ di ];
      if( not ( 0 <= nx and nx < H and 0 <= ny and ny < W ) ) continue;
      if( G[ nx ][ ny ] == '#' ) continue;
      if( upmin( dp[ nx ][ ny ], dp[ x ][ y ] + 1 ) ) {
        que.emplace( nx, ny );
      }
    }
  }
  int ans = H;
  for( int i = 0; i < H; ++i ) {
    for( int j = 0; j < W; ++j ) {
      if( dp[ i ][ j ] <= K ) {
        ans = min( ans, min( { ( i + K - 1 ) / K, ( j + K - 1 ) / K, ( H - 1 - i + K - 1 ) / K, ( W - 1 - j + K - 1 ) / K } ) + 1 );
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    static const double pi = 3.141592653589793238;
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double zi,hun;
    zi = (M_PI*(h+(m/60)))/6;
    hun = (m*M_PI)/30;
    double rad = zi-hun;
    if(rad>M_PI){
        rad = 2*M_PI - rad; 
    }
    double ans;
    ans = (a*a)+(b*b)-2*a*b*cos(rad);
    double c = sqrt(ans);
    printf("%.10f",c);
    return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<char>> g (n + 1, vector<char>(m + 1));
    vector<vector<int>> h(n + 1, vector<int>(m + 1));
    vector<vector<int>> v(n + 1, vector<int>(m + 1));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            cin >> g[i][j];
    for(int i = 0; i < n; ++i) {
        int r = 0;
        for(int j = 0; j < m; ++j) {
            if(g[i][j] == '#') r = 0;
            else r++;
            h[i][j] = r;
        }
    }
    for(int j = 0; j < m; ++j) {
        int r = 0;
        for(int i = 0; i < n; ++i) {
            if(g[i][j] == '#') r = 0;
            else r++;
            v[i][j] = r;
        }
    }

    int ans = 0;
    for(int i = n - 1; i >= 0; --i) {
        for(int j = m - 1; j >= 0; --j) {
            if(v[i][j])
                v[i][j] = max(v[i][j], v[i + 1][j]);
            if(h[i][j])
                h[i][j] = max(h[i][j], h[i][j + 1]);
            ans = max(ans, h[i][j] + v[i][j] - 1);
        }
    }
    cout << ans << '\n';

}

Measured memory_bytes: 35712
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll x1,x2,x3,x4,x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;

    if (x1 == 0) cout << 1 << endl;
    else if (x2 == 0) cout << 2 << endl;
    else if (x3 == 0) cout << 3 << endl;
    else if (x4 == 0) cout << 4 << endl;
    else if (x5 == 0) cout << 5 << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int h,n; cin >> h >> n;
    int sum = 0;
    rep(i,n){int t; cin >> t; sum +=t;}
    if(h > sum) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256