akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
c = Array.new(n+1, 0)
w = Array.new(n+1, 0)
(1..n).each do |i|
  c[i], w[i] = gets.split.map(&:to_i)
end
dp = Array.new(n+1){ Array.new(n+1, 0) }
ret = Array.new(n+1, 0)
(1..n).each do |i| 
  dp[i][i] = c[i]
  ret[i] = ret[i-1] + 1
  x = w[i]
  y = w[i-1]
  (i-1).downto(1) do |j|
    dp[j][i] = [[dp[j+1][i], c[j] - x].min, [dp[j][i-1], c[i] - y].min].max
    x += w[j]
    y += w[j-1]
    break if dp[j][i] < 0
    ret[i] = ret[j-1] + 1
  end
end
p ret[n]

Measured memory_bytes: 16632
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.println(i+"x"+j+"="+i*j);
			}
		}
	}
}

Measured memory_bytes: 23880
def main():
    S = input()

    rule1 = S[0] == 'A'
    rule2 = S[2:len(S)-1].count('C') == 1
    rule3 = S[1:].replace('C','').islower()

    if(rule1 and rule2 and rule3):
        print('AC')
    else:
        print('WA')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define MOD 1000000007

int main()
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  s[k - 1] += 'a' - 'A';

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>


using namespace std;

int main() {
	int n, cnt = 1;
	cin >> n;
	int s[n];
	for(int i=0; i<n; i++) {
		cin >> s[i];
		if(i > 0) {
			if(s[i] != s[i%cnt]) {
				cnt = i+1;
			}
		}
	}
	if(n % cnt == 0)cout << n / cnt << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 1940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AApplePie solver = new AApplePie();
        solver.solve(1, in, out);
        out.close();
    }

    static class AApplePie {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int p = in.nextInt();
            out.println((a * 3 + p) / 2);
        }

    }
}



Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    double r; cin >> r;
    cout << 2*pi*r << endl;
    return 0;
}  

Measured memory_bytes: 3748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

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

  int n = std::stoi(s);
  int m = 0;
  for(char c:s){
    m += std::stoi(string() + c);
  }

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

  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var n, k int
	var ans int
	var s string
	//input
	fmt.Scan(&n, &k)
	d := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&d[i])
	}
	ans = n
	//process
	for true {
		for i := 0; i < k; i++ {
			s = strconv.Itoa(ans)
			if strings.Contains(s, d[i]) {
				break
			} else if i == k-1 {
				fmt.Println(ans)
				os.Exit(0)
			}
		}
		ans++
	}
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
const int MOD = 1000000007;
int sum[201], w[200];
int dp[10010];
int main() {
    int N, W; scanf("%d%d", &N, &W);
    rep(i, N) scanf("%d", w + i);
    sort(w, w + N);
    sum[0] = 0;
    rep(i, N) sum[i + 1] = sum[i] + w[i];
    if(sum[N] <= W) {
        puts("1");
        return 0;
    }
    memset(dp, 0, sizeof(dp));
    dp[0] = 1; int ans = 0;
    for(int i = N - 1; i >= 0; --i) {
        for(int j = W; j >= 0; --j) {
            if(sum[i] + j <= W && sum[i] + j > W - w[i])
              ans = (ans + dp[j]) % MOD;
            if(j >= w[i]) dp[j] = (dp[j] + dp[j - w[i]]) % MOD;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1252
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

ac,wa,tle,re = 0, 0, 0, 0

for _ in range(int(input()) if True else 1):
    #n, k = map(int, input().split())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    #a = list(map(int, input().split()))
    #b = list(map(int, input().split()))
    s = input()
    if s == "AC":
        ac += 1
    if s == "WA":
        wa += 1
    if s == "TLE":
        tle += 1
    if s == "RE":
        re += 1
print('''AC x %d
WA x %d
TLE x %d
RE x %d'''% (ac, wa, tle, re))

Measured memory_bytes: 74772
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for j in numdic:
    nsum += numdic[j] * (numdic[j] - 1) // 2

for k in range(n):
    ans = nsum
    if numdic[numlist[k]] >= 2:
        ans -= (numdic[numlist[k]]-1)
    print(ans)

Measured memory_bytes: 25716
import java.io.*;
import java.util.ArrayList;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        int a = 0;
 
        ArrayList<String> list1 = new ArrayList<>();
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        a = Integer.parseInt(br.readLine());
 
        for (int i = 0; i < a; i++) {
            list1.add(br.readLine());
        }
 
        for (int i = 1; i < 14; i++) {
            if (list1.contains("S " + i) == false) {
                System.out.println("S " + i);
            }
        }
 
        for (int i = 1; i < 14; i++) {
            if (list1.contains("H " + i) == false) {
                System.out.println("H " + i);
            }
        }
 
        for (int i = 1; i < 14; i++) {
            if (list1.contains("C " + i) == false) {
                System.out.println("C " + i);
            }
        }
 
        for (int i = 1; i < 14; i++) {
            if (list1.contains("D " + i) == false) {
                System.out.println("D " + i);
            }
        }
 
    }
 
}

Measured memory_bytes: 24488
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
int n, ans = 1e9;
char s[maxn + 10], t[maxn + 10];
vector<int> a, b;

void solve(char *s, vector<int> &a) {
	for (int i = 1; i < n; ++i)
		if (s[i] != s[i + 1]) a.push_back(i);
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 0; i < 5000; ++i)
		a.push_back(0);
	if (s[1] == '1') a.push_back(0);
	solve(s, a);
	for (int i = 0; i < 5000; ++i)
		a.push_back(n);
	scanf("%s", t + 1);
	if (t[1] == '1') b.push_back(0);
	solve(t, b);
	for (int i = 0; i < (int)a.size(); i += 2) {
		int l = i, r = i + (int)b.size() - 1, now = 0;
		if (r >= (int)a.size()) break;
		for (int j = 0; j < l; ++j) now += a[j];
		for (int j = l; j <= r; ++j)
			now += abs(a[j] - b[j - l]);
		for (int j = r + 1; j < (int)a.size(); ++j)
			now += n - a[j];
		ans = min(ans, now);
	}
	printf("%d", ans);
}


Measured memory_bytes: 512
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXH 32
#define MAXW 32
typedef long long ll;
typedef pair<int, int> P;

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

int w, h;
// hは縦方向 wは横方向
int wallh[MAXH][MAXW], wallw[MAXH][MAXW];
int d[MAXH][MAXW];

int main(void) {
    while (1) {
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w-1; j++) {
                cin >> wallw[i][j];
            }
            if (i < h-1) {
                for (int j = 0; j < w; j++) {
                    cin >> wallh[i][j];
                }
            } else {
                for (int j = 0; j < w; j++) {
                    wallh[i][j] = 1;
                }
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                d[i][j] = -1;
            }
        }
        d[0][0] = 1;
        queue<P> que;
        que.push(make_pair(0, 0));
        while (!que.empty()) {
            P now = que.front(); que.pop();
            int y = now.first, x = now.second;
            // 右方向
            if (x < w-1 && wallw[y][x] == 0) {
                int nx = x + 1;
                int ny = y;
                if (d[ny][nx] < 0) {
                    d[ny][nx] = d[y][x] + 1;
                    que.push(make_pair(ny, nx));
                }
            }
            // 上方向
            if (0 < y && wallh[y-1][x] == 0) {
                int nx = x;
                int ny = y - 1;
                if (d[ny][nx] < 0) {
                    d[ny][nx] = d[y][x] + 1;
                    que.push(make_pair(ny, nx));
                }
            }
            // 左方向
            if (0 < x && wallw[y][x-1] == 0) {
                int nx = x - 1;
                int ny = y ;
                if (d[ny][nx] < 0) {
                    d[ny][nx] = d[y][x] + 1;
                    que.push(make_pair(ny, nx));
                }
            }
            // 下方向
            if (y < h-1 && wallh[y][x] == 0) {
                int nx = x;
                int ny = y + 1;
                if (d[ny][nx] < 0) {
                    d[ny][nx] = d[y][x] + 1;
                    que.push(make_pair(ny, nx));
                }
            }
        }
        if (d[h-1][w-1] < 0) cout << 0 << endl;
        else cout << d[h-1][w-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
MOD = 1000000007

def pow(a, b):
	if not b:
		return 1
	c = pow(a, b // 2)
	if b % 2:
		c = a * c % MOD * c % MOD
	else:
		c = c * c % MOD
	return c

X, Y = map(int, input().split())
if (X * 2 - Y) % 3 or (Y * 2 - X) % 3:
	print(0)
else:
	a, b = (X * 2 - Y) // 3, (Y * 2 - X) // 3
	if a < 0 or b < 0:
		print(0)
	else:
		c = [1] * (max(a + b, a) + 1)
		i = 1
		while i <= max(a + b, a):
			c[i] = c[i - 1] * i % MOD
			i += 1
		print(c[a + b] * pow(c[a], MOD - 2) % MOD * pow(c[b], MOD - 2) % MOD)

Measured memory_bytes: 43888
(N,),r,*L=$<.map{_1.split.map &:to_i}
l=(n=*0..N).map{[1e9]*$.}
L.map{l[_1][_2]=l[_2][_1]=_3}
n.map{|k|n.map{|i|n.map{|j|l[i][j]=[l[i][j],l[i][k]+l[k][j]].min}}}
p r.permutation.map{|b,*a|a.sum{l[b][b=_1]}}.min

Measured memory_bytes: 145220
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
#低いやつを引いていく感じ
Hlist = list(int(x) for x in input().split())

flag = [1]*N

for i in range(M):
    A,B = map(int, input().split())
    A -= 1
    B -= 1
    if(Hlist[A] == Hlist[B]) :
        flag[A] = 0
        flag[B] = 0
    elif(Hlist[A] > Hlist[B]) :
        flag[B] = 0
    else :
        flag[A] = 0
print(sum(flag))

Measured memory_bytes: 20164
class Cell:
    def __init__(self, entity, next, prev):
        self.entity = entity
        self.next = next
        self.prev = prev


n = int(input())
A = list(map(int, input().split()))
cell = Cell(A[0], None, None)
top = cell
last = cell

cnt = 0
for i in range(1, len(A)):
    cnt += 1
    if i % 2 == 0:
        tmp = last
        last = Cell(A[i], None, last)
        tmp.next = last
    else:
        tmp = top
        top = Cell(A[i], top, None)
        tmp.prev = top

b = []
cell = top
while(True):
    b.append(cell.entity)
    if not(cell.next):
        break
    cell = cell.next
if n % 2 == 1:
    b.reverse()
print(' '.join(map(str, b)))


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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;


int main()
{
	string s, t;

	cin >> s >> t;
	t.pop_back();

	if (s == t) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

}

Measured memory_bytes: 3592
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    tmp = c
    for j in range(m):
        tmp += a[i][j]*b[j]
    if tmp > 0:
        ans += 1

print(ans)


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

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    int a,b,m;cin>>a>>b>>m;
    vector<int>c1(a);
    vector<int>c2(b);
    rep(i,a)cin>>c1[i];
    rep(i,b)cin>>c2[i];
    int res = INF;
    rep(i,m){
        int x,y,c;cin>>x>>y>>c;
        x--;y--;
        int sum = c1[x]+c2[y]-c;
        res = min(res,sum);
    }
    sort(ALL(c1));
    sort(ALL(c2));
    res = min(res,c1[0]+c2[0]);
    cout<<res<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,y,z,l,n,m,a,r,f;
  long long min,max,sum;
  string s;
  //vector<vector<int>> A(n, vector<int>(m, 0));
  //vector<int> b(m);
  
  while(1){
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1)break;
    if(m == -1 || f == -1)s = "F";
    else if(m + f >= 80)s = "A";
    else if(m + f >= 65)s = "B";
    else if(m + f >= 50)s = "C";
    else if(m + f >= 30){
      if(r >= 50)s = "C";
      else s = "D";
    } else s = "F";
    cout << s << endl;
  }
  
}


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

int main() {
  int n;
  cin>>n;
  vector<int> a(n),s(n);
  bool no=false;
  int g=0;
  int f=1000000001;
  for(int i=0;i<n;i++){
    cin>>a[i];
    
    if(a[i]==0) no=true;
    if(a[i]<0){
      g++;
      s[i]= -a[i];
    }
    else{
      s[i]=a[i];
    }
    f=min(f,s[i]);
  }
  long long ans=0;
  if(no || (g%2==0)){
    for(int i=0;i<n;i++){
     
      ans+=s[i];
    }
  }
  else{
    for(int i=0;i<n;i++){
     
      ans+=s[i];
    }
    ans-=2*f;
  }
  cout<<ans<<endl;
}

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

int main(){
    int N, M;
    cin>>N>>M;
    vector<int>vec(N);
    vector<int>flg(N, -1);
    vector<int>path[N];
    for(int i=0;i<N;i++){
        cin>>vec[i];
        vec[i]--;
    }
    for(int i=0;i<M;i++){
        int a, b;
        cin>>a>>b;
        path[a-1].push_back(b-1);
        path[b-1].push_back(a-1);
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        if(flg[i]>=0)continue;
        stack<int>st;
        flg[i]=i;
        st.push(i);
        while(!st.empty()){
            int tmp = st.top();
            st.pop();
            for(int j=0;j<path[tmp].size();j++){
                if(flg[path[tmp][j]]>=0)continue;
                flg[path[tmp][j]]=i;
                st.push(path[tmp][j]);
            }
        }

    }
    for(int i=0;i<N;i++){
        if(flg[i]==flg[vec[i]])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

#define N 100010
int n,m,a[N],maxa;

int main() {
  sf("%d%d",&n,&m);
  rep(i,1,m) {
    sf("%d",a+i);
    gmax(maxa, a[i]);
  }
  pf("%d\n", max(0, maxa-(n-maxa)-1));
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n; cin>>n;
	vint b(n-1);
	rep(i,n-1)cin>>b[i];
	ll ans = b[0];
	REP(i,n-2){
		ans += min(b[i], b[i-1]);
	}
	cout<<ans+b[n-2]<<endl; return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    String s = sc.next();
    String t = sc.next();
    out.print(t);
    out.println(s);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 27860
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MAXLEN = 300;
const int MOD = 998244353;
void inc(int& a, int b) { if ((a += b) >= MOD) a -= MOD; }
void dec(int& a, int b) { inc(a, MOD - b); }

char s[MAXLEN + 1]; int slen;
int lim;

vector<int> groups;
int dp[MAXLEN + 1][MAXLEN + 1];
int dpsum[MAXLEN + 1][MAXLEN + 1];
int dpsum2[MAXLEN + 1][MAXLEN + 1];
int ndp[MAXLEN + 1][MAXLEN + 1];

int solve() {
	{ groups.clear(); int groupsz = 0; REP(i, slen) if (s[i] == '1') ++groupsz; else groups.PB(groupsz), groupsz = 0; groups.PB(groupsz); }
	int sum = 0; REPSZ(i, groups) sum += groups[i];
	REPE(rem, sum) REPE(need, sum - rem) dp[rem][need] = need == 0 ? 1 : 0;

	for (int i = SZ(groups) - 1; i >= 0; --i) {
		REPE(rem, sum) REPE(need, sum - rem) { dpsum[rem][need] = dp[rem][need]; if (need - 1 >= 0) inc(dpsum[rem][need], dpsum[rem][need - 1]); }
		for (int rem = sum; rem >= 0; --rem) REPE(need, sum - rem) { dpsum2[rem + need][need] = dp[rem][need]; if (need - 1 >= 0) inc(dpsum2[rem + need][need], dpsum2[rem + need][need - 1]); }
		REPE(rem, sum) REPE(need, sum - rem) {
			ndp[rem][need] = 0;
			// remove at least one of them
			{ int lo = need - min(need, groups[i]), hi = need - 1; if (lo <= hi) { inc(ndp[rem][need], dpsum[rem][hi]); if (lo - 1 >= 0) dec(ndp[rem][need], dpsum[rem][lo - 1]); } }
			//FORE(j, 1, min(need, groups[i])) inc(ndp[rem][need], dp[rem][need - j]);
			// keep same or add some
			{ int lo = need, hi = need + min(rem, sum - need); if (lo <= hi) { inc(ndp[rem][need], dpsum2[rem + need][hi]); if (lo - 1 >= 0) dec(ndp[rem][need], dpsum2[rem + need][lo - 1]); } }
			//REPE(j, min(rem, sum - need)) inc(ndp[rem][need], dp[rem - j][need + j]);
		}
		REPE(rem, sum) REPE(need, sum - rem) dp[rem][need] = ndp[rem][need];
	}
	return dp[min(lim, sum)][0];
}


void run() {
	scanf("%s", s); slen = strlen(s);
	scanf("%d", &lim);
	printf("%d\n", solve());
}

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


Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long H;
    cin >> H;
    long long answer = 1;
    for(long long i = 0; i < 1000000 ; i++){
        H = H/2;
        answer = answer * 2;
        if(H == 0){
            break;
        }
    }
    printf("%lld\n", answer -1);

}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

struct P {
    vi pos;
    int from;
    int cost;

    bool operator >(const P& p) const {
        return cost > p.cost;
    }
};

const int moveto[9][4] = {
    {2,4,9,7},
    {3,5,1,8},
    {4,6,2,9},
    {5,7,3,1},
    {6,8,4,2},
    {7,9,5,3},
    {8,1,6,4},
    {9,2,7,5},
    {1,3,8,6},
};

inline int keypos(vi& pos) {
    int pp = 0;
    REP(i, 9) {
        pp *= 10;
        pp += pos[i];
    }
    return pp;
}

int main() {
    int c[2];
    while (cin >> c[0] >> c[1], c[0]|c[1]) {
        vi start(9), goal(9);
        REP(i, 9) cin >> start[i];
        REP(i, 9) cin >> goal[i];

        map<int, int> G;

        priority_queue<P, vector<P>, greater<P>> que;
        G[keypos(start)] = 0;
        int from = find(ALL(start), 0) - start.begin();
        que.push({start, from, 0});

        while (!que.empty()) {
            P p = que.top(); que.pop();
            if (p.pos == goal) {
                cout << p.cost << endl;
                break;
            }

            REP(i, 4) {
                int to = moveto[p.from][i]-1; // oops
                swap(p.pos[p.from], p.pos[to]);
                int cost = p.cost + c[i%2];
                int k = keypos(p.pos);
                if (!EXIST(G, k) || G[k] > cost) {
                    G[k] = cost;
                    que.push({p.pos, to, cost});
                }
                swap(p.pos[p.from], p.pos[to]);
            }
        }
    }
}

Measured memory_bytes: 29424
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    string S, T; cin >> S >> T;
    string ans = "";
    REP(i, 0, N) {
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }
    cout << ans << endl;
    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;
using P = pair <int, int>;
const double PI = acos(-1);

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  int j=0;
  rep(i,N) {
    cin >> p[i];
    if(p[i] != (i+1)) j++;
  }
  if(j == 0 || j ==2) cout << "YES" << endl;
  else  cout << "NO" << endl;
}


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

int main(){
    bool ret=true;
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    
    if(x - r < 0 || y - r < 0 || x + r > w || y + r > h){
       cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 1156
#include <stdio.h>

int main(void) {
  long long A, B, C;
  scanf("%lld%lld%lld\n", &A, &B, &C);
  if (A+B<C) printf("%lld\n", A+1+2*B);
  else printf("%lld\n", C+B);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int N;
	int V=100000;
	scanf("%d",&N);
	for(;N>=1;N--){
		V+=V*0.05;
		if(V%1000)
			V=V-V%1000+1000;
	}
	printf("%d\n",V);
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int q;
  cin>>q;
  rep(i,q){
    int c,a,n;
    cin>>c>>a>>n;
    int cca,ccc,can;
    int ans=0;
    rep(can,min(min(c,a),n)+1){//num of can                             
      cca=min((c-can)/2,a-can);//num of cca                             
      ccc=(c-can-cca*2)/3;//num of ccc                                  
      ans=max(ans,can+cca+ccc);
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;

int solve(vector<int> &vpos, int l, int r) {
  auto lb_it = lower_bound(vpos.begin(), vpos.end(), l);
  auto ub_it = upper_bound(vpos.begin(), vpos.end(), r);
  int ans = distance(lb_it, ub_it);
  if (binary_search(vpos.begin(), vpos.end(), r)) {
    ans--;
  }

  return ans;
}

int main(int argc, const char *argv[]) {
  int n, q;
  string s;
  cin >> n >> q >> s;

  vector<pair<int, int>> qs(q);
  for (auto &q : qs) {
    cin >> q.first >> q.second;
    q.first--;
    q.second--;
  }

  vector<int> vpos;
  for (int i = 1; i < s.size(); i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') {
      vpos.push_back(i - 1);
    }
  }

  for (auto q : qs) {
    cout << solve(vpos, q.first, q.second) << '\n';
  }

  return 0;
}

Measured memory_bytes: 2044
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    ll N, T; cin >> N >> T;
    vl A(N); REP(i, N) cin >> A[i];

    vl lo(N, LINF); // minimun in [0,i]
    lo[0] = A[0];
    FOR(i, 1, N) {
        lo[i] = min(lo[i-1], A[i]);
    }

    ll difHi = 0;
    ll cnt = 0;
    REP(i,N) {
        int dif = A[i] - lo[i];
        if (dif > difHi) {
            difHi = dif;
            cnt = 1;
        } else if (dif == difHi) {
            cnt++;
        }
    }

    ll ans = cnt;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll x;
    cin >> x;
    cout << ( x / 500 ) * 1000 + ( x % 500 / 5 ) * 5 << endl;
    return 0;
}


Measured memory_bytes: 384
// Vicfred
// https://atcoder.jp/contests/abc163/tasks/abc163_c
// map
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(to!int).array;

    int[] boss = new int[n+1];

    foreach(person; a)
        boss[person] += 1;

    for(int i = 1; i <= n; i++)
        boss[i].writeln;
}



Measured memory_bytes: 11716
#include <iostream>
#include <algorithm>
using namespace std;
const static int MAX = 100;

void printArray(int* array, int loop) {
	for (int i = 0; i < loop; i++) {
		if(i != loop - 1) cout << array[i] << " ";
		else cout << array[i] << endl;
	}
}

void insertSort(int* array, int loop) {
	int v, j;

	printArray(array, loop);

	for (int i = 1; i < loop; i++) {
		v = array[i];
		j = i - 1;
		while (j >= 0 && array[j] > v) {
			array[j + 1] = array[j];
			j--;
		}
		array[j + 1] = v;
		printArray(array, loop);
	}
	//printArray(array, loop);
}

int main()
{
	int loop = 0;
	int a[MAX];

	cin >> loop;
	for (int i = 0; i < loop; i++) cin >> a[i];

	insertSort(a, loop);

	return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  long long A,B;
  cin>>A>>B;
  
  int G;
  
  for(int i=100000;i>=0;i--){
    if(A%i==0&&B%i==0){
      G=i;
      break;
    }
  }
  
  cout<<A*B/G<<endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
#define MAX_N 2000
#define INF 1000000
int d[MAX_N][MAX_N];

void init(){
	rep(i,MAX_N){
		rep(j,MAX_N){
			d[i][j] = INF;
		}
	}
}

void warshall_floyd(int n){
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

void solve(int n,int x,int y){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			d[i][j] = min(min(abs(i - j),abs(i - x) + 1 + abs(j - y)),abs(i - y) + 1 + abs(j - x));
		}
	}
}

int main()
{
	init();
	int n,x,y;
	cin>>n>>x>>y;
	for(int i = 0; i < n-1; i++){
		d[i][i+1] = 1;
		d[i+1][i] = 1;
	}
	x = x - 1;
	y = y - 1;
	d[x][y] = 1;
	d[y][x] = 1;
	solve(n,x,y);
	int *distance = new int[n];
	rep(i,n) distance[i] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			distance[d[i][j]-1]++;
		}
	}
	rep(i,n-1){
		cout<<distance[i]/2<<endl;
	}
	/*for(int k = 1; k <= n-1; k++){
		int ans = 0;
		for(int i = 0 ; i < n-1; i ++){
			for(int j = i + 1; j < n; j++){
				if(d[i][j] == k) ans++;
			}
		}
		cout<<ans<<endl;
	}*/
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

// http://koturn.hatenablog.com/entry/2018/08/01/010000
template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  int n;
  cin >> n;
  vi32 x(n);
  cin >> x;
  rep(i, n) x[i]--;
  using T = tuple<int, int>;
  pqasc<T> pq;
  queue<int> q;
  vi32 used(n);
  rep(i, n) {
    if (i != 0) {
      pq.emplace(x[i], i);
    }
  }
  vi32 a(n * n);
  rep(i, n) a[x[i]] = i + 1;
  rep(i, n * n) {
    if (a[i] != 0) {
      int id = a[i] - 1;
      if (used[id] < id) {
        no();
      }
      used[id] += 1;
      if (id + 1 != n) q.emplace(id);
    } else {
      if (sz(pq)) {
        int xi, id;
        tie(xi, id) = pq.top();
        a[i] = id + 1;
        used[id] += 1;
        if (used[id] == id) {
          pq.pop();
        }
      } else if (sz(q)) {
        int id = q.front();
        a[i] = id + 1;
        used[id] += 1;
        if (used[id] == n) {
          q.pop();
        }
      } else {
        no();
      }
    }
  }
  cout << "Yes" << endl;
  cout << a << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    vector<vector<int>> distance(n, vector<int>(n));
    vector<vector<bool>> check(n, vector<bool>(n, true));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) cin >> a[i][j];
    }
    distance = a;
    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                if (i != k && j != k && distance[i][j] >= distance[i][k] + distance[k][j]) {
                    check[i][j] = false;
                }
                distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j]);
            }
        }
    }
    if (a != distance) cout << -1 << endl;
    else {
        long long ans = 0;
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                if (check[i][j]) ans += distance[i][j];
            }
        }
        cout << ans / 2 << endl;
    }
}

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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/


int main()
{
    SAM;
    string s;
    cin>>s;
    int n=s.length();
    if(s[n-1]=='s')
        cout<<s<<"es";
    else
        cout<<s<<"s";
    
    
    
    
    
    return 0;
}




Measured memory_bytes: 3660
#46 ABC137D
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab=sorted(ab, key=lambda x:x[0])
import heapq
i=0
heap=[]
res=[]
for x in range(1,m+1):
	while(i<n):
		if ab[i][0]==x:
			heapq.heappush(heap,-ab[i][1])
			i+=1
		else:
			break
	if len(heap)>0:
		res.append(heapq.heappop(heap))
print(-sum(res))

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

using namespace std;

int dp[111][111];
void solve() {
    int n,m;
    cin >> n >> m;
    vector<string> s(n);
    for (auto& x: s) cin >> x;
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = s[0][0]=='#';
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int _:{0,1}) {
                int x = i+_;
                int y = j+(_^1);
                if (x<n&&y<m) {
                    int more = (s[i][j]=='.' && s[x][y]=='#');
                    dp[x][y] = min(dp[x][y], dp[i][j] + more);
                }
            }
        }
    }
    cout << dp[n-1][m-1];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N,D;cin>>N>>D;
  vector<vector<int> > X(N,vector<int>(D));
  int dist,cnt=0;
  REP(i,0,N)REP(j,0,D)cin>>X[i][j];
  REP(i,0,N)REP(j,i+1,N){
    dist=0;
    REP(d,0,D){
      dist+=pow((X[i][d]-X[j][d]),2);
    }
    REP(k,0,dist+1){
      if(pow(k,2)==dist)cnt++;
    }
  }
  print(cnt)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll X;
    cin >> X;

    ll ans = 0;
    ans += (X / 500) * 1000;
    X -= (X / 500) * 500;
    ans += (X / 5) * 5;
    X -= (X / 5) * 5;

    print(ans);

    return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String N = sc.next();
		char c = N.charAt(0);
		boolean allsmall = true;
		
		for(int i = 1; i < N.length(); i++){
			if(N.charAt(i) > c) allsmall = false;
		}
		
		for(int i = 0; i < N.length(); i++) System.out.print(allsmall?""+c:""+(char)(c+('2'-'1')));
		System.out.println();
	}
}

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

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

  int b, e;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      b = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      e = i;
      break;
    }
  }

  cout << e - b + 1<< endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int N;
    char A;
    cin >> N;
    for(int i = 0; i < N; i++){
    cin >> A;
        if(A == 'Y'){
        cout << "Four" << endl;
        break;
            }
        if ( i == N-1 ){
            cout << "Three" << endl;
            break;
        }    
        
    }
    // Your code here!
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout <<"Cloudy"<<endl;
    }
    else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
    else if(s=="Rainy"){
        cout <<"Sunny"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
int l,r;
int ans;
int main(void){
    cin>>n;
    while(n--){
        cin>>l>>r;
        ans+=(r-l+1);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int main()
{
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll> >arr(n+1);
    for(ll i = 1; i <= n; i++)
    {
        ll a,b;
        cin>>a>>b;
        arr[i] = mp(a,b);
    }
    vector<vector<ll> >dp(n+1,vector<ll>(w+1));
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= w; j++)
        {
            if(j < arr[i].first)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-arr[i].first]+arr[i].second);
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 83032
#include <iostream>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i<n; i++)
#define rep1(i, n) for (int i = 1; i<=n; i++)
using namespace std;
typedef long long ll;

int main() {
    string a, b;
    cin >> a;
    cin >> b;
    int cnt = 0;
    rep(i, a.size()) if (a[i] != b[i]) cnt++;
    
    if (cnt > 0) cout << "No" << endl;
    else  cout << "Yes" << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;

lli dp[2005];
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    cin >> n;

    dp[0] = 1;

    for(int i=3;i<=n;i++)
    {
        for(int j=3;j<=n;j++)
        {
            if(i-j>=0)
            {
                dp[i] += dp[i-j];
                dp[i] %= mod;
            }
        }
    }

    cout << dp[n] << endl;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, m;
  cin >> n >> m;
  vector<long> v(m);
  rep(i, m) {
    long p, y;
    cin >> p >> y;
    v[i] = (p << 32) | y;
  }

  vector<long> sorted_v(v);
  sort(sorted_v.begin(), sorted_v.end());

  rep(i, m) {
    const long p = v[i] >> 32;
    auto it1 = lower_bound(sorted_v.begin(), sorted_v.end(), p << 32);
    auto it2 = lower_bound(it1, sorted_v.end(), v[i]);
    auto d = distance(it1, it2);
    printf("%06ld%06ld\n", p, d + 1); 
  }
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

signed main(){
    int N,M;
    cin >> N >> M;
    
    if(N==M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256