akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

int main()
{
  string s;
  cin >> s;
  int size = s.size();
  int ans = 0;
  for (int i = 0; i < size; i++)
  {
    if (s[i] == 'g')
    {
      ans++;
    }
    else
    {
      ans--;
    }
  }
  cout << ans / 2 << "\n";
}

Measured memory_bytes: 512
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int n;
cin>>n;
vector<ll>v(n);
ll sum=0;
map<ll,ll>mp;
for(auto &x:v)
{
	cin>>x;
	sum+=x;
	mp[x]++;
}
int q;
cin>>q;
while(q--)
{
ll b,c;
cin>>b>>c;
//ll freq=mp[b];
if(mp.find(b)!=mp.end())
{
	ll freq=mp[b];
	sum-=freq*b;
mp.erase(b);
mp[c]+=freq;
sum+=freq*c;
cout<<sum<<endl;
}
else
	cout<<sum<<endl;
}
}
int main()
{
//code
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 7920
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
k=A[0]
ans=k
if(N % 2 ==0):
    l=int((N-2)/2)
    for i in range(l):
        ans+=2*A[i+1]
else:
    l=int((N-3)/2)
    for i in range(l):
        ans+=2*A[i+1]
    ans+=A[l+1]
print(ans)


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

float a[50];
int main(){
	int n;
	cin >> n;
	double sum = 0;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a,a+n);
	for(int i = 0; i < n; i++){
		a[i+1] = (a[i] + a[i+1]) / 2;
	}	
	printf("%f",a[n-1]);
    return 0;  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10LL * TEN(n-1); }

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = TEN(18);
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++) {
            if (b % y) continue;
            ans = min(ans, abs(a - b / y * x));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3088
#include <stdio.h>
#define NUMBER 100
main()
{
	int i, n, x[100];
	scanf("%d\n", &n);
	for (i=0;i<n;i++){
		scanf("%d\n", &x[i]);
		
	}
	for (i=n-1; i>=0; i--){
	 printf("%d", x[i]);
         if (i==0)
		printf("\n");
	 else 
                printf(" ");
}
}



Measured memory_bytes: 2084
n, m, x = gets.split(" ").map &:to_i
a = readlines.map{|i| i.split(' ').map(&:to_i)}
#a.sort_by {|x| x[0]}
ans = -1
aa = Array.new(m+1, 0)
#bit全探索
(1 << n).times{ |is|
  min = -1
  aa.fill(0)
  n.times{ |i|
    if(is>>i&1 == 1)
      count = 0
      (m+1).times{ |j|
        aa[j] += a[i][j]
        if aa[j] >= x && j > 0
          count += 1
        else 
          count = 0
        end
      }
      if count == m
        min = aa[0]
        if ans > min || ans == -1
          ans = min
        end
        break		#最小の組み合わせなのでBreak
      end
    else
      next
    end
  }
}
puts ans


Measured memory_bytes: 14344
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 72

/* Naive 0/1 Trie */

typedef struct trie *trie;
struct trie { trie children[26]; char flag; };

trie trie_cons(char* str, trie t)
{
    if(!t)
        t = (trie)calloc(1, sizeof(struct trie));

    if(*str)
        t->children[*str - 'a'] = trie_cons(str + 1, t->children[*str - 'a']);
    else
        t->flag = 1;

    return t;
}

int trie_count(trie t)
{
    if(!t)
        return 0;
    else
    {
        int res = (t->flag != 0), i;
        for(i = 0; i < 26; i++)
            res += trie_count(t->children[i]);
        return res;
    }
}

void trie_free(trie t)
{
    int i;

    if(t)
    {
        for(i = 0; i < 26; i++)
            trie_free(t->children[i]);
        free(t);
    }
}

/* --- */

void reverse(char* buf, int size)
{
    int i;
    char t;

    for(i = 0; i < size / 2; i++)
    {
        t = buf[i];
        buf[i] = buf[size - i - 1];
        buf[size - i - 1] = t;
    }
}

int main(void)
{
    trie t;
    int split_pos, len, i;
    char buf[MAX_LENGTH + 1], swapped[MAX_LENGTH + 1];

    scanf("%*d%*c");

    while(~scanf("%s%*c", buf))
    {
        t = NULL, len = strlen(buf);

        for(split_pos = 1; split_pos < len; split_pos++)
            for(i = 0; i < 4; i++)
            {
                /* reverse */
                if(i & 2) reverse(buf, split_pos);
                if(i & 1) reverse(buf + split_pos, len - split_pos);

                /* swap */
                memcpy(swapped, buf + split_pos, len - split_pos);
                memcpy(swapped + (len - split_pos), buf, split_pos);
                swapped[len] = '\0';

                /* push to the trie */
                t = trie_cons(buf, trie_cons(swapped, t));

                /* undo reverse */
                if(i & 2) reverse(buf, split_pos);
                if(i & 1) reverse(buf + split_pos, len - split_pos);
            }

        printf("%d\n", trie_count(t));
        trie_free(t);
    }

    return 0;
}

Measured memory_bytes: 5024
#include <iostream>

#include <vector>
#include <string>

using namespace std;

int main()
{
    int k, a, b;

   cin >> k >> a >> b;

   for(int i = 1; i <= 1000; ++i)
   {
       if(k * i >= a)
        {
            if(k * i <= b)
            {
                cout << "OK\n";
                return 0;
            }
            else
            {
                cout << "NG\n";
                return 0;
            }
            
        }
   }

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, x, mi=2000, ans = 0;
  cin >> n >> x;
  for(int i=0; i<n; i++){
    int a; cin >> a;
    if(mi>a) mi = a;
    x -= a;
    ans++;
  }
  ans += x/mi;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    vector<pair<int, int> > p;
    vector<int> point[5001];
    rep (i, n) {
      int x, y;
      cin >> x >> y;
      p.push_back(make_pair(x, y));
      point[x].push_back(y);
    }
    rep (i, 5001) sort(point[i].begin(), point[i].end());
    int res = 0;
    rep (i, p.size()) rep (j, i) {
      int dx = p[j].first - p[i].first;
      int dy = p[j].second - p[i].second;
      int x1 = p[j].first - dy;
      int y1 = p[j].second + dx;
      int x2 = x1 - dx;
      int y2 = y1 - dy;
      if (x1 < 0 || 5000 < x1) continue;
      if (y1 < 0 || 5000 < y1) continue;
      if (x2 < 0 || 5000 < x2) continue;
      if (y2 < 0 || 5000 < y2) continue;
      if (!binary_search(point[x1].begin(), point[x1].end(), y1)) continue;
      if (!binary_search(point[x2].begin(), point[x2].end(), y2)) continue;
      res = max(res, dx * dx + dy * dy);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1436
import sys
input=sys.stdin.readline
n=int(input())
pointx=[]
pointy=[]
for i in range(n):
    x,y=map(int,input().split())
    pointx.append((x,i))
    pointy.append((y,i))
pointx.sort()
pointy.sort()
G=[[] for i in range(n)]
for i in range(n-1):
    dx=abs(pointx[i+1][0]-pointx[i][0])
    G[pointx[i][1]].append((dx,pointx[i+1][1]))
    G[pointx[i+1][1]].append((dx,pointx[i][1]))
    dy=abs(pointy[i+1][0]-pointy[i][0])
    G[pointy[i][1]].append((dy,pointy[i+1][1]))
    G[pointy[i+1][1]].append((dy,pointy[i][1]))
import heapq
q=[]
check=[False]*n
check[0]=True
for i in G[0]:
    heapq.heappush(q,i)
ans=0
while len(q)>0:
    now=heapq.heappop(q)
    if not check[now[1]]:
        ans+=now[0]
        check[now[1]]=True
        for i in G[now[1]]:
            heapq.heappush(q,i)
print(ans)




Measured memory_bytes: 119900
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
use std::cmp::*;
//use std::num;

fn main() {
    input! {
        L:f64
    }
    println!("{}", (L / 3f64).powf(3f64));
}


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _xx ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int MAXN=1e2+5;
bool vis[MAXN],match[MAXN][MAXN];
int girl[MAXN];
bool dfs(int x, int n){
    for(int j = 1; j <= n; j++){
        if(match[x][j] && !vis[j]){
            vis[j] = true;
            if (girl[j]==0||dfs(girl[j], n)){
                girl[j]=x;
                return true;
            }
        }
    }
    return false;
}
int solve(int m,int n)
{
    int ans=0;
    for(int i=1;i<=m;i++){
        memset(vis,0,sizeof(vis));
        if(dfs(i,n)) ans++;
    }
    return ans;
}
int main()
{
    int n,x[105],y[105];
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(int i=1;i<=n;i++){
        int xx,yy;
        cin>>xx>>yy;
        for(int j=1;j<=n;j++){
            if(x[j]<xx && y[j]<yy) match[j][i]=true;
        }
    }
    cout<<solve(n,n)<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pllint a, pllint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	rep(i, s.size()) {
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int N,R,K;
  scanf("%d",&K);
  if(K<10)
    R=100*(10-K);
  else
    R=100*0;
  scanf("%d",&N);
  printf("%d\n",R+N);
  
  return 0 ;
}
    

Measured memory_bytes: 128
import sys
import math
from itertools import permutations
from itertools import combinations

#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
S = input()

l = []
for s in S:
    neww = chr(ord('A') + (( ord(s) - ord('A') + N )%26))
    l.append(neww)

print(''.join(l))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
	char n[200001]={};
	cin>>n;
	int k=strlen(n);
	int ans=0;
	for(int i=0; i<k; i++){
		ans+=int(char(n[i]))-int(char('0'));
	}
	if(ans%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int c[105][105];

int main() {
  int h,w,n;
  cin >> h >> w >> n;
  int a[n];
  FOR(i,0,n-1) cin >> a[i];

  int refh = 0;
  int refw = 0;
  int refa = 0;

  while(refh<=h-1){
    // cout << "test" << endl;
    if(refh%2==0){
      // cout << "test" << endl;
      // cout << refh << " " << refw << endl;
      // cout << c[refh][refw] << endl;
      c[refh][refw] = refa + 1;
      // cout << c[refh][refw] << endl;
      --a[refa];
      ++refw;
    }
    else{
      // cout << "test2" << endl;
      c[refh][refw] = refa + 1;
      --a[refa];
      --refw;
    }



    if(a[refa]<=0) ++refa;
    if(refw == -1){
      ++refw;
      ++refh;
    }
    if(refw == w){
      --refw;
      ++refh;
    }
  }


  FOR(i,0,h-1){
    FOR(j,0,w-1){
      cout << c[i][j] << " ";
    }
    cout << endl;
  }


}



Measured memory_bytes: 384
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    ll h, w;
    cin >> h >> w;
    
    if (h == 1 || w == 1) cout << 1 << endl;
    else cout << (h * w + 1) / 2 << endl;
    return 0;
}

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

ll getSum(ll n)
{
    ll t = 0;
    while(n > 0){
        t += n % 10;
        n /= 10;
    }
    return t;
}
int main()
{
    ll n, k = 0;
    cin >> n;
    k = getSum(n);
    if(n % k == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

void main_()
{
    ll N;
    cin >> N;

    queue<ll> que;
    for (int i = 1; i < 10; ++i) {
        que.push(i);
    }

    N--;
    while (N--) {
        auto n = que.front();
        que.pop();
        for (int i = max(n % 10 - 1, 0LL); i <= min(n % 10 + 1, 9LL); i++) {
            que.push(n * 10 + i);
        }
    }

    cout << que.front() << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 4744
#include <cstdio>
 
using lint = long long;
 
int main(){
    lint n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    if(a>b){
    	puts("0");
    	return 0;
    }
  	if(n==1LL){
        if(a==b)puts("1");
        else puts("0");
        return 0;
    }
    if(n==2LL){
        puts("1");
        return 0;
    }
    lint l = a * (n-1) + b;
    lint g = b * (n-1) + a;
    printf("%lld\n",g-l+1);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;

}


Measured memory_bytes: 3632
n = int(input())
TARO = HANAKO = 0
for i in range(n):
    taro, hanako = input().split()
    if taro == hanako:
        TARO += 1
        HANAKO += 1
    elif taro > hanako:
        TARO += 3
    elif taro < hanako:
        HANAKO += 3
print(TARO, HANAKO)

Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <numeric>
#include <iterator>
using namespace std;


int main()
{
    int a, b, k, ans;
    vector<int> veca, vecb;
    cin >> a >> b >> k;
    for (int i = 1; i <= a; i++) {
        if (a % i == 0) veca.push_back(i);
    }
    for (int i = 1; i <= b; i++) {
        if (b % i == 0) vecb.push_back(i);
    }
    vector<unsigned int> list_inter; //list1とlist2の両方にある値 (積集合)
    set_intersection(veca.begin(), veca.end(), vecb.begin(), vecb.end(), back_inserter(list_inter));
    sort(list_inter.begin(), list_inter.end(), greater<int>());
    cout << list_inter[k-1] << endl;
}


Measured memory_bytes: 256
#include <utility>
#include <bitset>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <ios>
#include <iomanip>
#include <sstream>
#include <climits>
#include <cmath>

using namespace std;

#ifdef USE_LOG
#define LOG(str)  cout << str << endl
#define DMP(var)  cout << #var << " = " << var << endl
#else
#define LOG(...)
#define DMP(...)
#endif

#define FOR(v, b, e)   for (int v = (b); v < (e); ++v)
#define RFOR(v, b, e)  for (int v = (e) - 1; (b) <= v; --v)
#define REP(v, n)      FOR(v, 0, n)
#define RREP(v, n)     RFOR(v, 0, n)

#define ALL(c)         (c).begin(), (c).end()

typedef long long           ll;
typedef unsigned long long  ull;

bool ans (int a[3], int b[3], int c[3][3]) {
	REP (i, 3)
	REP (j, 3) {
		if (c[i][j] != (a[i] + b[j])) {
			return false;
		}
	}
	return true;
}

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

	int a[3] = {};
	int b[3] = {};
	int c[3][3] = {};

	REP (i, 3)
	REP (j, 3) {
		cin >> c[i][j];
	}

	b[0] = c[0][0];
	b[1] = c[0][1];
	b[2] = c[0][2];

	a[0] = c[0][0] - b[0];
	a[1] = c[1][0] - b[0];
	a[2] = c[2][0] - b[0];

	if (ans(a, b, c)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
long long int gcd(long long int a,long long int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
 
int main()
{
	long long int n; cin>>n;
	long long int a[1000001];
	for(long long int i=0;i<n;i++) cin>>a[i];
	
	long long int l[1000001],r[1000001];
	
	l[0]=a[0],r[n-1]=a[n-1];
	
	for(long long int i=1,j=n-2;i<n;i++,j--)
	{
	   l[i]=gcd(l[i-1],a[i]);
	   r[j]=gcd(r[j+1],a[j]);
	}
	long long int m=0;
	for(long long int i=1;i<=n-2;i++) m=max(m,gcd(l[i-1],r[i+1]));
	
	m=max(m,l[n-2]);
	m=max(m,r[1]);
	cout<<m<<endl;
}

Measured memory_bytes: 9216
// inputに入力データ全体が入る
function Main(input) {
  var input = input.split('\n');
  var answer;

  var nums = input[0].split(' ');
  nums = nums.map(e => parseInt(e));
  var n = nums[0];
  var a = nums[1];
  var b = nums[2];

  function matches(x) {
    return (x >= a && x <= b);
  }

  function sumOfDigits(x) {
    var digits = x.toString(10).split('');
    var sum = 
      digits.reduce((ac, v) => parseInt(ac) + parseInt(v));
    return sum;
  }

  answer = 0;

  for (var i = 1; i <= n; i++) {
    var sum = sumOfDigits(i);

    if (matches(sum)) {
      answer += i;
    }
  }


  // 出力
  console.log(answer);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 22916
#include <bits/stdc++.h>
using namespace std;
int A, B, C;
int main()
{
	scanf("%d%d%d", &A, &B, &C);
	int Ans = -1, x, y, z;
	while (1)
	{
		++ Ans;
		if ((A & 1) || (B & 1) || (C & 1)) { printf("%d\n", Ans); return 0; }
		if (A == B && B == C) { puts("-1"); return 0; }
		x = (A >> 1) + (B >> 1);
		y = (A >> 1) + (C >> 1);
		z = (C >> 1) + (B >> 1);
		A = x, B = y, C = z;
	}
	return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll r,d,x;
  cin>>r>>d>>x;
  rep(i,0,10){
    x = r*x-d;
    cout<<x<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2018/03/11
 *      Author: sep
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

inline int main001();
inline int main002();
inline int main003();
inline int main004();


int main() {

		main001();

	return 0;
}

inline int main001() {

	int i;
	string str[3];

	for (i = 0; i < 3; i++)
		cin >> str[i];

	for (i = 0; i < 3; i++)
		cout << str[i][i];

	return 0;

}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	int tc; cin>>tc;
	while(tc--){
		vector<ll> n(9);
		rep(i,9) cin>>hex>>n[i];
		
		ll res=0;
		rep(i,32){
			ll sum=0;
			rep(j,8) sum+=(n[j]^res);
			if(((n[8]^res)&1ll<<i)!=((sum^res)&1ll<<i))
				res|=1ll<<i;
		}
		cout<<hex<<res<<endl;
	}
}

Measured memory_bytes: 1196
use std::collections::VecDeque;
use std::collections::HashSet;

fn main(){
  loop {
    let wh: Vec<usize> = read_vec();
    let w = wh[0];
    let h = wh[1];
    
    if w == 0 && h == 0 { break; }
    
    let txy: Vec<usize> = read_vec();
    let tx = txy[0] - 1;
    let ty = txy[1] - 1;
    let kxy: Vec<usize> = read_vec();
    let kx = kxy[0] - 1;
    let ky = kxy[1] - 1;
    let mut d : Vec<Vec<usize>> = Vec::new();
    
    for _ in 0 .. h {
      d.push(read_vec());
    }
    
    let mut que: VecDeque<((usize, usize), (usize, usize), usize)> = VecDeque::new();
    let mut set: HashSet<(usize, usize, usize, usize)> = HashSet::new();

    que.push_back(((tx, ty), (kx, ky), 0));
    set.insert((tx, ty, kx, ky));

    loop {
      match que.pop_front() {
        Some(((x1, y1), (x2, y2), wk)) => {
          if wk >= 100 { continue; }
          
          if x1 == x2 && y1 == y2 {
            println!("{}", wk);
            break;
          }
          
          let nx1 = if x1 < w - 1 && d[y1][x1+1] == 0 { x1 + 1 } else { x1 };
          let nx2 = if x2 > 0 && d[y2][x2-1] == 0 { x2 - 1 } else { x2 };
          if !set.contains(&(nx1, y1, nx2, y2)) {
            que.push_back(((nx1, y1), (nx2, y2), wk + 1));
            set.insert((nx1, y1, nx2, y2));
          }
          
          let nx1 = if x1 > 0 && d[y1][x1-1] == 0 { x1 - 1 } else { x1 };
          let nx2 = if x2 < w - 1 && d[y2][x2+1] == 0 { x2 + 1 } else { x2 };
          if !set.contains(&(nx1, y1, nx2, y2)) {
            que.push_back(((nx1, y1), (nx2, y2), wk + 1));
            set.insert((nx1, y1, nx2, y2));
          }
          
          let ny1 = if y1 < h - 1 && d[y1+1][x1] == 0 { y1 + 1 } else { y1 };
          let ny2 = if y2 > 0 && d[y2-1][x2] == 0 { y2 - 1 } else { y2 };
          if !set.contains(&(x1, ny1, x2, ny2)) {
            que.push_back(((x1, ny1), (x2, ny2), wk + 1));
            set.insert((x1, ny1, x2, ny2));
          }
          
          let ny1 = if y1 > 0 && d[y1-1][x1] == 0 { y1 - 1 } else { y1 };
          let ny2 = if y2 < h - 1 && d[y2+1][x2] == 0 { y2 + 1 } else { y2 };
          if !set.contains(&(x1, ny1, x2, ny2)) {
            que.push_back(((x1, ny1), (x2, ny2), wk + 1));
            set.insert((x1, ny1, x2, ny2));
          }
        },
        None => {
          println!("NA");
          break;
        },
      }
    }
  }
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 20648
#include <bits/stdc++.h>
using namespace std;
void File()
{
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
}
void yAsEr_HaFiz() {
    //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);

 ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 }



typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<long, long> mll;
typedef set<int> si;
typedef set<string> st;
typedef set<long> sl;
typedef pair<int, int> pii;
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define setzero(a)	memset(a,0,sizeof(a))
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define el      	 "\n"
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define ndl puts("")
#define SS stringstream
#define ll long long
#define endl '\n'
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };




int const N = 5e5 + 9, MOD = 1e9+7 , oo = 1e9+7;
//------------------------------------------------------------------------------------






int index1,index2;


int main()
{
    yAsEr_HaFiz();
string str;

cin>>str;
int n=str.size();
if (n==1)return cout<< 0,0;
int i;
for (i=0;i<n;i++){
    if (str[i]=='A'){
        index1=i;
break;
    }
}
for (i=0;i<n;i++){
    if (str[i]=='Z'){
        index2=i;
    }
}
cout<< index2-index1+1;







    /*
    */
return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t a,b,c; char u; cin>>a>>b>>u>>c;
	b*=100; b+=c;
	cout<<a*b/100<<"\n"s; 
}

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

class Cmondai
{
    static void Main()
    {
        var nk = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = nk[0];
        var K = nk[1];
        var A = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var array = new int[200001];
        for (int i=0;i<N;++i) array[A[i]]++;
        var ans=array.OrderBy(x => x).Take(200001-K).Sum(); 
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 34860
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 		
 	int n ; 
 	cin >> n ; 
 	map<int,int> present ;
 	bool ok = 1 ; 
 	vt<int> a(n) ; 
 	rep(i,0,n) {
 		cin >> a[i] ; 
 		if(present[a[i]]) 
 			ok = 0 ; 
 		present[a[i]]++; 
 	}
 	if(ok) {
 		cout << "YES" ; 
 	} else {
 		cout << "NO" ; 
 	}


	return 0 ; 
}

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

int main(){
    int N, K, sum;
    vector<int> l;
    cin >> N >> K;
    l.resize(N);
    for(int i=0;i<N;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    sum = 0;
    for(int i=0;i<K;i++){
        sum += l[N - 1 - i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
vi dy = { 0,0,1,-1 };
vi dx = { 1,-1,0,0 };
constexpr auto INF = INT_MAX/2;
constexpr auto INFL = 5000000000000000;
constexpr auto MOD = 1000000007;

int n, WW;
vi w,v;
vector<vector<ll>> memo;

ll dp(int x, int y) {

	if (memo[x][y] != INFL)return memo[x][y];

	if (x == 0) {
		if (w[x] <= y)return (ll)v[x];
		else return 0;
	}

	ll re;
	if (y - w[x] < 0) re = dp(x - 1, y);
	else re = max(dp(x - 1, y), dp(x - 1, y - w[x]) + v[x]);
	memo[x][y] = re;
	return re;
}

int main() {
	cin >> n >> WW;
	w.resize(n);
	v.resize(n);
	rep(i, n)cin >> w[i] >> v[i];

	memo.assign(n, vector<ll>(WW+1, INFL));
	
	cout << dp(n-1,WW) << endl;
}

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

int main(int argc, char* argv[]){
    int N;
    string S;
    int K;

    cin >> N >> S >> K;

    for(auto&& s: S){
        if (s == S[K-1]){
            cout << s;
        } else {
            cout << '*';
        }
    }
    cout << endl;

    return 0; 
}

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

int main(){
    int a,b;
    cin >> a >> b;
    for(int i = 1; i <= 3; i++)
    {
        if ((a*b*i)%2 == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,s;
  cin>>k>>s;
  int count=0;
  for(int a=0;a<=k;a++){
    for(int b=0;b<=k;b++){
      int x=s-a-b;
      if(x>=0&&x<=k){count++;}
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    // Your code here!
    int n,m;
    cin>>n>>m;
    int A[n+1][m+1];
    int B[m+1];
    
    //初期化
    for(int i=0; i<n+1; i++){
        for(int j=0; j<m+1; j++)
        A[i][j]=0;
    }
    
    for(int i=0; i<m+1; i++){
        B[i]=0;
    }
    
    
    //代入
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            cin>>A[i][j];
        }
    }
    
    for(int i=1; i<=m; i++){
        cin>>B[i];
    }
    
    //出力
    for(int i=1; i<=n; i++){
        int sum=0;
        for(int j=1; j<=m; j++){
            sum+=A[i][j]*B[j];
        }
        cout<<sum<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3128
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String nl = System.getProperty("line.separator");
		StringBuilder p = new StringBuilder(500);
		StringBuilder d = new StringBuilder(".");
		StringBuilder s = new StringBuilder("#");
		StringBuilder k = new StringBuilder(50);
		Scanner r = new Scanner(System.in);
		int h, w, ww = 0;
		String u;
		while (4 > ww++) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while (0 < (h = r.nextInt()) + (w = r.nextInt())) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(u = s.substring(0, w)).append(nl);
			k.setLength(0);
			k.append(d.substring(0, w)).append(nl)
			.replace(0, 1, "#").replace(w - 1, w, "#");
			while (2 < h--) {
				p.append(k);
			}
			p.append(u).append(nl).append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18344
s=input()
t=input()
ls=len(s)
lt=len(t)

ans=0
for i in range(ls-lt+1):
  x=s[:i]+t+s[i+lt:ls]
  f=1
  for j in range(ls):
    if s[j]=='?':
      continue
    if s[j]!=x[j]:
      f=0
      break
  if f:
    p=''
    for k in range(ls):
      if x[k]=='?':
        p+='a'
      else:
        p+=x[k]
    ans=p
    
if ans:
  print(p)
else:
  print('UNRESTORABLE')
    

Measured memory_bytes: 9032
//ysh_gpta
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
#define vb vector<bool>
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define mkp make_pair
#define pb push_back
#define INF 1000000000000000
#define MOD 1000000007
#define ff first
#define ss second
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//ll gcd( ll a, ll b ){if(b==0) return a; else return gcd( b, a%b );}
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
//void printArray(vi &v){for(int i=0;i<v.size();i++) cout<<v[i]<<endl; cout<<endl; }
ll n;

ll dp[3005][3005][2];

ll solve(ll i,ll j,bool t,vi &v){
    if(i>j) return 0;
    if(dp[i][j][t]!=-1)
    return dp[i][j][t];
    if(t){
        return dp[i][j][t] = max(solve(i+1,j,!t,v)+v[i],solve(i,j-1,!t,v)+v[j]);
    }else{
        return dp[i][j][t] = min(solve(i+1,j,!t,v)-v[i],solve(i,j-1,!t,v)-v[j]);
    }
}

int main(){
   FastIO
   
   cin>>n;
   vi v(n);
   for(int i=0;i<n;i++)
   cin>>v[i];
   memset(dp,-1,sizeof(dp));
   cout<<solve(0,n-1,true,v);
   return 0;
}

Measured memory_bytes: 141568
S = input()

m = {}

for c in S:
  if c in m:
    m[c] += 1
  else:
    m[c] = 1

if len(m) != 2:
  print("No")
  exit()

for k, v in m.items():
  if v != 2:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 3060
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    N, M = in_nn()
    X = list(in_nn())
    Y = list(in_nn())

    x_tsum = [0] * (N + 1)
    for i in range(N):
        x_tsum[i + 1] += x_tsum[i] + X[i]
        x_tsum[i + 1] %= MOD

    x_sum = 0
    for i in range(1, N):
        x_sum += X[i] * i - x_tsum[i]
        x_sum %= MOD

    y_tsum = [0] * (M + 1)
    for i in range(M):
        y_tsum[i + 1] += y_tsum[i] + Y[i]
        y_tsum[i + 1] %= MOD

    y_sum = 0
    for i in range(1, M):
        y_sum += Y[i] * i - y_tsum[i]
        y_sum %= MOD

    print(x_sum * y_sum % MOD)


if __name__ == '__main__':
    main()


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

int ans[100005];
vector<vector<int>> G(100005);
int N,M;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cin >> N >> M;
    int a,b;
    for(int i=0;i<M;++i) {
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(ans,-1,sizeof(ans));
    queue<int> q;
    q.push(1);
    ans[1] = 0;
    int cnt = 1;
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        for(auto nxt:G[cur]) {
            if(ans[nxt] == -1) {
                ans[nxt] = cur;
                q.push(nxt); ++cnt;
            }
        }
    }
    if(cnt != N) cout << "No" << '\n';
    else {
        cout << "Yes" << '\n';
        for(int i=2;i<=N;++i) cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 10188
/************************* In the name of Allah *************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef string          str;
typedef pair<ll,ll>     pll;

#define F               first
#define S               second
#define pb              push_back
#define sep             ' '
#define endl            '\n'
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MOD = 1e9 + 7,
         INF = 1e18,
         MAXN = 1e5 + 10;

const int N = 1e2 + 10;

int a[N], b[N];

int main(){
    fast_io
    int n;
    cin >> n;
    for (int i = 1; i < n; i ++)
        cin >> a[i];
    a[n] = 1e5 + 100;
    b[1] = a[1];
    //b[2] = a[1];
    for (int i = 2; i <= n; i ++)
        b[i] = min(a[i - 1], a[i]);
    int ans = 0;
    for (int i = 1; i <= n; i ++)
        ans += b[i];
    cout << ans;
    return 0;
}

/*
 __  __       _         _ _  _____ _           _                __ _
|  \/  |     | |       | (_)/ ____| |         | |              / _(_)
| \  / | __ _| |__   __| |_| (___ | |__   ___ | | _____  _   _| |_ _
| |\/| |/ _` | '_ \ / _` | |\___ \| '_ \ / _ \| |/ / _ \| | | |  _| |
| |  | | (_| | | | | (_| | |____) | | | | (_) |   < (_) | |_| | | | |
|_|  |_|\__,_|_| |_|\__,_|_|_____/|_| |_|\___/|_|\_\___/ \__,_|_| |_|
*/


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';
ll const mod = 998244353;

int main() {
    int n,k;
    cin >> n >> k;
    vector<ll> dp(n+2,0);
    vector<int> l(k),r(k);
    for (int i = 0;i < k;++i) cin >> l[i] >> r[i];
    dp[0] = 1;
    dp[1] = -1;
    for (int i = 0;i < n;++i) {
        for (int j = 0;j < k;++j) {
            int u = i+l[j],v = min(i+r[j],n);
            if (u > n) continue;
            (dp[u] += dp[i]) %= mod;
            (dp[v+1] += -dp[i]) %= mod;
        }
        (dp[i+1] += dp[i]) %= mod;
        // p_ary(dp,0,n+2);
    }
    cout << (dp[n-1]+mod)%mod << newl;
}

Measured memory_bytes: 4764
# アライグマはモンスターと戦っています。モンスターの体力はHです。
# アライグマはN種類の必殺技を使うことができ、i番目の必殺技を使うとモンスターの体力を Ai
# 減らすことができます。 必殺技を使う以外の方法でモンスターの体力を減らすことはできません。
# モンスターの体力を0以下にすればアライグマの勝ちです。
# アライグマが同じ必殺技を2度以上使うことなくモンスターに勝つことができるなら Yes を、
# できないなら No を出力してください。

H, N = map(int, input().split())
damege = map(int, input().split())

total_damege = sum(damege)

if H - total_damege <= 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 17276
from collections import Counter
import bisect


S = input()
S = S + S
T = input()
SC = Counter(S)
TC = Counter(T)
A = [[] for _ in range(150)]

for t in TC.keys():
    if t not in SC:
        print(-1)
        exit()

for i, s in enumerate(S):
    A[ord(s)].append(i)

N = len(S) // 2
ans = 0
now = -1

for t in T:
    At = A[ord(t)]
    x = bisect.bisect_left(At, now)
    now = At[x]
    if now + 1 >= N:
        ans += 1
    now += 1
    now %= N

print(ans * N + now)


Measured memory_bytes: 51820
#include<stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);

    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2084
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define isz(x) (int)(x).size()
using ll = long long;
ll solve(ll n) {
    if (n <= 2) return 0;
    if (n % 2 == 1) return 0;
    // (2n)!! = 2^n * n!
    n /= 2;
    ll n5 = 0, pow5 = 5;
    while (n / pow5 > 0) {
        n5 += n / pow5;
        pow5 *= 5;
    }
    return n5;
}
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
	for (ll n; std::cin >> n; std::cout << solve(n) << std::endl);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
void solve(){//素数3個かけるものは210以上なので範囲外
//素数^7: 128のみ→偶数でout
vector<bool> is_8(201);
//3 * 5 * 素数
is_8.at(105) = 1;
is_8.at(165) = 1;
is_8.at(195) = 1;
//素数^3 * 素数
is_8.at(135) = 1;
is_8.at(189) = 1;
int n;
cin >> n;
int ans = 0;
for(int i = 0; i <= n; i++){
    ans += is_8.at(i);
}
cout << ans << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
// #include <functional>

using namespace std;

void solve()
{
    // 入力の処理
    int N;
    cin >> N;
    vector<int> a(N);

    int c = 1;
    int crashcount = 0;
    int cfind = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
        if (a.at(i) == c)
        {
            c++;
            cfind = 1;
        }
        else
        {
            crashcount++;
        }
    }

    if (cfind == 0)
    {
        cout << "-1" << endl;
    }
    else
    {
        cout << crashcount << endl;
    }

    return;
}

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


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n; cin >> n, n;){
        vs tree(n);
        rep(i, n){
            cin >> tree[i];
        }

        rep(i, n){
            int ind = 0;
            rep(j, tree[i].size()){
                if(tree[i][j] == '.'){
                    tree[i][j] = ' ';
                    
                    if(tree[i][j + 1] != '.'){
                        tree[i][j] = '+';
                        ind = j;
                    }
                }
                else break;
            }

            int j = i;
            while(0 <= --j && tree[j][ind] == ' '){
                tree[j][ind] = '|';
            }
        }

        rep(i, n){
            cout << tree[i] << endl;
        }
    }

	return 0;
}

Measured memory_bytes: 1856
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 1e9
using namespace std;
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}

typedef long long ll;
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;
}

#pragma endregion

int main() {
  int n = in(), a = in(), b = in();
  string s = in<string>();

  int countAB = 0;
  int countB = 0;
  rep(i, n) {
    switch (s[i]) {
      case 'a':
        if (countAB < a + b) {
          countAB++;
          cout << "Yes" << endl;
        } else {
          cout << "No" << endl;
        }
        break;
      case 'b':
        if (countAB < a + b && countB < b) {
          countAB++;
          countB++;
          cout << "Yes" << endl;
        } else {
          cout << "No" << endl;
        }
        break;
      case 'c':
        cout << "No" << endl;
        break;
    }
  }
  return 0;
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main() {
    int N, M;
    int num[30] = {0};
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        int K; cin >> K;
        for (int j = 0; j < K; j++) {
            int tempnum;
            cin >> tempnum;
            tempnum--;
            num[tempnum]++;
        }   
    }   
    int ans = 0;
    for (int i = 0; i < M; i++) {
        if (num[i] == N) ans++;
    }   
    cout << ans << endl;
}

Measured memory_bytes: 256