akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{long long i,j,k,l,m,n,x,y,t,z,sum;
string s;
cin>>s;
n=s.size();
if(s[n-1]=='s')s=s+"es";
else s=s+"s";
cout<<s;
return 0;}


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

int main(){
  int n;
  std::cin >> n;
  int ans=0;
  for (int i = 1; i <= n; i++) {
    int now;
    std::cin >> now;
    if(i%2==1 && now%2==1)ans++;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,l,r) for(int i=(l);i<(r);i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// g++ -std=c++11 prac.cpp 

int main(){
    ll x=0,y=0,z=0,n,m=0,k,h,ans=0,w,sum=1,Max=-1e9-1,cnt=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n;
    VI a(n),c(3);
    rep(i,n) { cin >> a[i]; }
    rep(i,n){
        ll id = -1;
        if(a[i] == c[0]) { cnt++; id=0; }
        if(a[i] == c[1]) { cnt++; id=1; }
        if(a[i] == c[2]) { cnt++; id=2; }
        if(id == -1){
            cout << 0 << endl;
            return 0;
        }
        sum *= cnt;
        c[id]++;
        sum %= mod;
        cnt = 0;
    }
    cout << sum << endl;
    return 0;    
}
 


 

Measured memory_bytes: 640
#include <iostream>

#define repeat_with_index(n, i) for(int i=0;i<n;i++)
#define repeat(n) for(int __i=0;__i<n;__i++)
#define repete_from_to(from, to, i) for(int i=from;i<=to;i++)
#define multi_cin(n, array) repeat_with_index(n,i){cin>>array[i];}
#define assign_if_smaller(var, val) if(var>val)var=val;
#define assign_if_larger(var, val) if(var<val)var=val;

using namespace std;

int coin_value[] = {1, 5, 10, 50, 100, 500};

int pay_count(int price, int *coins) {
  int count = 0;

  repeat_with_index(6, i) {
    int _count = min(price / coin_value[5 - i], coins[5 - i]);
    price -= _count * coin_value[5 - i];
    count += _count;
  }

  if (price != 0) return -1;

  return count;
}

int change_count(int price) {
  int count = 0;

  repeat_with_index(6, i) {
    int _count = price / coin_value[5 - i];
    price -= _count * coin_value[5 - i];
    count += _count;
  }

  return count;
}

int main(int argc, char const* argv[])
{
  while (true) {
    int price; cin >> price;
    if (price == 0) break;

    int coins[6];
    multi_cin(6, coins);

    int count = 6000;

    repete_from_to(price, price + 499, p) {
      int p_count = pay_count(p, coins);
      if (p_count == -1) continue;

      int c_count = change_count(p - price);

      assign_if_smaller(count, p_count + c_count);
    }

    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int r, D, x;

    Scd3(r,D,x);

    Rep(i,10){
        x = x * r - D;
        printf ("%d\n", x );
    }

    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    k, t = list(map(int, input().strip().split()))
    v = list(map(int, input().strip().split()))
    v.sort(reverse=True)
    if len(v) > 1:
        print(v[0]-1 - min(v[0]-1, sum(v[1:])))
    else:
        print(v[0]-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    a -= b;
    cout << a%c;
    cout << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
string S[200000];
int main(){
  int i;
  wmem = memarr;
  int res = 1;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  sort(S,S+N);
  for(i=(1);i<(N);i++){
    if(S[i] != S[i-1]){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200419-1

// --- original code ---
// int N;
// string S[2d5];
// {
//   int res = 1;
//   rd(N,S(N));
//   sort(S,S+N);
//   rep(i,1,N) if(S[i] != S[i-1]) res++;
//   wt(res);
// }


Measured memory_bytes: 10912
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
const int N=1e5+5;
ll a[N]={0};
int main()
{
  ll n;
  CloseIo;
  cin>>n;
  rep(i,0,n)
  cin>>a[i];
  

  	 ll ans=0;
  	 ll flag=1;
  	 rep(j,0,n)
  	 {
  	 	ans+=(a[j]*flag);
  	 	flag=-flag;
	   }
   vector<ll>v;
   v.push_back(ans);
  for(int i=0;i<n-1;i++)
  {
  	ans=2*a[i]-ans;
  	//printf("%lld",ans);
  	v.push_back(ans);
  }
  for(int i=0;i<v.size();i++)
  {
  	 printf("%lld%s",v[i],i==v.size()-1?"":" ");
  }
}




Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int X, Y, Z;
  scanf("%d", &X);
  scanf("%d", &Y);
  scanf("%d", &Z);
  printf("%d %d %d\n", Z, X, Y);
  return 0;
}


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

int main(void) {
  long int num;
  vector<int> a;

  cin >> num;
  for(int i = 0; i < num; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  sort(a.begin(), a.end());
  long int sum = 0;
  for(int i = 0; i < num; i++) {
    sum += a[i];
  }

  cout << a.front() << " " << a.back() << " " << sum << endl;
}


Measured memory_bytes: 3268
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc;
vector<ll> va,vb,vc;

int main(){
    cin>>a>>ca>>b;
    if(ca=='+')c=a+b;
    else c=a-b;
    C(c);
}

Measured memory_bytes: 256
import java.util.*;
class Main{
 public static void main(String[]  args){
  Scanner sc = new Scanner(System.in);
   char ch = sc.next().charAt(0);
   if(Character.isUpperCase(ch))
     System.out.println("A");
   else
     System.out.println("a");
   
   
 }
  
  
  
}

Measured memory_bytes: 35644
/*
 * main.c
 *
 *  Created on: 2020/07/28
 *      Author: 113896
 */
#include <stdio.h>
#include <string.h>

#define BSIZE 2000

int main() {

	char buffer[BSIZE];
	fgets(buffer, BSIZE, stdin);

	int length = 0;
	while (buffer[length] != '\0') {
		length++;
	}
	char out[length+1];
	strncpy(out, buffer, length+1);

	char c;
	for (int i = 0; i < length; i++) {
		c = out[i];
		if (c >= 'a' && c <= 'z') {
			out[i] = c - 'a' + 'A';
		} else if (c >= 'A' && c <= 'Z') {
			out[i] = c - 'A' + 'a';
		}
	}

	printf("%s", out);

	return 0;
}




Measured memory_bytes: 2056
#include<iostream>

int main()
{

	int N, A, B;
	std::cin >> N >> A >> B;
	
	if(( B - A + 1) % 2 == 0 )
	{
		std::cout << "Borys";
	}
	else
	{
		std::cout << "Alice";
	}



}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vi a(N);
    vvi app(20);

    for (int i = 0; i < N; i++) {
        cin >> a[i];
        for (int j = 0; j < 20; j++) if (a[i] & (1 << j)) {
            app[j].push_back(i);
        }
    }

    for (int i = 0; i < 20; i++) {
        app[i].push_back(N);
        app[i].push_back(N);
    }

    ll ans = 0;

    for (int i = 0; i < N; i++) {
        int stop = N;
        for (int j = 0; j < 20; j++) {
            auto it = lower_bound(all(app[j]), i);
            stop = min(stop, *next(it));
        }
        ans += stop - i;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
using Int = long long;
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    string s[3]; cin >> s[0] >> s[1] >> s[2];
    int turn = 0;
    for (;;) {
        if (s[turn].size() == 0) {
            cout << "ABC"[turn] << endl;
            break;
        }
        char head = s[turn][0];
        s[turn].erase(s[turn].begin());
        if (head == 'a') turn = 0;
        else if (head == 'b') turn = 1;
        else turn = 2;
    }
    return 0;
}

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

int main() {
  int A, B, C; cin >> A >> B >> C;
  set<int> S;
  for (int i = 0; i < B; i++) {
    S.insert((A*i)%B);
  }
  if (S.count(C))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
program main

  implicit none

  integer(8) :: i, j , ii, jj
  integer(8) :: ij, k, tmp, jjtmp

  read(*,*) i, j

  if( i > j ) then
    ii = i
    jj = j
  else
    ii = j
    jj = i
  end if

  do
    tmp = int( mod(ii,jj) )
    if( tmp == 0 ) then
      jjtmp = jj
      exit
    end if
    ii = jj
    jj = tmp
  end do

  tmp  = i*j/jjtmp
  !tmp  = int( i*j/jjtmp )
  write( 6, "(1p,I20)") tmp
  !print*, tmp

end program main

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const lb PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll p[n],q[n];
  rep(i,0,n)cin>>p[i];
  rep(i,0,n)cin>>q[i];

  ll per[n];rep(i,0,n)per[i]=i+1;

  ll pnum=0,qnum=0;
  ll count=0;
  do{
    count++;
    bool pe=true,qe=true;
    rep(i,0,n){
      if(p[i]!=per[i])pe=false;
      if(q[i]!=per[i])qe=false;
    }

    if(pe)pnum=count;
    if(qe)qnum=count;


  }while(next_permutation(per,per+n));

  out(abs(pnum-qnum));


  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<Work> work = new ArrayList<>();
//        Work work[] = new Work[n];
        for (int i = 0; i < n; i++) {
            int time = Integer.parseInt(sc.next());
            int limit = Integer.parseInt(sc.next());
            work.add(new Work(time, limit));
        }
        sc.close();
        work.sort(Comparator.comparingInt(x -> x.limit));
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += work.get(i).time;
            if (ans > work.get(i).limit) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

    static class Work {
        int time;
        int limit;

        Work(int time, int limit) {
            this.time = time;
            this.limit = limit;
        }
    }
}

Measured memory_bytes: 73452
import std.stdio;
import std.conv;
import std.string;
import std.algorithm; 
import std.file;
import std.math;

int main() {
	string l;
	while((l = readln().chomp, l.length)){
		int[] a;
		foreach(string s; l.split()) a ~= to!int(s);
		sort!("a > b")(a);
		string[] b;
		foreach(int i; a) b ~= to!string(i);
		write(b.join(" ") ~ "\n");
		}
	return 0;
	}

Measured memory_bytes: 1096
import numpy as np
card = []
for _ in range(3):
  card.append(list(map(int, input().split())))

N = int(input())
card = np.array(card)
atari = np.zeros((3,3))

for _ in range(N):
  b = int(input())
  atari[card==b] = 1


# if any([(card==0).all(axis=0).any() , (card==0).all(axis=1).any(), (card[[0,0], [1,1], [2,2]]==0).all(), (card[[0,2], [1,1], [2,0]]==0).all()]):
if any([atari.all(axis=0).any(), atari.all(axis=1).any(), all([atari[0,0], atari[1,1], atari[2,2]]), all([atari[0,2], atari[1,1], atari[2,0]])]):
  print('Yes')
else:
  print('No')

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

using namespace std;

int main() {

	int x, y;

	cin >> x >> y;

	int n1=0, n2=0;

	string ans = "No";

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			if (i + j == x && i * 2 + j * 4 == y) {
				ans = "Yes";
			}
		}
	}
		cout << ans;
}


Measured memory_bytes: 3132
from collections import defaultdict
import sys
sys.setrecursionlimit(20000000)
connection = defaultdict(lambda: [])

n = int(input())

ab = []
for i in range(n-1):
    a, b = map(int, input().split())
    connection[a].append(b)
    connection[b].append(a)
    ab.append((a, b))

c = list(map(int, input().split()))
c.sort()

ans = [0] * (n+1)
checked_list = []
def dfs(num):
    checked_list.append(num)
    ans[num] = c.pop()
    for next_num in connection[num]:
        if next_num not in checked_list:
            dfs(next_num)

dfs(1)

score = 0

for a, b in ab:
    score += min(ans[a], ans[b])

print(score)
print(" ".join(map(str, ans[1:])))


Measured memory_bytes: 14880
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
long long a,b,c;
int main(){
	cin>>a>>b>>c;
	int t=0;
	if(a>b)t=a,a=b,b=t;
	if(b>c)t=b,b=c,c=t;


	cout<<a+b<<endl;





	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
bool pairComparesecond(const p& firstElof, const p& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main(){
	ll n,k;
	cin>>n>>k;
	if(n%2==0){
		if(k<=n/2)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	else{
		if(k<=n/2+1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

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

using namespace std;

int ctoi(const char);

int main(void) {
  int num, a, b, l, total;
  
  cin >> num >> a >> b;
  
  for (int i = 1;i <= num;i++) {
    string iStr;
  	iStr = to_string(i);
    
    l = iStr.length();
    int sum = 0;
    
    for (int j = 0;j < l;j++) {
      int n = ctoi(iStr[j]);
      sum += n;
    }
    
    if (sum >= a && sum <= b) {
      total += i;
    }
  }
  
  cout << total << endl;
  
  return 0;
}

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


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextDouble()){
			double a=sc.nextDouble();
			double b=sc.nextDouble();
			double c=sc.nextDouble();
			double d=sc.nextDouble();
			double e=sc.nextDouble();
			double f=sc.nextDouble();
			double x=(c*e-b*f)/(e*a-b*d);
			double y=(c-a*x)/b;
		if(x==-0){
			x=0;
		}else if(y==-0){
			y=0;
		}
		System.out.printf("%.3f %.3f\n",x,y);


		}




	}
}

Measured memory_bytes: 28340
import java.util.*;

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

        String ans;

        if(s.charAt(0) != 'A' || s.charAt(1) <= 'Z' || s.charAt(s.length() - 1) <= 'Z') ans = "WA";

        else{
            int c_count = 0;
            int small_count = 0;
            int other = 0;
            for(int i = 2; i < s.length() - 1; i++){
                if(s.charAt(i) == 'C')     c_count++;
                else if(s.charAt(i) <= 'z' && s.charAt(i) >= 'a') small_count++;
                else other++;
            }

            if(c_count == 1 && small_count == s.length() - 4 && other == 0) ans = "AC";
            else ans = "WA";
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int	main(void)
{
	int	W, H;
	int	x, y, r;
	int left, right, top, bottom;
	int	flg = 1;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	left = x - r;
	right = x + r;
	top = y + r;
	bottom = y - r;
	if (left < 0 || bottom < 0 || top > H || right > W)
		flg = 0;
	if (flg)
		printf("%s\n", "Yes");
	else
		printf("%s\n", "No");
	return (0);
}





Measured memory_bytes: 2064
def main():
    N, M = map(int, input().split())  # N must be an odd number

    if N % 2 == 1:
        gen = ((i+1, N-i) for i in range(M))
    else:
        gen = ((i+1, N-i) if 2*i < N/2-1 else (i+1, N-i-1) for i in range(M))

    for s in gen:
        print(*s)


if __name__ == "__main__":
    main()


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

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

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

int main(){
	ll k,a,b;
	cin>>k>>a>>b;

	ll c=1;
	if(a+2>=b){
		c+=k;
	}else{
		int i=0;
		while(i!=k){
			if(i+2<=k && a<=c){
				i+=2;
				c=c-a+b;
			}else{
				c++;
				i++;
			}
		}
	}

	cout<<c<<endl;

	
	return 0;
}
	


Measured memory_bytes: 256
import std.stdio, std.array, std.conv, std.string;

void main() {
  while (true) {
    string[] input = split(readln());
    if (input[1] == "?") break;

    writeln(calc(input));
  }
}

int calc(string[] s) {
  int a = to!int(s[0]), b = to!int(s[2]);
  string op = s[1];

  if (op == "+") return a + b;
  if (op == "-") return a - b;
  if (op == "*") return a * b;
  if (op == "/") return a / b;

  return -1;
}

Measured memory_bytes: 2488
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll //9223372036854775807
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
#define nl "\n"
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
//ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
ll inve(ll x){return x==1?1:(mod-mod/x)*inve(mod%x)%mod;}

const int N = 1e5+5;

int n, a[N];

int main()
{
    ll sum = 0;
    cin>>n;
    for(int i=1;i<=n;i++) a[i] = read(), sum += a[i];
    sort(a+1,a+1+n);
    //sum -= a[n];
    int ans = 0;
    for(int i=n;i>=1;i--)
    {
        sum -= a[i];
        ans ++ ;
        if(sum*2<a[i]) break;
    }
    //while(i>=1 && sum*2>=a[i]) i--, ans++, sum -= a[i];
    cout<<ans<<nl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int N;
    int a[100] = {};

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

    int max, min;
    max = min = a[0];

    for(int i = 0; i < N; i++){
        if(max < a[i])
            max = a[i];
        if(min > a[i])
            min = a[i];
    }

    cout << (max - min);

    return 0;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  string res;
  switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      res = "hon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      res = "pon";
      break;
    case 3:
      res = "bon";
      break;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
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 FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

using namespace std;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	vvl dp(10 + 1, vl(1000 + 1));
	dp[0][0] = 1;

	FOR(i, 0, 100) {
		for (int j = 9; j >= 0; j--) {
			for (int k = 0; k + i <= 1000; k++) {
				dp[j + 1][k + i] += dp[j][k];
			}
		}
	}

	int n, s;
	while (cin >> n >> s, n) {
		cout << dp[n][s] << endl;
	}

	return 0;
}

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


int32_t main(){
     int n; cin>>n;
     
     vector <int> a(n),s(1000005);
      int flag1=0, GCD=1;
     
      for(int i=0 ; i<n ; i++)
            cin>>a[i];
            
      sort(a.begin(),a.end());

      for(int i=0 ; i<n ; i++){
        int j=2;
        for(j=1 ; j*j<=a[i] ; j++){
                if(a[i]%j==0){
                   if(s[j] || s[a[i]/j]) {flag1=1; break;}
                   else{
                      if(j!=1) s[j]=1; if(a[i]/j!=1) s[a[i]/j]=1;
                   }
                }
            }
            
              if(flag1==1) break;
      }
      
        for(int i=0 ; i<n ; i++){
               if(i==0) GCD=a[0];
               else GCD = __gcd(GCD,a[i]);
        }
       if(flag1==0) cout<<"pairwise coprime";
       else if(GCD==1) cout<<"setwise coprime";
       else cout<<"not coprime";
}

Measured memory_bytes: 18768
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp*/

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a,b;
    while(cin>>a>>b){
        cout<<(int)(log10(a+b)+1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	int a[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int m[100005];
	int ans = 1;
	m[0] = a[0];
	int min, max, mid;
	for (i = 1; i < n; i++)
	{
		if (a[i] > m[0])
		{
			m[0] = a[i];
			continue;
		}
		if (a[i] <= m[ans - 1])
		{
			m[ans] = a[i];
			ans++;
			continue;
		}
		max = ans - 1;
		min = 0;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (m[mid] >= a[i])
				min = mid;
			else
				max = mid;
		}
		m[max] = a[i];
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll mo=1000000007;
ll combi(ll N_, ll C_) {
	const int NUM_=4500001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int N,K;
ll dp[2020][2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	if(K==1) return _P("1\n");
	
	dp[0][1]=1;
	for(y=2;y<=N;y++) dp[0][y] = dp[0][y-1]*combi(y*(K-1)-1,K-2)%mo;
	
	for(x=1;x<=N;x++) {
		
		if(x==1) dp[1][1]=1;
		else dp[x][x]=dp[x-1][x];
		
		for(y=x+1;y<=N;y++) dp[x][y] = (dp[x-1][y] + dp[x][y-1]*combi(x+y*(K-1)-1,K-2))%mo;
	}
	
	ll ret=dp[N][N];
	for(i=1;i<=N;i++) ret=ret*i%mo;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 128384
# coding: utf-8
h, w = map(int, input().split())
cloud = [[i for i in input()] for i in range(h)]
flag = 0 #1?????¨????????????
cnt = 0 
for i in range(h):
    for j in range(w):
        if j==w-1 and flag==0 and cloud[i][j]=='.':
            print(-1, end='')
        elif j==w-1 and cloud[i][j]=='c':
            print(0, end='')
            flag = 1
            cnt = 0
        elif j==w-1 and cloud[i][j]=='.':
            cnt += 1
            print(cnt, end='')
        elif flag==0 and cloud[i][j]=='.':
            print(-1, end=' ')
        elif cloud[i][j]=='c':
            print(0, end=' ')
            flag = 1
            cnt = 0
        else:
            cnt += 1
            print(cnt, end=' ')
    print()
    cnt = 0
    flag = 0

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

int main() {
  long long n, d, ans = 0;
  cin >> n >> d;
  long long x, y;
  for (int i = 0 ; i < n ; i++) {
    cin >> x >> y;
    if (sqrt(x * x + y * y) <= d) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3676
val MOD = 1000000007

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s1 = readLine()!!
    val s2 = readLine()!!

    if (n == 1) {
        println(3)
        return
    }

    var cnt = 0L
    var wasHorizontal = false
    var shouldSkip = false

    for (i in 0..n-2) {
        if (shouldSkip) {
            shouldSkip = false
            continue
        }

        if (s1[i] == s1[i+1]) {
            // horizontal
            if (i == 0) {
                cnt = 3 * 2
            } else {
                if (wasHorizontal) {
                    // horizontal -> horizontal
                    cnt *= 3
                } else {
                    // vertical -> horizontal
                    cnt *= 2
                }
            }
            wasHorizontal = true
            shouldSkip = true
        } else {
            // vertical
            if (i == 0) {
                cnt = 3
            } else {
                if (wasHorizontal) {
                    // horizontal -> vertical
                    cnt *= 1
                } else {
                    // vertical -> vertical
                    cnt *= 2
                }
            }
            wasHorizontal = false
        }

        cnt %= MOD
    }

    if (!wasHorizontal) {
        cnt *= 2
        cnt %= MOD
    }

    println(cnt)
}

Measured memory_bytes: 33828
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    cnt = 0
    for i in range(n):
        d1, d2 = rli()
        if d1 == d2:
            cnt += 1
            if cnt == 3:
                print("Yes")
                return
        else:
            cnt = 0
    print("No")


if __name__ == '__main__':
    main()


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


int main()
{
  string s;
  cin >> s;
  if (s == "ABC")
    printf("ARC\n");
  else
    printf("ABC\n");
  return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int n;

LL gcd(LL x, LL y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

LL lcm(LL x, LL y) {
	return (x / gcd(x, y) * y);
}

int main()
{
	scanf("%d", &n);
	LL ans = 1;
	for (int i = 1; i <= n; i++) {
		LL x; scanf("%lld", &x);
		ans = lcm(ans, x);
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(void)
{
	int n, s[100], ans;
	cin >> n;

	int i, sum=0;
	for(i=0; i<n; i++){
		cin >> s[i];
		sum += s[i];
	}

	if(sum % 10 != 0){
		cout << sum << endl;
		return 0;
	}

	sort(s, s+n);

	for(i=0; i<n; i++){
		if(s[i]%10 != 0 && (sum-s[i])%10 != 0){
			cout << sum-s[i] << endl;
			return 0;
		}
	}

	if(i == n) cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import permutations
n=int(input())
p=tuple(map(lambda x:int(x)-1,input().split()))
q=tuple(map(lambda x:int(x)-1,input().split()))
perms=list(permutations(range(n)))
for i in range(len(perms)):
    if perms[i]==p:
        pidx=i
    if perms[i]==q:
        qidx=i
print(abs(pidx-qidx))

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

using namespace std;
using ll = long long;


int main()
{
    srand((unsigned)time(NULL));
    string s; cin >> s;

    int n = s.size();
    while(true) {
        int t = rand() % n;
        if(t + 3 <= n) {
            cout << s.substr(t, 3) << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

int main() {
	int N;
	cin >> N;

	double L=N;

	if (N % 2 == 0) { cout << fixed << setprecision(15) << 0.5 << endl; }
	if (N % 2 == 1) { cout << fixed << setprecision(15) << (L+1)/(2*L) << endl; }
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    vi v ( n ) ;
    for ( int  i=0 ; i < n ; i ++ ) cin >> v[i] ;

    for ( auto i : v )
    {
        if ( i % 2 ) C ;

        if ( i % 3 == 0 ) C ;
        if ( i % 5 == 0 ) C ;

        cout << "DENIED" ;
        line ; R ;
    }

    cout << "APPROVED" ;  line ;

}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define float double
int main()
{
  float a,b,x;
  cin>>a>>b>>x;
  float v=a*a*b;
  float s=a*b;
  float y=x/a;
  float tan;
  float ans;
  if(v>=2*x){
    tan=b*b/(2*y);
    ans=atan(tan);
    ans=ans*180/3.14159265358979;
  }
  else{
    y=s-y;
    tan=2*y/(a*a);
    ans=atan(tan);
    ans=ans*180/3.14159265358979;
  }
  cout<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 256
nml = input()
nml = nml.split()
n,m,l = nml
m,n,l =int(m),int(n),int(l)
NM = list()
ML = list()
NL = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
    nm = input()
    nm = nm.split()
    NM.append(nm)
for j in range(m):
    ml = input()
    ml = ml.split()
    ML.append(ml)
for i in range(n):
    for a, A in enumerate(NM[i]):
        for b, B in enumerate(ML[a]):
            NL[i][b] = NL[i][b] + int(A)*int(B)
else:
    for a, A in enumerate(NL):
        p = ''
        for b, B in enumerate(NL[a]):
            p = p + ' {}'.format(B)
        else:
            print(p[1:])


Measured memory_bytes: 7404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] heights = new int[N];
		
		for (int i = 0; i < N; i++) {
			heights[i] = sc.nextInt();
		}
		System.out.println(frog(heights));
	}
	
	private static int frog(int[] heights) {
		int len = heights.length;
		int[] dp = new int[len];
		dp[0] = 0;
		dp[1] = Math.abs(heights[0] - heights[1]);
		
		for (int i = 2; i < len; i++) {
			dp[i] = Math.abs(Math.min(dp[i-1] + Math.abs(heights[i-1]-heights[i]),
					                  dp[i-2] + Math.abs(heights[i-2]-heights[i])));
		}
		
		return dp[len-1];
	}

}


Measured memory_bytes: 48984
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;
  vector<ll> b(n-1);
  rep(i,n-1) cin>>b[i];

  ll ans=0;

  rep(i,n){
    ll x;
    if(i==0) x=b[i];
    else if(i==n-1) x=b[n-2];
    else x=min( b[i],b[i-1] );
    //cout << x << endl;
    ans+=x;
  }

  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int s, w;
    cin >> s >> w;
    if (s > w) cout << "safe" << en;
    else cout << "unsafe" << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
int main(void){
    int n,k,cnt,i,j;
    double ans=0;
    scanf("%d%d",&n,&k);
    for(i=1;i<n+1;i++){
        j=i;
        cnt=0;
        while(j<k){
            j*=2;
            cnt++;
        }
        ans += (double)1/(1<<cnt);
    }
    printf("%.10f",ans/n);
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// use std::io::{stdout, Write, BufWriter};
// use std::cmp::{max, min};

fn main() {
    input! {
        h: i64,
    }
    println!("{}",
             2i64.pow((h as f64).log2().floor() as  u32 + 1) - 1i64
    );
}


Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main() {
  ll N,K;
  cin >> N >> K;
  vector <ll> stones(N);
  for(int i = 0; i < N; i++){
    cin >> stones[i];
  }
  vector <ll> dp(N,99999999999);
  dp[0] = 0;
  for(int q = 1; q < N; q++){
    for(int p =  1; p < K + 1; p ++){
      if(q-p >= 0){
        dp[q] = min(dp[q], dp[q-p] + abs(stones[q-p] - stones[q]));
      }
    }
  }
  cout << dp[N-1];
}

Measured memory_bytes: 4776
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while True:
    flag = True
    for i in range(n):
        if a[i]%2 == 0:
            a[i] //= 2
        else:
            flag = False
            break
    if not flag:
        break
    cnt += 1
print(cnt)

Measured memory_bytes: 63652
#include<iostream>

using namespace std;

int main() {
	int N, warisu = 0, nam, saiwari = 0, A=1;

	cin >> N;

	for (int i = 2; i <= N; i++) {
		warisu = 0;
		nam = i;
		while (true){
			if (nam % 2 == 0) {
				nam /= 2;
				warisu++;
			}
			else {
				break;
			}
		}
		if (saiwari < warisu) {
			saiwari = warisu;
			A = i;
		}

	}
	cout << A << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
#include<numeric>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
#define INF 1e5
#define MODE 1000007
int main(){
	int a,b,t;
	cin>>a>>b>>t;
	cout<<t/a*b<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn=100010;
int n,m,Q;
LL q[maxn];
LL x;
LL tag[maxn],a[maxn];
void solve(LL x,LL y){
	if(x<=q[1]){
		if(x) a[x]+=y;return;
	}
	int l=1,r=n,ret=1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(q[mid]<x){
			ret=mid;
			l=mid+1;
		}else r=mid-1;
	}
	tag[ret]+=x/q[ret]*y;
	solve(x%q[ret],y);
}
int main(){
	scanf("%d%d",&m,&Q);
	q[n=1]=m;q[0]=q[1];
	for(int i=1;i<=Q;i++){
		scanf("%lld",&x);
		while(n && x<=q[n]) n--;
		q[++n]=x;
	}
	tag[n]=1;
	for(int i=n;i>1;i--){
		tag[i-1]+=(q[i]/q[i-1])*tag[i];
		solve(q[i]%q[i-1],tag[i]);
	}
	a[q[1]]+=tag[1];
	for(int i=m;i>=1;i--) a[i]+=a[i+1];
	for(int i=1;i<=m;i++) printf("%lld\n",a[i]);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int h,w,a,b;
	cin>>h>>w;
	if(w==1 || h==1)
	{
		cout<<1<<endl;	
		return 0;
	}
	
	else if(w%2==0)
	{
		a=h*(w/2);
	}
	else
	{
		if(h%2==0)
		{
			a=(h*w)/2;
		}
		else
		{
			b=((w-1)/2)+1;
			a=b+(((h-1)/2)*w);
		}
	}
	cout<<a<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b;
  cin>>a>>b;
  if(a>b){
    swap(a,b);
  }
  long long  n=b;
  while(n%a!=0){
    n+=b;
  }      
  cout<<n<<endl;
}

Measured memory_bytes: 256