akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(int(1e9))

class uft:
  def __init__(self, N):
    self.__N = N
    self.__arr = [-1] * (N + 1)
  def fp(self, x):
    if self.__arr[x] < 0:
      return x
    else:
      self.__arr[x] = self.fp(self.__arr[x])
      return self.__arr[x]
  def add(self, x, y):
    px = self.fp(x)
    py = self.fp(y)
    if px > py:
      px, py = py, px
    if px == py:
      return 1
    self.__arr[px] += self.__arr[py]
    self.__arr[py] = px
  def groups(self):
    ret = -1
    for i in self.__arr:
      if i < 0:
        ret += 1
    return ret
  def show_arr(self):
    print(self.__arr)
  
N, M = map(int, input().split()) 
UFT = uft(N)

for i in range(M):
  A, B = map(int, input().split())
  UFT.add(A,B)
print(UFT.groups() -1)


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

int main()
{
    int n,x,c=1;
    cin >> n >> x;
    int arr[n+1];
    arr[0] = 0;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin >> a;
        arr[i] = arr[i-1]+a;
        if(arr[i]<=x)
        {
            c++;
        }
    }
    cout << c;
}


Measured memory_bytes: 256
def f(x,y):
    d=(x*x+y*y)**0.5
    return -y/d,x/d
while True:
    n=input()
    if n==-1:
        break
    x,y=1.0,0
    for i in xrange(n-1):
        dx,dy=f(x,y)
        x,y=x+dx,y+dy
    print x,y

Measured memory_bytes: 4364
import sys 
from heapq import heapify,heappop,heappush,heappushpop
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(N,K,L,R):
    left = [[] for _ in range(N)]
    right = [[] for _ in range(N)]
    score = 0
    for i in range(N):
        k = K[i]; l = L[i]; r = R[i]
        k -= 1
        if l >= r:
            left[k].append(l-r)
            score += r
        else:
            right[k].append(r-l)
            score += l
    q = []
    for n,xs in enumerate(left,1):
        for x in xs:
            if len(q) < n:
                heappush(q,x)
            else:
                heappushpop(q,x)
    score += sum(q)
    q = []
    for n,xs in enumerate(right[::-1][1:],1):
        for x in xs:
            if len(q) < n:
                heappush(q,x)
            else:
                heappushpop(q,x)
    score += sum(q)
    print(score)

T = int(readline())
for _ in range(T):
    N = int(readline())
    K, L ,R = [],[],[]
    for _ in range(N):
        k,l,r = map(int,readline().split())
        K.append(k)
        L.append(l)
        R.append(r)
    main(N,K,L,R)

Measured memory_bytes: 70376
// abc174_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int X;
    cin >> X;

    if (X >= 30){
        print("Yes");
    } else {
        print("No");
    }


    return 0;
}


Measured memory_bytes: 3648
import collections
import copy
def main():
    ct=collections.Counter
    N=int(input())
    A=[int(i) for i in input().split()]
    B=ct(A)
    anum=sorted(B,reverse=True)
    tate=0
    yoko=0
    for _ in range(2):
        for k,a in enumerate(anum):
            if B[a]>=2 and tate==0:
                tate=a
                break
            elif B[a]>=2 and tate:
                if a==tate and B[a]<4:continue;
                else:
                    yoko=a
                    break
    print(tate*yoko)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 18320
#! /usr/bin/python
# -*- coding: utf-8 -*-

#LPABCDEFSM
#0123456789

while 1:
    N = int(raw_input())
    if N==0: break
    crop = [raw_input().split() for i in range(N)]
    for i in range(N): crop[i][1:] = map(int, crop[i][1:])
    ef = []
    for i in range(N):
        com = (crop[i][-3]*crop[i][-1])*crop[i][-2]-crop[i][1]
        t = sum(crop[i][2:7])
        for j in range(crop[i][-1]-1):
            t += sum(crop[i][5:7])
        ef.append([-com/float(t), crop[i][0]])
    ef.sort()
    for i in range(N): print ef[i][1]
    print '#'
        

Measured memory_bytes: 4256
#include <iostream>
int main() {
	int n ,w;
	int m[105][2];
	int dp[105][10005];
	std::cin >> n >> w;
	for(int i = 0; i < n; i++){
		std::cin >> m[i][0] >> m[i][1];
	}
	for(int i = 0; i < w; i++){
		dp[0][i] = 0;
	}
    for(int i = 0; i < n; i++){
        dp[i][0] = 0;
    }
	for(int i = 1; i < n + 1; i++){
		for(int j = 1; j < w + 1; j++){
			if(j < m[i-1][1]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = std::max(dp[i-1][j-m[i-1][1]]+m[i-1][0], dp[i-1][j]);
		}
	}
	std::cout << dp[n][w] << std::endl;
	return 0;
}

Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int solve(vector<int> a,vector<int> b){
    int sq=0;
    rep(i,a.size()){
        sq+=pow(a.at(i)-b.at(i),2);
    }
    if(sqrt(sq)==int(sqrt(sq)))return 1;
    return 0;
}
int main(){
    int n,d,ans=0;
    cin >> n >> d;
    vector<vector<int> > vec(n,vector<int>(d));
    rep(i,n){
        rep(j,d){
            cin >> vec.at(i).at(j);
        }
    }
    rep(i,n){
        rep(j,i){
            ans+=solve(vec.at(i),vec.at(j));
        }
    }
    cout << ans << endl;
}

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

void swap(int &a,int &b){int c=a;a=b;b=c;}

int a[N],b[N],k,lena,lenb;
int main(){
	scanf("%d%d%d",&lena,&lenb,&k);
	char ch;
	int llen;
	for(int i=1;i<=lena;++i){
		cin>>ch;
		a[i]=ch-'0';
	}
	for(int i=1;i<=lenb;++i){
		cin>>ch;
		b[i]=ch-'0';
	}
	for(int i=1;i<=lena>>1;++i)
	swap(a[i],a[lena-i+1]); 
	for(int i=1;i<=lenb>>1;++i)
	swap(b[i],b[lenb-i+1]); 
	int len=max(lena,lenb);
	for(int i=len;i>0;--i){
		int s=0,kk=k;
		while (a[i+s]==1&&b[i+s]==1&&kk>0){
			a[i+s]=0;
			++a[i+s+1];
			b[i+s]=0;
			++b[i+s+1];
			++s;
			--kk; 
			int sa=s,sb=s;
			while(a[i+sa]==2){
				a[i+sa]=0;
				++a[i+sa+1];
				++sa;
			}
			while(b[i+sb]==2){
				b[i+sb]=0;
				++b[i+sb+1];
				++sb;
			}
			s=max(sa,sb);
		}
		llen=max(llen,s+i);
	}
	int sa=0,sb=0;
	while(!a[llen-sa])++sa;
	while(!b[llen-sb])++sb;
	for(int i=llen-sa;i>0;--i)cout<<a[i];
	cout<<"\n";
	for(int i=llen-sb;i>0;--i)cout<<b[i];
	cout<<"\n";
}

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

int main() {
  int a, b;
  
  cin >> a >> b;
  int r = a * b % 2;
  
  if (r == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC142A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int cnt = 0;
            for (int i = 1; i <= n; i++)
            {
                if (i % 2 != 0)
                {
                    cnt++;
                }
            }
            Console.WriteLine((decimal)cnt / n);
        }
    }
}


Measured memory_bytes: 13140
import sys

x,n = map(int, input().split())

if n == 0:
  print(x) 
  sys.exit()

p = set(map(int, input().split()))

if x not in p:
  print(x)

else:
  flag = True
  d = 0
  while flag == True:
    d += 1
    if x-d not in p:
      print(x-d)
      flag = False
    elif x+d not in p:
      print(x+d)
      flag = False


Measured memory_bytes: 9172
#include <bits/stdc++.h>
 
using namespace std;
 
//#define PRAGMA 448
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
 
#ifdef LUCARIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
 
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define f first 
#define s second 
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define mp make_pair    
#define endl "\n"
 
#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = b - 1; i >= a; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define ing(g,u,v)  g[u].pb(v); g[v].pb(u);
#define ingp(g,u,v,c) (g[u].pb({v,c});g[v].pb({u,c});)
#define mm(a,b) memset(a , b , sizeof a) 
#define trans(a,b) trasform(a.begin(),a.end(),a.begin(),b)
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())
#define sfind(s,t) (s.find(t) != string::npos)
 
#define infll (ll)1e15
#define infi  (int)(1e9+1)
#define PI 3.14159265359 
#define mod (ll)(1e9+7)
#define eps  1e-10

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int n,d;
string s;
int dp[100001][101][2];

int solve(int i, int re,int e){
    if(i == n)return (re == 0);
    int &r = dp[i][re][e];
    if(~r)return r;
    r=0;
    if(e){
        fore(j,0,s[i]-'0'+1){
            r = (r+ solve(i+1,(re+j)%d,(j == s[i]-'0')))%mod;
        }
    }else{
        fore(j,0,10){
            r = (r + solve(i+1,(re+j)%d,0))%mod;
        }  
    }
    return r;
}

int32_t main(int32_t argc, char const *argv[]){
    FIN;
    cin>>s>>d;
    n=SZ(s);
    mm(dp,-1);
    cout<<(solve(0,0,1)+mod-1)%mod;

    return 0;
}





































































































































































































































































































































































//formulas 
//cero = r/k  -(l/k + (l%k!=0)) +1; cantidad de numeros divisibles por k en el intervalo [l r]
//upper_bound primer elemento mayot estricto
//lower_bound primer elemento mayo o igual
//al hacer bfs con distancia recordar simpre antes de visitar preguntar si ya llegue antes co
//un peso menor
//setprecision(15)




//PROGRAMADO POR xXLucarioXx    


Measured memory_bytes: 158848
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
  cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
    int cnt=1;
  for(int i=0;i<n-1;i++){
  if(!(vec.at(i)==vec.at(i+1)))cnt++;}
  cout <<cnt <<endl;
}

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



int main(){

  int N;
  cin>>N;

  vector<ll> A(N),B(N),C(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];
  rep(i,N) cin>>C[i];

  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  ll ans = 0;

  rep(i,N){
    ans += (lower_bound(A.begin(),A.end(), B[i]) - A.begin()) *
    (C.end() - upper_bound(C.begin(), C.end(), B[i]));
    //cout<<ans<<endl;
  }

  cout<<ans;

}


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

int main() {
	char s[100010];
	scanf("%s", s);

	int a=0, b=0;
	for (int i = 0; i < strlen(s); i++) {
		if (s[i] == '0') a++;
		else b++;
	}

	cout << (a < b ? 2 * a : 2 * b) << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i=0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.rbegin(), vec.rend());
  int res=0;
  for (int i=0; i < n; i++) {
    if (i % 2 == 0) res += vec[i];
    else res -= vec[i];
   }
  cout << res << endl;
}


Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
	// write your code here
        int [] intarray = inputval();
        int n = intarray[0];
        int y = intarray[1];
        for (int i=0; i<=n; i++){
            int jMax = n-i;
            for (int j=0; j<=jMax; j++){
                int otoshidama = 10000*i+5000*j+1000*(n-i-j);
                    if (otoshidama > y){
                        break;
                    }else if (otoshidama == y){
                        System.out.println(String.valueOf(i)+" "+String.valueOf(j)+" "+String.valueOf(n-i-j));
                        return;
                    }
                }


        }
        System.out.println("-1 -1 -1");
    }

}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >>n;
  string s;
  int p;
  
  pair<pair<string,int>,int>answer[n];
  for(int i=0; i<n; i++){
    cin >>s >>p;
    answer[i]=make_pair(make_pair(s,-p),i+1);
  }
  
  sort(answer,answer+n);
  for(int i=0; i<n; i++){
    cout <<answer[i].second <<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int N, M;
bool g[51][51];
bool visited[51];
void dfs(int v) {
	visited[v] = true;
	for (int v2 = 0; v2 < N; ++v2) {
		if (g[v][v2] == false)continue;
		if (visited[v2] == true)continue;
		dfs(v2);
	}
}
int a[51], b[51];
int main() {
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}
	int ans = 0;
	for (int i = 0; i < M; ++i) {
		g[a[i]][b[i]] = g[b[i]][a[i]] = false;
		for (int j = 0; j < N; ++j)visited[j] = false;
		dfs(0);
		bool bridge = false;
		for (int j = 0; j < N; ++j) {
			if (visited[j] == false) {
				bridge = true;
			}
		}
		if (bridge)ans += 1;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations
from collections import Counter
class UnionFind():
  def __init__(self, x):
    self.x=x
    self.root=[-1]*(N+1)
    self.rnk=[0]*(N+1)
  
  def Find_root(self, x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.Find_root(self.root[x])
      return self.root[x]
    
  def Unite(self, x, y):
    x = self.Find_root(x)
    y = self.Find_root(y)
    if x==y:
      return
    elif self.rnk[x]>self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x]==self.rnk[y]:
        self.rnk[y]+=1
  
  def isSameGroup(self, x, y):
    return self.Find_root(x)==self.Find_root(y)
  
  def Count(self, x):
    return -self.root[self.Find_root(x)]
N,K,L=map(int,input().split())
u1=UnionFind(N)
u2=UnionFind(N)
for _ in range(K):
  x,y=map(int,input().split())
  u1.Unite(x-1,y-1)
for _ in range(L):
  x,y=map(int,input().split())
  u2.Unite(x-1,y-1)
l=[]
for i in range(N):
  l.append((u1.Find_root(i), u2.Find_root(i)))
c = Counter(l)
ans = []
for i in range(N):
  ans.append(c[(u1.Find_root(i), u2.Find_root(i))])
print(*ans)



Measured memory_bytes: 47332
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
////////////////////////////////////////////////////////////////////////////////////

const int N = 5E5 + 100;
int n, k; char s[N], t[N];
LL f[N], g[N], b[N];
deque<int> q;

int main() {
    cin >> n >> k;
    scanf("%s%s", s + 1, t + 1);
    FOR (i, 2, n + 1)
        b[i] = b[i - 1] + (t[i] != t[i - 1]);
    b[n + 1] = b[n];
    q.push_back(0);
    FOR (i, 1, n + 1) {
        if (t[i] == s[i]) {
            f[i] = f[i - 1];
        } else {
            while (q.front() < i - k) q.pop_front();
            assert (!q.empty());
            auto x = q.front();
            f[i] = (g[x] + b[i] + 2 + 1) / 2;
        }
        dbg(i, f[i]);
        g[i] = 2 * f[i] - b[i + 1];
        while (!q.empty() && g[q.back()] >= g[i]) q.pop_back();
        q.push_back(i);
    }
    cout << f[n] << endl;
    return 0;
}



Measured memory_bytes: 15920
/*
      author : nishi5451
      created: 11.08.2020 00:30:17
*/

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


int main(){
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    char c;
    c = s1[0]+'A'-'a';
    cout << c;
    c = s2[0]+'A'-'a';
    cout << c;
    c = s3[0]+'A'-'a';
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x;
repone(i,10){
  if(x%i==0&&x/i<10){
    std::cout << "Yes" << '\n';
    return 0;
  }
}
std::cout << "No" << '\n';
}


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

int main(){
  ll n;
  cin >> n;
  int ans = 0;
  for (ll i=2; i*i<=n-1; i++){
    if ((n-1) % i == 0){
      ans++;
      if (i*i != n-1) ans++;
    }
  }
  if (n > 2) ans++;  // n-1
  for (ll i=2; i*i<=n; i++){
    ll nn = n;
    ll k = i;
    while (nn % k == 0) nn /= k;
    if (nn < n && (nn-1) % k == 0){
      ans ++;
    }
    if (i*i != n){
      nn = n;
      k = n / i;
      while (nn % k == 0) nn /= k;
      if (nn < n && (nn-1) % k == 0){
        ans ++;
      }
    }
  }
  ans++;  // n
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
'''
ITP-1_2-D
????????¢?????????????????????????????????????????????????????°????????????????????????????????????
?¬????????????????????????¢?????????????????????????????¨??????????????????????????§?¨? (W,H)(W,H) ????????????????????????
????????????????????????????????§?¨? (x,y)(x,y) ??¨?????? rr ??§?????????????????????
'''
# ?????°??????????????????
W, H, x, y, r = map(int,input().split())

# ?????§?¨?x - ??????
if x-r < 0:
    print( "No" )
# ?????§?¨?x + ?????? > ????????¢??§?¨?W
elif x + r > W:
    print( "No" )
# ?????§?¨?y - ?????? < 0
elif y-r < 0:
    print( "No" )
# ?????§?¨?y + ?????? > ????????¢??§?¨?H
elif y+r > H:
    print("No" )
# ??\???
else:
    print( "Yes" )

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

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
////////////////////

void bad(){
	printf("No\n");
	exit(0);
}

int n;
void solve(){
	vector<int> a;
	while(n){
		a.pb(n%10);
		n /= 10;
	}
	if(a[0] == a[1] && a[1] == a[2]) return;
	if(a[1] == a[2] && a[2] == a[3]) return;
	bad();
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);

	solve();

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

using namespace std;
long long int B0[108], B1[108], B2[108], B3[108];
long long int A0[108], A1[108], A2[108], A3[108];
int main() {
	long long int N, W;
	cin >> N >> W;
	
	long long int u, w,W1;
	cin >> w >>u;
	A0[0] = u;
	long long int a = 1, b = 0, c = 0 , d = 0;
	W1 = w;
	for (int i = 0; i < N-1; i++) {
		cin >> w >> u;
		if (w - W1 == 0) {
		    A0[a] = u;
			a++;
		}
		if (w - W1 == 1) {
			A1[b] = u;
			b++;
		}
		if (w - W1 == 2) {
			A2[c] = u;
			c++;
		}
		if (w - W1 == 3) {
			A3[d] = u;
			d++;
		}
	}
	sort(A0, A0 + a+1, greater<int>());
	sort(A1, A1 +b +1, greater<int>());
	sort(A2, A2 + c+1, greater<int>());
	sort(A3, A3 + d+1, greater<int>());
	for (int i = 1; i < N; i++) {
		A0[i] += A0[i-1];
	}
	for (int i = 1; i < N; i++) {
		A1[i] += A1[i - 1];
	}
	for (int i = 1; i < N; i++) {
		A2[i] += A2[i - 1];
	}
	for (int i = 1; i < N; i++) {
		A3[i] += A3[i - 1];
	}
	
	for (int i = 0; i < N; i++) {
		B0[i + 1] = A0[i];
	}
	for (int i = 0; i < N; i++) {
		B1[i + 1] = A1[i];
	}
	for (int i = 0; i < N; i++) {
		B2[i + 1] = A2[i];
	}
	for (int i = 0; i < N; i++) {
		B3[i + 1] = A3[i];
	}

	long long int X = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= N; k++) {
				for (int y = 0; y <= N; y++) {
					if (i*W1+j*(W1+1)+k*(W1+2)+y*(W1+3)<=W) {
						X = max(X, B0[i] + B1[j] + B2[k] + B3[y]);
					}
				}
			}
		}
	}
	cout << X << endl;
	return 0;
}



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

class Progaram
{
    static void Main(String[] args)
    {
        var n = Int32.Parse(Console.ReadLine());
        var s = Console.ReadLine().ToCharArray();
        var res = 0;
        for (var i = 0; n - 2 > i; i++)
        {
            if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
            {
                res++;
                i += 2;
            }
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
using namespace std;
int main (){
    int a=0;
    string A;
    cin>>A;
    if(A[0]=='1')a++;
    if(A[1]=='1')a++;
    if(A[2]=='1')a++;
    cout<<a<<endl;
    return 0;
}

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

int main() {
  ll n; cin >> n;
  ll nn = n, ans = n-1;
  for (ll i = 2;i*i<=n;i++) {
    if (n%i==0) ans = min((i-1)+(n/i-1), ans);
  }
  cout << ans << endl;
  return 0;
}

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

signed main(void){
    int n,a,b; cin >> n >> a >> b;
    if((b-a)%2==0){
        cout << (b-a)/2 << endl;
    }else{
        // cout << min(max(abs(a-1),abs(b-1)),max(abs(n-b),abs(n-a))) << endl;
        cout << min(a-1+1+(b-a-1)/2,n-b+1+(b-a-1)/2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s ^= ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))

Measured memory_bytes: 178384
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;

struct edge {
	int to, cost;
};
class dijkstra {
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<P>> que;
	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first) continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}
	int find(int e) {
		return d[e];
	}
};
int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}
	void Union(int x, int y) {
		if (same(x, y)) return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}
	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}
	bool same(int x, int y) {
		return Find(x) == Find(y);
	}
	int get_Size(int a) {
		return s[a];
	}
};
signed main() {
	int n;
	cin>>n;
	map<string,vector<P>>mp;
	rep(i,n){
		string s;
		int p;
		cin>>s>>p;
		mp[s].push_back({p,i+1});
	}
	for(auto it:mp){
		vector<P> vec=it.second;
		sort(vec.begin(),vec.end(),greater<P>());
		rep(i,vec.size()){
			cout<<vec[i].second<<endl;
		}
	}
}


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

int main(){
  int N;
  int a[101];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];

  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a[i];
    }
    else{
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != t.charAt(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


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

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main() {
    string s;
    cin >> s;
    int sum = 0;
    for(const auto & i : s) {
        sum += ctoi(i);
    }

    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3752
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
	string s;
  	cin>>s;
  	int n=s.size(),ans=999,a;
  	
  	for(int i=0;i<n-2;i++){
		a=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
      	ans=min(ans,abs(a-753));
    }
	
  	cout<<ans<<endl;
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d){
    cout << "Left" << endl;
  }
  else if (a + b == c + d){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using namespace std;

const int INF = 1 << 30;

struct Event
{
  int length, idx;
  bool type;
};

int H, W, L, P;
bool wall[4000][4000];
int dp1[4000][4000], dp2[4000][4000];

void Calcdp()
{
  for(int i = 0; i < H; i++) {
    int now = 0;
    for(int j = W - 1; j >= 0; j--) {
      if(wall[i][j]) now = 0;
      else ++now;
      dp1[i][j] = now;
    }
  }
  for(int j = 0; j < W; j++) {
    int now = 0;
    for(int i = H - 1; i >= 0; i--) {
      if(wall[i][j]) now = 0;
      else ++now;
      dp1[i][j] = min(dp1[i][j], now);
    }
  }
  for(int i = 0; i < H; i++) {
    int now = 0;
    for(int j = 0; j < W; j++) {
      if(wall[i][j]) now = 0;
      else ++now;
      dp2[i][j] = now;
    }
  }
  for(int j = 0; j < W; j++) {
    int now = 0;
    for(int i = 0; i < H; i++) {
      if(wall[i][j]) now = 0;
      else ++now;
      dp2[i][j] = min(dp2[i][j], now);
    }
  }
}


struct BIT
{
  int data[4005], sz;
  int suz;

  void build(int crr)
  {
    sz = ++crr;
    suz = 0;
    memset(data, 0, sizeof(int) * sz);
  }

  inline int sum(int k)
  {
    int ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  inline int sum(int l, int r)
  {
    if(l > r) return (0);
    if(r == sz - 1) return (suz - sum(l - 1));
    return (sum(r) - sum(l - 1));
  }

  inline void add(int k, int x)
  {
    suz += x;
    for(++k; k < sz; k += k & -k) data[k] += x;
  }
};

Event e[8000];
BIT bitL, bitR;

long long CountDiagonal(int y, int x)
{
  int ptr = 0, now = 0;
  while(y < H && x < W) {
    if(dp1[y][x] >= L) {
      e[ptr++] = (Event) {dp1[y][x], now, 0};
    }
    if(dp2[y][x] >= L) {
      e[ptr++] = (Event) {dp2[y][x], now, 1};
    }
    ++y, ++x;
    ++now;
  }

  sort(e, e + ptr, [](const Event& a, const Event& b)
  {
    return (a.length > b.length);
  });

  long long ret = 0;
  bitL.build(now);
  bitR.build(now);
  for(int i = 0; i < ptr; i++) {
    const Event& o = e[i];
    if(o.type) {
      ret += bitL.sum(o.idx - o.length + 1, o.idx - L + 1);
      bitR.add(o.idx, 1);
    } else {
      ret += bitR.sum(o.idx + L - 1, o.idx + o.length - 1);
      bitL.add(o.idx, 1);
    }
  }
  return (ret);
}

int main()
{
  scanf("%d %d %d %d", &H, &W, &L, &P);
  while(P--) {
    int A, B;
    scanf("%d %d", &A, &B);
    --A, --B;
    wall[A][B] = true;
  }
  Calcdp();
  long long ret = 0;
  for(int i = 0; i < H; i++) {
    ret += CountDiagonal(i, 0);
  }
  for(int i = 1; i < W; i++) {
    ret += CountDiagonal(0, i);
  }
  printf("%lld\n", ret);
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<ll, int> P;

int n,a,b;
ll v[50];
ll c[51][51];

void comb() {
	REP(i,n+1) {
		REP(j,i+1) {
			if(j==0||j==i) c[i][j]=1LL;
			else c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
	}
}

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

	cin>>n>>a>>b;
	REP(i,n) cin>>v[i];
	comb();
	sort(v,v+n); reverse(v,v+n);

	double avr=0;
	REP(i,a) avr+=v[i];
	avr/=a;

	int num=0,pos=0;
	REP(i,n) {
		if(v[i]==v[a-1]) {
			num++;
			if(i<a) pos++;
		}
	}

	ll cnt=0;
	if(pos==a) {
		FOR(pos,a,b+1) cnt+=c[num][pos];
	}
	else cnt+=c[num][pos];

	printf("%f %lld\n",avr,cnt);

	return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a;
  int total=0;
  for(int i=0;i<n;++i){
    int x;
    cin >> x;
    a.push_back(x);
    total += x;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int count=0;
  for(int i=0;i<m;++i){
    if(a.at(i) * 4*m>= total) count++;
  }
  if(count == m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
int deg[10010] = {};
VI adj[10010];
int used[10010] = {};
int used2[10010] = {};
int val[10010];
VI c;
VI order;
LL ans = 0;

void bfs(int u){
    queue<int> que;
    que.push(u);
    order.pb(u);
    used[u] = 1;
    while(!que.empty()){
        int x = que.front();
        que.pop();
        used[x] = 1;
        for(auto p : adj[x]){
            if(used[p] == 1)  continue;
            else{
                que.push(p);
                order.pb(p);
            }
        }

    }
}
void bfs2(int u){
    queue<int> que;
    que.push(u);
    order.pb(u);
    used2[u] = 1;
    while(!que.empty()){
        int x = que.front();
        que.pop();
        used2[x] = 1;
        for(auto p : adj[x]){
            if(used2[p] == 1)  continue;
            else{
                que.push(p);
                order.pb(p);

                ans += min(val[p],val[x]);
            }
        }

    }
}





signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    REP(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        deg[a]++; deg[b]++;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    REP(i,N) {
        int tc; cin >> tc;
        c.eb(tc);
    }
    sort(c.begin(),c.end(),greater<int>());
    int start;
    int memo = 0;
    REP(i,N){
        if(deg[i] > memo){
            memo = deg[i];
            start = i;
        }
    }
    bfs(start);
    //cout << printVector(order) << endl;


    REP(i,N) {
        //cout << c[order[i]] << endl;
        //val.pb(c[order[i]]);
        val[order[i]] = c[i];
    }
    bfs2(start);
    cout << ans << endl;
    REP(i,N) {
        cout << val[i] <<" ";
        //val.pb(c[order[i]]);
    }
    cout << endl;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.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 popcount(n) (__builtin_popcountll(n))

using namespace std;

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 ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:
const int limit = 1010;
using edge = struct{int to,id;};
vector<edge> graph[limit];

int a[200010],b[200010];

bool visited[limit][limit];
void dfs(int v,int root){
	visited[root][v] = true;
	for(auto &e:graph[v]){
		if(visited[root][e.to]) continue;
		dfs(e.to,root);
	}
}

int small[limit][limit];
void dfs2(int v,int root,int id){
	small[root][v] = id;
	for(auto &e:graph[v]){
		if(small[root][e.to] != -1) continue;
		dfs2(e.to,root,id);
	}
}


int large[limit][limit];
void dfs3(int v,int root,int id){
	large[root][v] = id;
	for(auto &e:graph[v]){
		if(large[root][e.to] != -1) continue;
		dfs3(e.to,root,id);
	}
}

string ans[200010];

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

	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--,b[i]--;
		graph[a[i]].push_back({b[i],i});
	}

	rep(i,n) dfs(i,i);

	rep(i,n){
		const int l = graph[i].size();
			
		rep(j,n) small[i][j] = -1;
		small[i][i] = 0;
		rep(j,l) if(small[i][graph[i][j].to] == -1) dfs2(graph[i][j].to,i,j);

		rep(j,n) large[i][j] = -1;
		large[i][i] = 0;
		rrep(j,l) if(large[i][graph[i][j].to] == -1) dfs3(graph[i][j].to,i,j);
	}

	rep(i,n){
		const int l = graph[i].size();	
		rep(j,l){
			const int to = graph[i][j].to;
			bool ab = false;
			if(small[i][to] != -1 and small[i][to] <= j - 1) ab = true; 
			if(large[i][to] != -1 and j + 1 <= large[i][to]) ab = true; 
			//cerr << small[i][to] << " " << large[i][to] << endl;
			bool ba = visited[to][i];
			//cerr << graph[i][j].id << " " << ab << " " << ba << endl;
			ans[graph[i][j].id] = (ab != ba) ? "diff" : "same";
		}
	}

	rep(i,m) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 25472
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;

using namespace std;

int main(){
	int N;
  	cin >> N;
  	int B[N-1];
  	for(int i = 0; i < N-1; i++){
      	cin >> B[i];
    }
  	ll sum = B[0];
  	for(int i = 0; i < N-2; i++){
    	sum += min(B[i], B[i+1]);
    }
  	sum += B[N-2];
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top();
		S.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}
void assignColor() {
	int id = 1;
	for (int i = 0; i < n; i++) color[i] = NIL;
	for (int u = 0; u < n; u++) {
		if (color[u] == NIL) dfs(u, id++);
	}
}
int main() {
	int s, t, m, q;

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> s >> t;
		if (color[s] == color[t]) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}


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

using namespace std;

int main(){
    int niz[5];
    int rj;
    for(int i=0;i<5;i++){
        cin>>niz[i];
        if(niz[i]==0){
            rj=i+1;
        }
    }
    cout <<rj<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int x,y;
    cin >> x >> y;
    if(x < y){
        int a = x;
        x = y;
        y = a;
    }
    int r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    cout << y << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int n,a[100];

void print(){
	int i=0;
	while(true){
		cout<<a[i];
		i++;
		if(i<n){
			cout<<" ";
		}else{
			break;
		}
	}
	cout<<endl;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	bool flag=true;
	int cont=0,send=0;
	while(flag){
		flag=false;
		for(int i=n-1;i>send;i--){
			if(a[i]<a[i-1]){
				const int tmp=a[i];
				a[i]=a[i-1];
				a[i-1]=tmp;
				flag=true;
				cont++;
			}
		}
		send++;
	}
	print();
	cout<<cont<<endl;
	return 0;
}


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

// input
int A, B;
string S;


void input() {
    cin >> A >> B >> S;
}


int main() {
    input();
    int c = count(S.cbegin(), S.cend(), '-');
    string ans;
    if (S[A] == '-' && c == 1) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll K; cin >> K;
  ll mod = K;
  ll now = 0;
  rep(i,10000000){
    now *= 10;
    now += 7;
    now %= mod;
    if(now==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3632
def point(a,b):
    return a[0]*b[0]+a[1]*b[1]
def euclid(a):
    return (a[0]**2+a[1]**2)**(1/2)
def cos(a,b):
    return point(a,b)/(euclid(a)*euclid(b))
while 1:
    try:
        ax,ay,bx,by,cx,cy,px,py = map(float, input().split(" "))
        ab = [bx-ax, by-ay]
        ac = [cx-ax, cy-ay]
        ba = [ax-bx, ay-by]
        bc = [cx-bx, cy-by]
        ap = [px-ax, py-ay]
        bp = [px-bx, py-by]
        if min(cos(ab,ap),cos(ac,ap)) > cos(ab,ac) and min(cos(ba,bp),cos(bc,bp)) > cos(ba,bc):
            print("YES")
        else:
            print("NO")
    except:
        break


Measured memory_bytes: 5648
#include <iostream>
#include <string>
#include <vector>

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m);
    std::vector<int> b(m);
    for (int i = 0; i < m; i++) {
        std::cin >> a[i] >> b[i];
    }

    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        for (int j = 0; j < m; j++)
        {
            if(a[j] == i || b[j] == i) {
                cnt++;
            }
        }
        std::cout << cnt << "\n";
    }
}

Measured memory_bytes: 3616
# Union Find木の問題である

# 次のURLを参照して解いた
# http://at274.hatenablog.com/entry/2018/02/02/173000

class UnionFind():
    
    def __init__(self, n):
        # 各数字の親を管理するためのリストを作成する
        self.par = [i for i in range(n+1)]
        
        # 木の高さを管理するリストを用意する
        self.rank = [0] * (n+1)
    
    # 各数字の木の根が同じかどうかをチェックする
    def find(self, x):
        # 根である場合はその数字を返す
        if self.par[x] == x:
            return x
        # 違う場合は再帰関数を用いて根を返す
        # ただしこのままでは木が縦長の場合に検索の手間がかかる
        # 親を順に書き換えていく必要がある
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    # 根が同一かどうかを判定する
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    # 木どうしを結合するUnionの実装
    # 木の高さをなるべく低くするために、木が低い方の根から、高い方の根に辺を張る

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        # 木の高さを比較する
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
        
            # 木の高さが同じ場合は片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


n, m = map(int, input().split())
P = list(map(int, input().split()))
XY = []
ans = 0

for _ in range(m):
    xy = list(map(int, input().split()))
    XY.append(xy)

UF = UnionFind(n)
for i in range(m):
    UF.union(P[XY[i][0]-1], P[XY[i][1]-1])

for j in range(n):
    if UF.same_check(j+1, P[j]):
        ans += 1

print(ans)

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int>& vec) {
    for (auto& e : vec) {
        cout << e << " ";
    }
    cout << endl;
}

int func(long long N, std::string S) {
    // cout << fixed << setprecision(8);

    return 0;
}

int main() {
    double p;
    cin >> p;

    double t   = 1.08;
    int    u   = ceil(p / t);
    int    ans = floor(u * t);

    if (ans == p) {
        cout << u << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 256