akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      push(i,&st1);// 位置 i を st1 にプッシュ(write your code)
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
    	int j=pop(&st1);
    	sum+=i-j;// 水たまりの総水量 sum を更新(write your code)
      // ここからは(?) st2_j と st2_a を用いて水たまりの水量を更新 
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        a+=pop(&st2_a);
      	pop(&st2_j);// 水たまりの水量を求めていく (write your code)
      }
      push(j,&st2_j);
    	push(a,&st2_a);// 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}




Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N = 0,K = 0;
    cin >> N >> K;

    int fruit[N];

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

    sort(fruit, fruit + N);

    int ans=0;
    for(int i =0;i<K;i++){
        ans+=fruit[i];
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
int dp[1000005];
void init(){
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=1000004;i++){
		for(int j=1;j*i<=1000004;j++){
			dp[i*j]+=1;
		}
	}
}
void solve(){
	ll n;cin>>n;
	init();
	int ans=0;
	for(int i=1;i<=n-1;i++){
		int x=n-i;
		ans+=dp[x];
	}
	cout<<ans;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

Measured memory_bytes: 11416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		if(X==7 || X==5 || X==3) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21716
#include <cstdio>
using namespace std;
int n;
long long bits[60];
const int MOD=1000000007;
int main(){
    scanf("%d",&n);
    long long ans=0;
    long long temp;
    for (int x=0;x<n;x++){
        scanf("%lld",&temp);
        
        for (int y=0;y<60;y++){
            if (temp&1){
                ans+=(1LL<<y)%MOD*(x-bits[y])%MOD;
                bits[y]++;
            }
            else{
                ans+=(1LL<<y)%MOD*bits[y]%MOD;
            }
            ans%=MOD;
            temp>>=1;
        }
    }
    
    printf("%d\n",ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> sub(n+1);
    for (int i = 2; i <= n; i++) {
        int boss;
        cin >> boss;
        sub[boss]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << sub[i] << "\n";
    }
}

Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[110][100010];

int main(){
  ll N,W; cin >> N >> W;
  vector<ll> w(N); vector<ll> v(N);
  for(ll i = 0; i < N; i++){
    cin >> w[i] >> v[i];}
  
  for(ll j = 0; j < 110; j++){
    for(ll k = 0; k < 100010; k++){
      dp[j][k] = 0;}} //初期化
  
  for(ll i = 0; i < N; i++){
    for(ll sum_w = 0; sum_w <= W; sum_w++){
      
     if( sum_w >= w[i]){
    dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w - w[i]] + v[i]);}
    dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w]); }}
  
  cout << dp[N][W] << endl;
  return 0;}
                         
                         
      
  
  


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

int checkNum( int i );

int main( void )
{
  int N;
  cin >> N;
  int count = 0;

  for( int i = 1; i <= N; i++ ) {
    count += checkNum( i );
  }

  cout << count << endl;
}

int checkNum( int i )
{
  int count = 0;
  
  if( i % 2 == 0 ) {
    return 0;
  }

  for( int j = 1; j <= i; j++ ) {
    if( i % j == 0 )
      count++;
  }
  
  if( count == 8 )
    return 1;
  else
    return 0;
}
    

Measured memory_bytes: 3596
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <bitset>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    bitset<3> b;
    int num = 0;
    string ans = "";
    for (int i=0; i<8; ++i){
        b = static_cast<bitset<3>>(i);
        num = s[0] - '0';
        for (int j=0; j<3; ++j){
            if(b[j] == 0){
                num += s[j+1] - '0';
            }
            else {
                num -= s[j+1] - '0';
            }
        }
        if(num == 7){
            ans += s[0];
            ans += (b[0]) ? "-" : "+";
            ans += s[1];
            ans += (b[1]) ? "-" : "+";
            ans += s[2];
            ans += (b[2]) ? "-" : "+";
            ans += s[3];
            ans += "=7";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from functools import reduce
import math
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return (gcd(y, x%y))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr

def ans(n, a):
    div = {}
    for i in range(n):
        k = (factorization(a[i]))
        for j in k:
            if j==1:
                pass
            elif j not in div:
                div[j]=1
            else:
                return True
    return False
    

n = int(input())
a = list(map(int, input().split()))
gcd = reduce(math.gcd, a)
if gcd !=1:
    print("not coprime")
else:
    if ans(n, a):
        print("setwise coprime")
    else:
        print("pairwise coprime")


Measured memory_bytes: 183552
#!python3

LI = lambda: list(map(int, input().split()))

# input
x, y = LI()


def group(num):
    if num == 2:
        return 0
    if num in {4, 6, 9, 11}:
        return 1
    return 2


def main():
    if group(x) == group(y):
        ans = "Yes"
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
package main

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

func main() {
	nm := nextIntArray()
	n, m := nm[0], nm[1]
	state := make([][]int, n)
	for i := 0; i < n; i++ {
		state[i] = []int{}
	}
	input := make([][]int, m)
	for i := 0; i < m; i++ {
		py := nextIntArray()
		input[i] = py
		state[py[0]-1] = append(state[py[0]-1], py[1])
	}
	for i := 0; i < n; i++ {
		sort.Ints(state[i])
	}
	smap := make([]map[int]int, n)
	for i := 0; i < n; i++ {
		smap[i] = map[int]int{}
		for k, v := range state[i] {
			smap[i][v] = k + 1
		}
	}

	for i := 0; i < m; i++ {
		p, y := input[i][0], input[i][1]
		fmt.Printf("%06d%06d\n", p, smap[p-1][y])
	}
}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 32768
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int add[200000+10];
int n;
int q;
int ans[200000+10];
vector<int> each[200000+10];
void dfs(int now,int las,int ADD){
	ADD+=add[now];
	ans[now]=ADD;
	int SZ=each[now].size();
	rep(i,SZ){
		int to=each[now][i];
		if(to!=las){
			dfs(to,now,ADD);
		}
	}
}
int main(){
	scanf("%d %d",&n,&q);
	rb(i,1,n-1){
		int ai,bi;
	scanf("%d %d",&ai,&bi);
	each[ai].PB(bi),each[bi].PB(ai);
	}
	rb(i,1,q){
		int pi,xi;
		scanf("%d %d",&pi,&xi);
		add[pi]+=xi;
	}
	dfs(1,INF,0);
	rb(i,1,n){
		printf("%d ",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 27264
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int n,w,z;

  cin >> n >> w >> z;

  if ( n == 1 ) {
    int tmp;
    scanf("%d", &tmp);

    cout << abs(tmp-z) << "\n";
  } else {
    int tmp1,tmp2;
    for ( int i = 0; i < n-2; ++i ) scanf("%d", &tmp1);
    scanf("%d%d", &tmp1, &tmp2);

    cout << ( abs(tmp2-z) > abs(tmp2-tmp1) ? abs(tmp2-z) : abs(tmp2-tmp1) )<< "\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll fact(ll n){
	if(n == 0) return 1;
	return n * fact(n - 1) % MOD;
}

int main(){
	ll n,m;
	cin >> n >> m;
	if(abs(n - m) > 1) cout << 0 << endl;
	else if(abs(n - m) == 1) cout << fact(n) * fact(m) % MOD << endl;
	else cout << fact(n) * fact(m) * 2 % MOD << endl;
}

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

using namespace std;

int main(){
    int K,X;
    cin >> K >> X;
    if(X-K+1<-1000000){
        for(int a=-1000000;a<=X+K-1;a++){
            cout << a << " ";
        }
    }else if(X+K-1>1000000){
        for(int b=X-K+1;b<=1000000;b++){
            cout << b << " ";
        }
    }else{
        for(int c=X-K+1;c<X+K;c++){
            cout << c << " ";
        }
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];

    vector<int> ans; //A[i]がansの中で最小値以下 -> push_back(A[i])
                     //それ以外 -> ans未満のうち最大の色をにぶたん -> A[i]で書き換え
                     //ansは降順に並ぶ
    rep(i, N){
        if(i == 0) ans.push_back(A[i]);
        else{
            if(A[i] <= ans[ans.size()-1]) ans.push_back(A[i]);
            else{
                int val = A[i];
                if(val > ans[0]) ans[0] = val;
                else{
                    int ok = ans.size()-1, ng = 0;
                    int m = (ok+ng)/2;
                    //valより小さい最大の場所は? ans[ok+1] >= val > ans[ok]
                    while(abs(ok-ng) > 1){
                        if(val <= ans[m]){ //mは条件を満たさない
                            ng = m;
                        }
                        else ok = m;
                        m = (ok+ng)/2;
                    }
                    ans[ok] = val;
                }
            }
        }
    }
    cout << ans.size() << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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 gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int digitsum(int x) {
	int res = 0;
	while (x) {
		res += x % 10;
		x /= 10;
	}
	return res;
}
int main() { // 問題文はしっかり読め!!!
	int n;
	cin >> n;
	int ans = upper;
	rep1(i, n - 1) {
		int a = i, b = n - i;
		chmin(ans, digitsum(a) + digitsum(b));
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    vector<int>A(5);
    vector<pair<int,int>>a(5);
    int sub=0;
    for(int i=0;i<5;i++){
        cin>>A[i];
        a[i].second=A[i]+9-(A[i]+9)%10;
        a[i].first=(A[i]+9)%10;
        sub+=a[i].second;
    }
    sort(a.begin(),a.end());
    sub-=a[0].second;
    sub+=a[0].second-(10-a[0].first-1);
    cout<<sub<<endl;
}

Measured memory_bytes: 256
N,W,*l = map(int,open(0).read().split())
wl = l[::2]
vl = l[1::2]
M = N*max(vl)
INF = float("inf")
dp = [[INF]*(M+1) for _ in range(N+1)]
dp[0][0] = 0

# minimum weight with value == j
for i in range(N):
	w,v = wl[i],vl[i]
	for j in range(M+1):
		if j >= v:
			dp[i+1][j] = min(dp[i][j],dp[i][j-v]+w)
		else:
			dp[i+1][j] = dp[i][j]
		
# maximum value provided dp[N][value] <= W
ans=0
for val,wei in enumerate(dp[-1]):
	if wei <= W:
		ans = max(ans,val)
print(ans)

Measured memory_bytes: 311448
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007


using namespace std;

int main(){
	string S;
	cin >> S;
	for(int i = 0; i < S.size(); i++){
		cout << S[i];
		if(i == 3){
			cout << " ";
		}
	}
	cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		while(scan.hasNext()){
			double x1,y1,x2,y2,x3,y3,xp,yp;
			x1 = scan.nextDouble();
			y1 = scan.nextDouble();
			x2 = scan.nextDouble();
			y2 = scan.nextDouble();
			x3 = scan.nextDouble();
			y3 = scan.nextDouble();
			xp = scan.nextDouble();
			yp = scan.nextDouble();
			double z1=(x3 - x2)*(yp - y2) - (y3 - y2)*(xp - x2);
			double z2=(x1 - x3)*(yp - y3) - (y1 - y3)*(xp - x3);
			double z3=(x2 - x1)*(yp - y1) - (y2 - y1)*(xp - x1);
			if(z1>=0&&z2>=0&&z3>=0||z1<=0&&z2<=0&&z3<=0){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

//i???????????????????????????
bool getBit(int num, int i){
	return ((num & (1 << i)) != 0);
}

//i?????????1?????????
int setBit(int num, int i){
	return num | (1 << i);
}

//i?????????0?????????
int clearBit(int num, int i){
	int mask = ~(1 << i);
	return num & mask;
}

//i?????????v??§???????????????
int updateBit(int num, int i, int v){
	int mask = ~(1 << i);
	return (num & mask) | (v << i);
}


int connect(string a, string b){
	rep(i,a.size()){
		string a_sub = a.substr(i,min(a.size() - i, b.size()));
		string b_sub = b.substr(0,a_sub.size());
		if(a_sub == b_sub){
			return b.size() - b_sub.size();
		}
	}
	return b.size();
}

int main(){
	int n;
	while(cin >> n,n){
		vector<string> in(n);
		rep(i,n){ cin >> in[i]; }

		vector<string> str;
		rep(i,n){
			bool f = false;
			rep(j,n){
				if(i == j) continue;
				if(string::npos != in[j].find(in[i])){
					f = true;
				}
			}
			if(not f) str.emplace_back(in[i]);
		}


		int c[20][20];
		n = str.size();
		rep(i,n){
			rep(j,n){
				if(i == j) continue;
				c[i][j] = connect(str[i], str[j]);
			}
		}

		int dp[1 << 14][20];
		rep(i,1 << 14) rep(j,20) dp[i][j] = INF;
		rep(i,n) dp[setBit(0,i)][i] = str[i].size();
		//rep(i,1 << n){ rep(j,n){ cout << dp[i][j] << endl; } cout << endl; }

		rep(s, 1 << n){
			rep(i,n){
				if(not getBit(s,i)) continue;
				rep(j,n){
					if(getBit(s,j)) continue;
					//cout << i << ' ' << j << endl;
					//show(c[i][j])
					dp[setBit(s,j)][j] = min(dp[setBit(s,j)][j], dp[s][i] + c[i][j]);
				}
			}
		}
		//rep(i,1 << n){ rep(j,n){ cout << dp[i][j] << endl; } cout << endl; }

		int ans = INF;
		rep(i,n){
			ans = min(ans, dp[(1 << n) - 1][i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 4444
#include <cstdio>
#include <algorithm>
#define pi std::pair<int,int>
const int maxN = 5e5+9;
struct Query{
	int l,r,i;
}query[maxN];
int last[maxN],arr[maxN],BIT[maxN],ans[maxN];
void update(int index,int val,int n){
	while(index<=n){
		BIT[index]+=val;
		index+=(index&-index);
	}
}
int ask(int index){
	int ret=0;
	while(index>0){
		ret+=BIT[index];
		index-=(index&-index);
	}
	return ret;
}
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%d",&arr[i]);
	for(int i=0;i<q;i++){scanf("%d%d",&query[i].l,&query[i].r);query[i].i=i;}
	std::sort(query,query+q,[](Query &q1,Query &q2){ return (q1.r<q2.r);});
	int r=1;
	for(int i=0;i<q;i++){
		while(r<=query[i].r){
			if(last[arr[r]])update(last[arr[r]],-1,n);
			update(r,1,n);last[arr[r]]=r;r++;
		}
		ans[query[i].i] = ask(query[i].r) - ask(query[i].l-1);
	}
	
	for(int i=0;i<q;i++)printf("%d\n",ans[i]);
}


Measured memory_bytes: 17288
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n, m;
    cin>>n>>m;
    lli l=0,r=INF;
    rep(i,m){
        lli x,y;
        cin>>x>>y;
        l=max(l, x);
        r=min(y, r);
    }
    out((r-l+1<0?0:r-l+1));

}

Measured memory_bytes: 3556
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

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

    int n;
    int w;
    cin >> n >> w;
    vector<int> w_s(n);
    vector<int> v_s(n);
    rep(i, n)
    {
        cin >> w_s[i] >> v_s[i];
    }

    constexpr int vinf = 100'001;
    // [0,i)を使い価値j以上にする重さの最小値
    vector dp(n + 1, vector<int>(vinf, w + 1));
    dp[0][0] = 0;
    rep(i, n)
    {
        dp[i + 1] = dp[i];
        rep(j, vinf - v_s[i])
        {
            chmin(dp[i + 1][j + v_s[i]], dp[i][j] + w_s[i]);
        }
    }

    int ans = 0;
    rep(j, vinf)
    {
        if (dp[n][j] < w + 1)
        {
            ans = j;
        }
    }
    cout << ans << '\n';

    return 0;
}


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

int main() {

	int N;
	cin >> N;
	int result = N;

	bool warikireru = false;

	do {
		warikireru = false;
		for (int j = 2; j < N; j++) {

			if (N % j == 0) {
				warikireru = true;
			}
		}
		result = N;
		N++;
	} while (warikireru != false);

	cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a, b;
    ll sum=0;
    bool flag=true;
    a.push_back(sum);
    rep(i, n){
        ll x;
        cin >> x;
        sum += x;
        if(flag){
            if(sum<=k){
                a.push_back(sum);
            }else{
                flag=false;
            }
        }
    }
    sum=0;
    flag = true;
    b.push_back(sum);
    rep(i, m) {
      ll x;
      cin >> x;
      sum += x;
      if (flag) {
        if (sum <= k) {
            b.push_back(sum);
        } else {
            flag = false;
        }
      }
    }
    int maxim=0;
    for(int i=a.size()-1;i>=0;i--){
      ll rem = k - a[i];
      auto pos = upper_bound(b.begin(), b.end(), rem);
      int dis = distance(b.begin(), pos)-1;
      maxim = max(maxim, i+dis);
    }
    cout << maxim << endl;
    return 0;
}

Measured memory_bytes: 7824
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, M, ans = 0;
	cin >> N >> M;
	vector<pair<int, int>> AB(M);
	for (pair<int, int>& i : AB) cin >> i.first >> i.second;
	sort(AB.begin(), AB.end(), greater<pair<int, int>>());
	for (int i = 0; i < M - 1; ++i) ans += max(0, AB[i].second - N);
	cout << ans << endl;
}


Measured memory_bytes: 3084
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    return 'YES' if int(math.ceil(N/2)) >= K else 'NO'


def main():
    # N = read_int()
    N, K = read_int_n()
    # A = [read_int_n() for _ in range(N)]
    print(slv(N, K))


if __name__ == '__main__':
    main()


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

int main() {
    int N;
    int D,X;
    cin >> N;
    cin >> D >> X;
    int A[N];
    int sum = 0;
    for(int i=0;i<N;i++) cin >> A[i];
    //cout << A[0] <<"\n";
    for(int i=0;i<N;i++){
        int p = 1;
        int c = 0;

        while(p<=D){
            sum++;
            c=c+1;
            //cout <<p << " " << sum <<"\n";
            p = c*A[i] + 1;
            //cout << p <<"\n";

        }
    }
    sum  = sum + X;
    cout << sum <<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

struct Rank {
  std::map<size_t, size_t> memo;
  std::map<size_t, std::set<size_t>> const& parents;

  Rank(decltype(parents) const& p)
    : parents(p) {};

  size_t operator()(size_t node) {
    if (memo.count(node) > 0) {
      return memo.at(node);
    } else if (parents.count(node) > 0) {
      size_t ret = 0;
      auto const& ps = parents.at(node);
      for (auto p : ps) {
        ret = std::max(ret, (*this)(p)) + 1;
      }
      memo.insert(std::make_pair(node, ret));
      return ret;
    } else {
      return 0;
    }
  }
};

int main() {
  size_t N, M;

  std::cin >> N >> M;

  size_t const NumEdges = N - 1 + M;
  std::vector<std::pair<size_t, size_t>> Edgeds(NumEdges);
  std::map<size_t, std::set<size_t>> Parents;

  for (size_t i=0; i<NumEdges; i++) {
    size_t A, B;
    std::cin >> A >> B;
    A--; B--;
    Edgeds[i] = std::make_pair(A, B);
    if (Parents.count(B) > 0) {
      Parents.at(B).insert(A);
    } else {
      std::set<size_t> s;
      s.insert(A);
      Parents.insert(std::make_pair(B, s));
    }
  }

  Rank rank(Parents);

  for (size_t i=0; i<N; i++) {
    if (Parents.count(i) > 0) {
      auto const& ps = Parents.at(i);
      auto ans = *std::max_element(ps.begin(), ps.end(),
                                   [&](auto a, auto b){return rank(a) < rank(b);});
      std::cout << (ans + 1) << std::endl;
    } else {
      std::cout << 0 << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 27008
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 3000;
LL dp[2][N + 5][N + 5];
bool vis[2][N + 5][N + 5];
LL arr[N + 5];
int n;

LL solve(int one,int idx,int dpn) {
	if(idx == n) return 0;
	if(vis[one][idx][dpn] == true) return dp[one][idx][dpn];
	vis[one][idx][dpn] = 1;
	int blkg = n - 1 - (idx - dpn);
	if(one == 1) {
		dp[one][idx][dpn] = -1e18;
		dp[one][idx][dpn] = max(arr[dpn] - solve(!one, idx + 1,dpn + 1), arr[blkg] - solve(!one, idx + 1, dpn));
	}
	else {
		dp[one][idx][dpn] = 1e18;
		dp[one][idx][dpn] = max(arr[dpn] - solve(!one, idx + 1,dpn + 1), arr[blkg] - solve(!one, idx + 1, dpn));
	}
	return dp[one][idx][dpn];
}

void hora(int tc) {
	cin>>n;
	for(int i = 0;i < n;i++) cin>>arr[i];
	memset(vis,0,sizeof vis);
	cout<<solve(1,0,0)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 158720
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
 
int n;
int m;
vector<vi> G;

vector<set<int>> s;

vector<vi> idxs;

bool dfs(int i, int a, int b, int pa){
    if(a == b){
        return true;
    }
    for(auto& na : G[a]){
        if(na == pa){
            continue;
        }
        if(dfs(i, na, b, a)){
            s[idxs[a][na]].insert(i);
            return true;
        }
    }
    return false;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin >> n;
    G = vector<vi>(n);
    s = vector<set<int>>(n-1);
    idxs = vector<vi>(n, vi(n));

    rep(loop, n-1){
        int a, b; cin >> a >> b;
        a--, b--;
        idxs[a][b] = loop;
        idxs[b][a] = loop;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    cin >> m;
    rep(i, m){
        int a, b; cin >> a >> b;
        a--, b--;
        dfs(i, a, b, -1);
    }

    vector<vll> dp(n, vll(1 << m));
    dp[0][0] = 1LL;
    rep(i, n-1){
        rep(j, 1 << m){
            ll cur = dp[i][j];
            if(dp[i][j] == 0LL) continue;

            // not paint
            int nj = j;
            dp[i+1][nj] += cur;

            // paint
            for(int k : s[i]){
                nj |= (1 << k);
            }
            dp[i+1][nj] += cur;
        }
    }

    cout << dp[n-1].back() << endl;

    return 0;
}

Measured memory_bytes: 418304
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, A, B);
  int c = A + B;
  if (c > 9) {
    print("error");
  } else {
    print(c);
  }
}


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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define H(x) cout << #x << " " << x << endl;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

vvi grid;
int H, W;

signed main () {
    cin >> H >> W;
    grid.assign(H, vi(W, -1));
    queue<ii> frontier, nxt;
    FOR(i, 0, H) FOR(j, 0, W) {
        char c;
        cin >> c;
        if(c == '#') {
            grid[i][j] = 0;
            frontier.push( {i, j});
        }
    }
    int steps = 0;
    while(!frontier.empty()) {
        steps++;
        while(!frontier.empty()) {
            ii p = frontier.front(); frontier.pop();
            int i = p.fst, j = p.snd;
            if(i+1 < H && grid[i+1][j] == -1) {
                grid[i+1][j] = steps;
                nxt.push({i+1,j});
            }  
            if(i-1 >= 0 && grid[i-1][j] == -1) {
                grid[i-1][j] = steps;
                nxt.push({i-1,j});
            }  
            
            if(j+1 < W && grid[i][j+1] == -1) {
                grid[i][j+1] = steps;
                nxt.push({i,j+1});
            }  
            if(j-1 >= 0 && grid[i][j-1] == -1) {
                grid[i][j-1] = steps;
                nxt.push({i,j-1});
            }  
        }
        frontier.swap(nxt);
        while(!nxt.empty()) nxt.pop();
    }

  
    cout<<steps-1<<endl;
}

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 1e2 + 5;
ll a[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen("VLJUM.INP", "r")){
                freopen("VLJUM.INP", "r", stdin);
                freopen("VLJUM.OUT", "w", stdout);
        }
        ll n, m;
        cin >> n >> m;
        if (n <= m) {
                cout << min(n, m - n);
                return 0;
        } else {
                cout << min(n % m , m - (n % m));
        }
}
/*
*/


Measured memory_bytes: 256
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	var ans, z int
	for i := 0; i < n; i++ {
		d1, d2 := getNextInt(scanner), getNextInt(scanner)
		if d1 == d2 {
			z++
			if ans < z {
				ans = z
			}
			continue
		}
		z = 0
	}
	if ans >= 3 {
		fmt.Fprintln(writer, "Yes")
		return
	}
	fmt.Fprintln(writer, "No")
}


Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, ans;
int32_t main() {
    ans = 0;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }

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

	vector<uint32_t> v(n);
	v[0] = (uint32_t)1e5;
	uint32_t result = 0;

	for (size_t i = 1; i < v.size(); i++) {
		cin >> v[i];
		result += min(v[i], v[i - 1]);
	}
	result += v.back();
	printf("%d\n", result);

	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
ab = nan(n)
ab.sort()

ans = 0
cur = 0
for i in range(n):
    a, b = ab[i]
    cur += b
    if cur >= k:
        print(a)
        break


Measured memory_bytes: 27860
use std::io;

fn main() {
    let (a, b) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    if a <= 8 && b <= 8 {
        println!("Yay!");
    } else {
        println!(":(");
    }

}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
import java.util.*;

class Main{

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a * b % 2 == 0) System.out.println("Even");
        else System.out.println("Odd");
    }

}


Measured memory_bytes: 35616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        double x1,y1,x2,y2,x,y,s;
        x1=scan.nextDouble();
        y1=scan.nextDouble();
        x2=scan.nextDouble();
        y2=scan.nextDouble();
        x=x2-x1;
        y=y2-y1;
        s=Math.sqrt(x*x+y*y);
        System.out.println(s);
    }
}


Measured memory_bytes: 27992
N, M = map(int, input().split())
AB = sorted([[int(i) for i in input().split()] for i in range(M)], key = lambda x: x[1])

cnt = 1
posi = AB[0][1]
for i in range(1, M):
    if AB[i][0] >= posi:
        cnt += 1
        posi = AB[i][1]

print(cnt)

Measured memory_bytes: 25000
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

int main() {
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else if(s == "ARC") cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3596
#practice
N=int(input())
if N>=0 and N<=1000:
	i=1
if N>1000 and N<=2000:
	i=2
if N>2000 and N<=3000:
	i=3
if N>3000 and N<=4000:
	i=4
if N>4000 and N<=5000:
	i=5
if N>5000 and N<=6000:
	i=6
if N>6000 and N<=7000:
	i=7
if N>7000 and N<=8000:
	i=8
if N>8000 and N<=9000:
	i=9
if N>9000 and N<=10000:
	i=10
x=1000*i-N
print(x)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
 
int main() {
    int n;
    cin >> n ;
    vector<int> vec(n);
    vector<int> vec_ans(n);
 
    rep(i,n-1){
        cin >> vec.at(i);
      	//vec_ans.at(i) = -1;
    }
  
  
  	for(int i = 0; i < n - 1; i++){
     	if(i == 0){
         	vec_ans.at(i) = vec.at(0);
        }
      	if(i > 0){
         	if(vec.at(i-1) < vec.at(i)){
             	vec_ans.at(i) = vec.at(i-1);
            }else{
              	vec_ans.at(i) = vec.at(i);
            }
        }
      	if(i == n - 2){
          vec_ans.at(i+1) = vec.at(i);
        }
    }
  
  
  	
  
  	ll ans = 0;
  	rep(i,n){
      //cout << "i = " << vec_ans.at(i) << endl;
      ans += vec_ans.at(i);
    }
  
  	cout << ans << endl;
 
 
}

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

void fnInput(vector<int>& rvnMonstr, vector<int>& rvnBrave)
{
  int nMonstrSiz;
  cin >> nMonstrSiz;
  rvnMonstr.resize(nMonstrSiz + 1);
  rvnBrave.resize(nMonstrSiz);

  for (int& rnMonstr : rvnMonstr)
    cin >> rnMonstr;

  for (int& rnBrave : rvnBrave)
    cin >> rnBrave;
}
  
int64_t fnStrikMonstr(vector<int>& rvnMonstr, vector<int>& rvnBrave)
{
  int64_t nSumStrikMon = 0;

  for (int nBgn = 0; nBgn < rvnBrave.size(); nBgn++)
    for (int nFoward = nBgn; nFoward < nBgn + 2; nFoward++)
    {
      int nStrikMonstr = min(rvnBrave[nBgn], rvnMonstr[nFoward]);
      rvnMonstr[nFoward] -= nStrikMonstr;
      rvnBrave[nBgn] -= nStrikMonstr;
      nSumStrikMon += nStrikMonstr;
    }

  return nSumStrikMon;
}
  
int main()
{
  vector<int> vnMonstr, vnBrave;

  fnInput(vnMonstr, vnBrave);
  cout << fnStrikMonstr(vnMonstr, vnBrave) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;

#define re_ return
#define in_ inline
#define op_ operator
#define inc(l, i, r) for(i=l; i<r; ++i)
#define st_ static
typedef long long ll;

const int mxn=1<<9;

int n, m, a[mxn], b[mxn<<1], cnt[2], h[mxn<<1];
struct edge{int v, o;} e[1<<20];

in_ ll dP(ll a, ll b, ll p)
{
    st_ ll r;
    for(r=1; b; a=a*a%p, b>>=1)
        b&1? r=r*a%p: 0;
    re_ r;
}

in_ char chk(ll a, ll p)
{
    st_ ll s, r, i;
    for(r=p-1, s=0; ~r&1; ++s, r/=2);
    if(i=dP(a, r, p), i==1 || i==p-1) re_ 1;
    for(;s--;)
        if((i=i*i%p)==p-1) re_ 1;
    re_ 0;
}

in_ char isP(int p)
{
    if(p==2) re_ 1;
    if(p==1 || ~p&1) re_ 0;
    st_  int i;
    inc(0, i, 4)
        if(!chk(rand()%(p-2)+1, p))
            re_ 0;

//    for(i=2; i*i<=p; ++i)
//        if(p%i==0)
//            re_ 0;
    re_ 1;
}

in_ void aE(int u, int v)
{
    st_ int tot;
    e[++tot]=(edge){v, h[u]}, u[h]=tot;
}

char vis[mxn<<1];
char Hun(int u)
{
    st_ int f[mxn<<1];
    int i, v;
    for(i=u[h]; v=i[e].v; i=i[e].o)
        if(!vis[v])
            if(vis[v]=1, !f[v] || Hun(f[v]))
            re_ f[v]=u, 1;
    re_ 0;
}

int main()
{
    srand(998244353);
    int i, j;
    scanf("%d", &n);
    inc(0, i, n)
        scanf("%d", a+i);
    sort(a, a+n);
    inc(0, i, n)
    {
        if(!i || a[i]>a[i-1]+1)
            b[++m]=a[i], ++cnt[a[i]&1];
        if(i>n-2 || a[i]<a[i+1]-1)
            b[++m]=a[i]+1, ++cnt[a[i]+1&1];
    }
    inc(1, i, m+1)
        if(b[i]&1)
            inc(1, j, m+1)
                if(~b[j]&1 && isP(abs(b[i]-b[j])))
                    aE(i, j);

    j=0;
    inc(1, i, m+1)
        if(b[i]&1)
            memset(vis, 0, sizeof(vis)),
                j+=Hun(i);

    printf("%d\n", cnt[0]+cnt[1]-j+(cnt[0]-j&1));
//    printf("%d\n", m);
//    for(;;) scanf("%d", &i), printf("%d\n", isP(i));
    0;
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    B = LI()

    sm = 0
    for i in range(n):
        j = i - 1
        # print(i, j)
        if j < 0:
            a = B[i]
        elif i == n-1:
            a = B[j]
        else:
            a = min(B[i], B[j])
        sm = sm + a
    print(sm)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064