akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

const int p=1000000007;

int c[300][300],g[100],h[100];
char b[100];
int i,j,k,l,m,n,r,s,t;

inline void pre()
{
	scanf("%d%d",&n,&m);
	scanf("%s",b+1);
	for (i=0;i<=250;i++)
		for (j=0;j<=i;j++)
			if ((j==0) || (j==i))
				c[i][j]=1;
			else
				c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
	return;
}

inline void calc()
{
	for (i=1;i<=n;i++)
		h[i]=g[i];
	t=0;
	for (i=1,k=1,l=1;i<=m;i++)
		if ((b[i]=='r') && (h[k]>0))
			h[k]--,k++;
		else
		if ((b[i]=='b') && (h[l]>0) && (l<k))
			h[l]--,t=t+h[l],l++;
		else
		if (t>0)
			t--;
	if ((h[k]) || (h[l]) || (t))
		return;
	r=1;
	for (i=1;g[i];i=j)
	{
		for (j=i;g[i]==g[j];j++);
		r=1LL*r*c[j-1][i-1]%p;
		if (g[i]==1)
			t=t+j-i;
		else
			t=t+(j-i)*(2*g[i]-3);
	}
	t=t+k-2;
	if (n-t<0)
		return;
	s=(s+1LL*r*c[n+2*l-1][t+2*l-1])%p;
	return;
}

inline void dfs(int w,int x,int y,int z)
{
	if (w<0)
		return;
	if (z)
		calc();
	if (x)
	{
		g[z+1]=1,dfs(w-2,x-1,1,z+1);
		for (int i=2;(i<=x) && (i<=y);i++)
			g[z+1]=i,dfs(w-2*i+2,x-i,i,z+1);
		g[z+1]=0;
	}
	return;
}

int main()
{
	pre();
	dfs(n+1,m,m,0);
	printf("%d",(s+1)%p);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int sum=0;

int main() {
	int n;
	cin>>n;
	int b=n;
	while(b!=0){
		sum+=b%10;
		b/=10;
	}
	if(n%sum==0||sum%n==0)
		cout<<"Yes"; 
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	int a,b,c,k,x,sum;
	int max=-1;
	
	scanf("%d%d%d%d",&a,&b,&c,&k);
	
	if(a>b&&a>c){
		max=a;
		sum=b+c;
	}else if(b>c&&b>a){
		max=b;
		sum=c+a;
	}else{
		max=c;
		sum=a+b;
	}
	
	x=pow(2,k);
	
	printf("%d\n",max*x+sum);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	string a,b;
	cin >> a>>b;
	string ao, bo;
	rep(i, atoi(b.c_str())) {
		ao += a;
	}
	rep(i, atoi(a.c_str())) {
		bo += b;
	}
	
	if (ao >= bo) {
		cout << bo << endl;
	}
	else {
		cout << ao << endl;
	}
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
int main()
{   char a[101],b[101];
    scanf("%s%s",a,b);
        if(strlen(a)>strlen(b)){
            printf("GREATER");
            return 0;
        }
        if(strlen(b)>strlen(a)){
            printf("LESS");
            return 0;
        }
    int c=strcmp(a,b);
    if(c>0)printf("GREATER");
    else if(c<0)printf("LESS");
    else printf("EQUAL");
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> H(N);
  for (int i = 0; i < N; i++){
    cin >> H[i];
  }
  int64_t max = H[0];
  bool can = true;
  for (int i = 0; i < N; i++){
    if (H[i] > max){
      max = H[i];
    }
    else if (H[i] + 1 < max){
      can = false;
      break;
    }
  }
  if (can){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  int B;
  int T;
  cin >>A>>B>>T;
  int x=T/A;
  cout <<x*B << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
const int mod=1e9+7;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)>=0?x:x+mod;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
inline int Pow(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=1ll*res*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return res;
}
int fac[max_n],inv[max_n];
void init(int n){
    fac[0]=1;
    for(int i=1;i<=n;i++)fac[i]=Mul(fac[i-1],i);
    inv[n]=Pow(fac[n],mod-2);
    for(int i=n-1;i>=0;i--)inv[i]=Mul(inv[i+1],i+1);
}
int C(int n,int m){
    if(n<m||m<0)return 0;
    return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int n;
vector<int> v[max_n];
int main(){
    scanf("%d",&n);
    init(n+1);
    for(int i=1;i<=n+1;i++){
        int x;scanf("%d",&x);
        v[x].push_back(i);
    }
    int x,y;
    for(int i=1;i<=n;i++){
        if(v[i].size()>=2)x=v[i][0],y=v[i][1];
    }
    for(int i=1;i<=n+1;i++){
        int res=C(n-1,i);
        if(i>=2)res=Add(res,C(n-1,i-2));
        if(i>=1){
            int tmp1=C(n+x-y,i-1);
            int tmp2=C(n-1,i-1);
            res=Add(res,tmp1);
            tmp2=Sub(tmp2,tmp1);
            res=Add(res,Add(tmp2,tmp2));
        }
        printf("%d\n",res);
    }
    return 0;
}


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

/*
提出前に確認!
- setとmultisetを間違えない
*/

int	main(void)
{
	char c;
	cin >> c;
	if ('a' <= c && c <= 'z') cout << 'a' << endl;
	else cout << 'A' << endl;
	return (0);
}


Measured memory_bytes: 3588
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int[] x = new int[N];
        for(int i=0; i<N; i++) {
          int A = sc.nextInt();
          x[i] = A;
        }
        long plus = 0;
        for(int i=1; i<N; i++) {
        if(x[i-1] > x[i]) {
          plus+=x[i-1]-x[i];
          //x[i]+=x[i-1]-x[i];
          x[i]=x[i-1];
        } else {
          continue;
        }
        }
      System.out.println(plus);
    }
  }

Measured memory_bytes: 60520
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,h,w;
    cin>>n>>h>>w;
    int res=0;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a>=h&&b>=w)res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#define MN 188

int n, m;
char c[MN][MN];
int f[MN][MN][MN][2], g[MN][MN][MN][2];
int sum[MN][MN];

int S(int a, int b, int c, int d) {return sum[c][d] - sum[a - 1][d] - sum[c][b - 1] + sum[a - 1][b - 1];}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (c[i][j] == '#');
			
	for(int i = 1; i <= n; i++)
		for(int j = i; j <= n; j++)
		{
			int r = 0;
			for(int l = 1; l <= m; l++)
			{
				r = std::max(r, l - 1);
				while(r < m && (S(i, l, j, r + 1) == (j - i + 1) * (r + 1 - l + 1) || S(i, l, j, r + 1) == 0)) r++;
				f[i][j][l][0] = r;
			}
		}
			
	for(int i = 1; i <= m; i++)
		for(int j = i; j <= m; j++)
		{
			int r = 0;
			for(int l = 1; l <= n; l++)
			{
				r = std::max(r, l - 1);
				while(r < n && (S(l, i, r + 1, j) == (r + 1 - l + 1) * (j - i + 1) || S(l, i, r + 1, j) == 0)) r++;
				g[i][j][l][0] = r;
			}
		}
		
	if(f[1][n][1][0] == m) return 0 * puts("0");
	
	for(int o = 1; o <= 16; o++)
	{
		for(int i = 1; i <= n; i++)
			for(int j = i; j <= n; j++)
			{
				int r = 0;
				for(int l = 1; l <= m; l++)
				{
					r = std::max(r, f[i][j][std::min(m, f[i][j][l][(o & 1) ^ 1] + 1)][(o & 1) ^ 1]);
					while(r < m && g[l][r + 1][std::min(m, g[l][r + 1][i][(o & 1) ^ 1] + 1)][(o & 1) ^ 1] >= j) r++;
					f[i][j][l][o & 1] = r;
				}
			}
			
		for(int i = 1; i <= m; i++)
			for(int j = i; j <= m; j++)
			{
				int r = 0;
				for(int l = 1; l <= n; l++)
				{
					r = std::max(r, g[i][j][std::min(n, g[i][j][l][(o & 1) ^ 1] + 1)][(o & 1) ^ 1]);
					while(r < n && f[l][r + 1][std::min(n, f[l][r + 1][i][(o & 1) ^ 1] + 1)][(o & 1) ^ 1] >= j) r++;
					g[i][j][l][o & 1] = r;
				}
			}
		
		if(f[1][n][1][o & 1] == m) return 0 * printf("%d\n", o);
	}
}

Measured memory_bytes: 102400
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

priority_queue<int> q;
int h[100000];

signed main()
{
	int r, g, b;
	cin >> r >> g >> b;
	int cnt = r * 100 + g * 10 + b;
	cout << ((cnt % 4 == 0) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//
	int n,m,t=1,i,j,k,sum=0,ans,f=0,x,y,w,a,b,c,d;
	//cin>>t;
	while(t--){
		string s;
		//vector<int> v;map<int,int> mp;
		set<string> st;
		cin>>n;
		while(n--){
			cin>>s;
			st.insert(s);
		}
		cout<<st.size();
		
		//int a[n];rep(i,n) cin>>a[i];

	}
	return 0;
}




Measured memory_bytes: 19216
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int ans = n;
	for (int i = 0; i <= n; i++) {
		int cc = 0;
		int t = i;
		while (t > 0)cc += t % 6, t /= 6;
		t = n - i;
		while (t > 0)cc += t % 9, t /= 9;
		if (ans > cc)ans = cc;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

ll func(ll A){

	// // 解1 
	// ll res = 0;

	// A++; // 周期的に考えてると0からスタートしてしまうので，インクリメント
	// for(int i=0; i<50; i++){
	// 	//Aを2進数の0~50桁目の各桁について
	// 	//1の個数を数える
	// 	ll loop = (ll)1 << (i+1);//00001111000011...という感じで01の周期
	// 	ll cnt = A/loop * loop/2;//周期の半分が1なので Aの中の周期数×周期の半分，半分が1

	// 	//周期のはみ出たところの1を足す
	// 	//(loop個のうちの半分は0なので，Aが0で終わってたらマイナスになるので0とmaxをとる
	// 	cnt += max((ll)0,  A%loop - loop/2);
	// 	// cout << " i: " << i << " cnt: " << cnt << " cnt%2: " << cnt%2 << endl;
	// 	if(cnt % 2 == 1){
	// 		res += (ll)1 << i;
	// 	}

	// }
	// return res;

	//解2
	ll r = A % 4;
	if(r == 0) return (ll)A;
	if(r == 1) return (ll)A^(A-1);
	if(r == 2) return (ll)A^(A-1)^(A-2);
	if(r == 3) return (ll)0;//A^(A-1)^(A-2)^(A-3)=0になる	
	return 0;
}

int main(){
	ll A, B;
	cin >> A >> B;

	// A~BのXOR   =  (0~BのXOR)  XOR  (0~A-1のXOR)
	//なぜなら a^a = 0 である．
	// 例: (4^5^6^7) = (1^2^3^4^5^6^7) ^ (1^2^3)
	ll ans = func(B)^func(A-1);
	// cout << " func(A-1): " << func(A-1) << "  func(B): " << func(B) << endl;
	cout << ans << endl;
}



Measured memory_bytes: 3556
K = int(input())

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[K-1])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    cout << n * 800 - n / 15 * 200 << endl;
    return 0;
}

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

int main() {
	int N, M, Q;
	int L[200000], R[200000];
	int nijigen[501][501] = {};
	cin >> N >> M >> Q;
	repeat(i, M) {
		cin >> L[i] >> R[i];
		nijigen[L[i]][R[i]] += 1;
	}
	int p[100000], q[100000];
	repeat(i, Q) {
		cin >> p[i] >> q[i];
	}

	
	int ruikei[502][502] = {};

	repeat(i, N) {
		repeat(ii, N) {
			ruikei[i + 1][ii + 1] = ruikei[i + 1][ii] + nijigen[i + 1][ii + 1];
		}
	}

	repeat(ii, N) {
		repeat(i, N) {
			ruikei[N - i][ii + 1] = ruikei[N - i + 1][ii + 1] + ruikei[N - i][ii + 1];
		}
	}

	repeat(i, Q) {
		cout << ruikei[p[i]][q[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 5248
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e9 + 4;
const int N = 1e2 + 4;
const int M = 1e3 + 4;

int d[N][N];
int n, m, a[M], b[M], c[M];

void solve() {
    for (int i = 0; i < N; ++i) {
        fill_n(d[i], N, INF);
        d[i][i] = 0;
    }
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }

    for (int k = 1; k <= n; ++k) {
        for (int u = 1; u <= n; ++u) {
            for (int v = 1; v <= n; ++v) {
                d[u][v] = min(d[u][v], d[u][k] + d[k][v]);
            }
        }
    }

    int res = 0;
    for (int i = 0; i < m; ++i) {
        bool flag = true;
        for (int u = 1; u <= n && flag; ++u) {
            for (int v = 1; v <= n && flag; ++v) {
                int len1 = d[u][a[i]] + d[b[i]][v] + c[i];
                int len2 = d[u][b[i]] + d[a[i]][v] + c[i];
                if (len1 == d[u][v] || len2 == d[u][v]) {
                    flag = false;
                }
            }
        }
        res += flag;
    }
    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	cin>>s;
	t=s;
	reverse(s.begin(),s.end());
	ll ans=0;
	for(ll i=0;i<s.size()/2;i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int a[maxn],n;

int qpow(int a,int x) {
    int res=1;
    for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod;
    return res;
}

pii solve(int l,int r) {
    int mn=1e9,pre=l-1,cnt=0;
    for(int i=l;i<=r;i++) mn=min(mn,a[i]);
    pii ans;ans.fr=ans.sc=1;
    for(int i=l;i<=r+1;i++) {
        if(i!=r+1&&a[i]!=mn) continue;cnt++;
        if(pre==i-1) {pre=i;continue;}
        int t=1e9;
        for(int j=pre+1;j<i;j++) t=min(t,a[j]);
        t--;
        pii res=solve(pre+1,i-1);
        res.sc=1ll*res.sc*qpow(2,t-mn)%mod;
        ans.sc=1ll*ans.sc*res.sc%mod;
        ans.fr=1ll*ans.fr*(2ll*res.sc+res.fr)%mod;
        pre=i;
    }
    cnt--;
    ans.sc=2ll*ans.sc%mod;
    ans.fr=1ll*ans.fr*qpow(2,cnt)%mod;
    ans.fr=(ans.fr-ans.sc+mod)%mod;
    // printf("solve :: %d %d ( %d %d ) \n",l,r,ans.fr,ans.sc);
    return ans;
}

int main() {
    read(n);for(int i=1;i<=n;i++) read(a[i]);
    pii ans=solve(1,n);
    int mn=1e9;
    for(int i=1;i<=n;i++) mn=min(mn,a[i]);
    ans.sc=1ll*ans.sc*qpow(2,mn-1)%mod;
    write((ans.fr+ans.sc)%mod);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector <int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A.begin(), A.end());
  
  for (int i = 0; i < N-1; i++) {
    if(A[i] == A[i+1]) {
      cout << "NO" << endl;
      return 0;      
    }
  }
  
  cout << "YES" << endl;
  return 0;
}

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

typedef long long ll;

#define rep0(i, n) for(ll i=0; i<(ll)(n); i++)
#define rep1(i, n) for(ll i=1; i<=(ll)(n); i++)
#define rep(i, a, b) for(ll i=(ll)a; i<=(ll)(b); i++)
#define rep0r(i, n) for(ll i=(ll)(n)-1; i>=0; i--)
#define rep1r(i, n) for(ll i=(ll)(n); i>0; i--)
#define repr(i, a, b) for(ll i=(ll)b; i>=(ll)(a); i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a * b / __gcd(a, b)


void solve() {
    double r;
    double pi = 3.14159265358979;
    
    cin >> r;

    cout << 2 * pi * r << '\n';
}

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

Measured memory_bytes: 3800
// A Dynamic Programming based 
// C# program to find minimum 
// number operations to 
// convert str1 to str2 
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{
    static Dictionary<int, int> ans = new Dictionary<int, int>();
    public static void Main()
    {
        var intput = Console.ReadLine();

        Sachi(intput);
    }

    public static void Sachi(string s)
    {

        var min = int.MaxValue;

        for(int i=0;i<s.Length-2;i++)
        {
            var temp = s.Substring(i, 3);
            var diff = Math.Abs(Convert.ToInt32(temp) - 753);
            min = Math.Min(diff, min);
            
        }

        Console.Write(min);
    }


}



Measured memory_bytes: 11604
x,y = (int(_) for _ in input().split())

s1 = {1,3,5,7,8,10,12}
s2 = {4,6,9,11}
s3 = {2}

if (x in s1 and y in s1) or \
        (x in s2 and y in s2) or \
        (x in s3 and y in s3):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
a, b, k = list(map(int, input().split()))
ans_a = 0
ans_b = 0

ans_a = max((a - k), 0)
if ans_a == 0:
    ans_b = max((a + b) - k, 0)
else:
    ans_b = b
print(str(ans_a) + " " + str(ans_b))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

static const int INF = 1e9;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n], t[n+1] = {};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        t[a[i]]++;
    }
    sort(t, t+n+1, greater<int>());
    ll sum = 0;
    for (int i = k; i < n; i++) {
        sum += t[i];
    }
    cout << sum << endl;
}

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

int main() {
	int k;
	cin>>k;
	int a,b;
	cin>>a>>b;
	int cnt=0;
	for(int i=a;i<=b;i++)
		if(i%k==0)
		cnt++;

if(cnt>0)
{
cout<<"OK";
}
else
cout<<"NG";
}

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

int c[100], n, k;

int rec(){
  int ret = 0;
  for(int i = 0 ; i <= n - k ; i++ ){
    int res = 1;
    for(int j = 0 ; j < k ; j++ ){
      res *= c[i + j];
    }
    ret = max( ret, res);
  }
  return ret;
}

int main(){

  while( cin >> n >> k, n){
    for(int i = 0 ; i < n ; i++ ){
      cin >> c[i];
    }

    int ck = rec();
    int ret = -1;

    for(int i = 0 ; i < n ; i++ ){
      for(int j = i + 1 ; j < n ; j++ ){
        swap( c[i], c[j]);
        ret = max( rec() - ck, ret);
        swap( c[j], c[i]);
      }
    }

    if(ret == -1) cout << "NOGAME" << endl;
    else cout << ret << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
static const int MAX_N = 100000;
static const int MAX_M = 100000;

int N, M;
vector<int> G[MAX_N + MAX_M];
bool visited[MAX_N + MAX_M];

void bfs(int s){
	queue<int> qa;
	qa.push(s);
	while(!qa.empty()){
		int s = qa.front(); qa.pop();
		for(int i = 0; i < G[s].size(); i++){
			int t = G[s][i];
			if(visited[t]) continue;
			visited[t] = true;
			qa.push(t);
		}
	}
	return ;
}

int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		int K;
		cin >> K;
		for(int j = 0; j < K; j++){
			int L;
			cin >> L;
			L--;
			G[i].push_back(L + N);
			G[L + N].push_back(i);
		}
	}
	bfs(0);
	bool flag = true;
	for(int i = 0; i < N; i++){
		if(!visited[i]) flag = false;
	}
	cout << (flag ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 8952
#include<stdio.h>
#include <string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(void){
char S[2];
int count;
scanf("%s",&S);
if ( !strcmp(S,"SUN")){
	count=7;	
}
else if (!strcmp(S,"MON")){
	count=6;	
}
else if (!strcmp(S,"TUE")){
	count=5;	
}
else if (!strcmp(S,"WED")){
	count=4;	
}
else if (!strcmp(S,"THU")){
	count=3;	
}
else if (!strcmp(S,"FRI")){
	count=2;	
}
else{
	count=1;
}
	printf("%d",count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}
// multimap
// mmap.emplace(key,value);
// auto ngw = list.equal_range("");
// for(auto e = ngw.first; it != ngw.second ; ++e)

int main(){
    int H, W; cin >> H >> W;
    vector<string> f(H);
    rep(i, H) cin >> f[i];
    vector<vector<ll>> toE(H, vector<ll>(W, 0));
    vector<vector<ll>> toW(H, vector<ll>(W, 0));
    vector<vector<ll>> toS(H, vector<ll>(W, 0));
    vector<vector<ll>> toN(H, vector<ll>(W, 0));
    rep(i, H){
        for(int j = 0; j < W - 1; ++j){
            if (f[i][j + 1] == '#' || f[i][j] == '#') continue;
            toW[i][j + 1] = toW[i][j] + 1;
        }
    }
    rep(i, H){
        for(int j = W - 1; 0 < j; --j){
            if (f[i][j - 1] == '#' || f[i][j] == '#') continue;
            toE[i][j - 1] = toE[i][j] + 1;
        }
    }

    rep(j, W){
        for(int i = 0; i < H - 1; ++i){
            if (f[i + 1][j] == '#' || f[i][j] == '#') continue;
            toN[i + 1][j] = toN[i][j] + 1;
        }
    }
    rep(j, W){
        for(int i = H - 1; 0 < i; --i){
            if (f[i - 1][j] == '#' || f[i][j] == '#') continue;
            toS[i - 1][j] = toS[i][j] + 1;
        }
    }
    // debug2(toE);
    // debug2(toW);
    // debug2(toS);
    // debug2(toN);
    ll ans = 0;
    rep(i, H) rep(j, W) ans = max(ans, toE[i][j] + toW[i][j] + toS[i][j] + toN[i][j] + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 129664
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

floor = 0
ceil = max(a)


def cut(long, logs):
    cnt = 0
    for i in logs:
        cnt += math.ceil(i / long) - 1
    return cnt


while ceil - floor > 1:
    L = (ceil + floor)//2
    num = cut(L, a)
    if num <= k:
        ceil = L
    else:
        floor = L

print(ceil)

Measured memory_bytes: 31020
l, r = map(int, input().split())
m = []
if l == r:
  print(l%2019 * l%2019)
else:
  if r - l < 2019:
    for i in range(l, r+1):
      m.append(i%2019)
    ans = 2019
    for i in range(len(m)-1):
      for j in range(i+1, len(m)):
        temp = (m[i]*m[j])%2019
        if ans > temp:
          ans = temp
    print(ans)
  else:
    print(0)


Measured memory_bytes: 40684
using System;

public class AtCoder{
	public static void Main(){
		string[] s;
		s = Console.ReadLine().Trim().Split(' ');
		
		int n,m,x,y;
		n = int.Parse(s[0]);
		m = int.Parse(s[1]);
		x = int.Parse(s[2]);
		y = int.Parse(s[3]);
		
		int[] ax = new int[n];
		int[] ay = new int[m];
		
		string[] sx;
		sx = Console.ReadLine().Trim().Split(' ');
		for(int i=0; i<n; i++) ax[i] = int.Parse(sx[i]);
		string[] sy;
		sy = Console.ReadLine().Trim().Split(' ');
		for(int i=0; i<m; i++) ay[i] = int.Parse(sy[i]);
		
		Array.Sort(ax);
		Array.Sort(ay);
		
		bool f = false;
		if(ax[n-1]<ay[0]){
			for(int i=ax[n-1]+1; i<ay[0]+1; i++){
				if(x<i){
					if(i<=y){
						f = true;
					}
				}
			}
		}
		
		if(f){
			Console.WriteLine("No War");
		} else {
			Console.WriteLine("War");
		}
	}
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 1; i <= n; i++)
			a[i - 1] = (in.nextLong() * 1000000) + i;
		Arrays.sort(a);
		for (int i = 0; i < n; i++)
			System.out.print(a[i] % 1000000 + " ");
		System.out.println();
		in.close();
	}
}

Measured memory_bytes: 66188
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    auto dx = readints;
    int d = dx[0], x = dx[1];
    int[] a;
    for (int i = 0; i < n; i++) {
        a ~= readint;
    }

    int ans = x + a.map!(e => (d - 1) / e + 1).sum;
    writeln(ans);
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    cout << (a+b+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#define MAX 1000

int main(void)
{
	int R[MAX], n, i;

	// input
	scanf("%d", &n);
	for (i = 0; i < (n-1); i++)
	{
		scanf("%d", &R[i]);
		printf("%d ", R[i]);
	}
	scanf("%d", &R[i]);
	printf("%d\n", R[i]);

	// sort
	for (i = 1; i < n; i++)
	{
		int v = R[i];
		int j = i - 1;
		while ((j >= 0) && (R[j] > v))
		{
			R[j + 1] = R[j];
			j--;
		}
		R[j + 1] = v;
		int k;
		for (k = 0; k < (n - 1); k++)
		{
			printf("%d ", R[k]);
		}
		printf("%d\n", R[k]);
	}
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> h(N);
  int s = 0;
  rep(i,N) 
  {
    cin >> h[i];
    s += h[i];
  }
  if(s==0)
  {
    cout << 0 << endl;
    return 0;
  }
  rep(i,1000000)
  {
    int sum = 0;
    int pour = 0;
    rep(j,N)
    {
      if(h[j]!=0)
      {
        h[j] --;
        pour ++;
      }
      else if(h[j]==0&&pour!=0)
      {
        break;
      }
    }
    rep(j,N)
    {
      sum += h[j];
    }
    if(sum==0)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3604
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

#include <iostream>
#include <tuple>
#include <stack>
using namespace std;

typedef tuple<int, int, int> st;

int main() {
  int N;
  cin >> N;
  for (auto i=0; i<N; i++) {
    int X[10];
    for (auto j=0; j<10; j++) {
      cin >> X[j];
    }
    stack<st> S;
    S.push(make_tuple(0, 0, 0));
    while (!S.empty()) {
      int now = get<0>(S.top());
      if (now == 10) goto EXIT;
      int R[2] = { get<1>(S.top()), get<2>(S.top()) };
      S.pop();
      int A = X[now];
      for (auto k=0; k<2; k++) {
	if (R[k] < A) {
	  S.push(make_tuple(now+1, A, R[(k+1)%2]));
	}
      }
    }
    printf("NO\n");
    continue;
  EXIT:
    printf("YES\n");
    continue;
  }
}

Measured memory_bytes: 1148
#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;
    int n = s.size();
    if (n % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < n - 1; i += 2)
    {
        if (s[i] == 'h' && s[i+1] == 'i') {
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var str string = "abcdefghijklmnopqrstuvwxyz"
	var si string

  fmt.Scanf("%s", &si)

	for i := 0; i < len(str)-1; i++ {
		if si == str[i:i+1] {
			fmt.Println(str[i+1:i+2])
		}
	}
}

Measured memory_bytes: 512
#include <memory>
#include <map>
#include <cassert>
#include <array>
#include <iterator>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <array>
#include <numeric>

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
      int n;
      in >> n;
      out << "ABC" + std::to_string (n) << '\n';
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <iostream>

int main ()
{
  solve (std::cin, std::cout);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, A, B, C, D, E;

    cin >> N >> A >> B >> C >> D >> E;

    cout << max({(N-1)/A,(N-1)/B,(N-1)/C,(N-1)/D,(N-1)/E})+5 << endl;

    return 0;
}

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


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

int A, N, M;
cin >> A >> N >> M;
string S;
cin >> S;
//int vec[200010];
//for(int i = 0; i < N; i++) cin >> vec[i];
int zen = 0;
int kai = 0;

for(int i = 0; i < A; i++){
if (S[i] == 'a' && N+M > zen){
    zen++;
    cout << "Yes" << endl;
} 
else if(S[i] == 'b' && N+M > zen && M > kai){
    zen++;
    kai++;
        cout << "Yes" << endl;
}
else cout << "No" << endl;
}



//if() cout << "Yes" << endl;
//else cout << "No" << endl;

// cout << "Yes" << endl;

}



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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  LL n, ans;
  vector<pair<LL, LL>> p;
  priority_queue<pair<LL, LL>> pqr;
  priority_queue<pair<LL, LL>, vector<pair<LL, LL>>, greater<pair<LL, LL>>> pql;
  Solver(LL n) : n(n), p(n){};
  LL calc(decltype(pqr) qr, decltype(pql) ql, bool r) {
    LL ret = 0, now = 0;
    vector<int> used(n);
    for (int i = 0; i < n; i++, r = !r) {
      if (r) {
        int id = -1;
        while (1) {
          if (qr.empty()) break;
          id = qr.top().second;
          qr.pop();
          if (!used[id]) break;
        }
        DBG(i, r, id)
        if (id != -1) {
          used[id] = 1;
          auto tmp = p[id];
          if (now < tmp.first) {
            ret += tmp.first - now;
            now = tmp.first;
          } else if (tmp.second < now) {
            ret += now - tmp.second;
            now = tmp.second;
          }
        }
      } else {
        int id = -1;
        while (1) {
          if (ql.empty()) break;
          id = ql.top().second;
          ql.pop();
          if (!used[id]) break;
        }
        DBG(i, r, id)
        if (id != -1) {
          used[id] = 1;
          auto tmp = p[id];
          if (now < tmp.first) {
            ret += tmp.first - now;
            now = tmp.first;
          } else if (tmp.second < now) {
            ret += now - tmp.second;
            now = tmp.second;
          }
        }
      }
      DBG(now, ret)
    }
    return ret + abs(now);
  }
  void solve() {
    ans = 0;
    for (int i = 0; i < n; ++i) {
      LL a, b;
      cin >> a >> b;
      p[i] = {a, b};
      pqr.push({a, i});
      pql.push({b, i});
    }
    cout << (max(calc(pqr, pql, false), calc(pqr, pql, true))) << "\n";
  }
};  // namespace Problem
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 11620
n=int(input())
b=list(map(int, input().split()))

b.insert(0, float("inf"))
b.insert(len(b), float("inf"))

a = []

for i in range(len(b)-1, 0, -1):
    a.insert(0, min(b[i-1], b[i]))

print(sum(a))


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


int main() {

    int n;
    cin >> n;
    if (1<= n && n <= 999) cout << "ABC" << endl;
    else cout << "ABD" <<  endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	
	int a,b,x;
	
	cin>>x;
	cin>>a;
	cin>>b;
	
	a=a-x;
	b=b-x;
	
	if(a<0){
		a*=-1;
	}
	if(b<0){
		b*=-1;
	}
	
	if(a>b){
		cout<<'B'<<endl;
	}else{
		cout<<'A'<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func solve(P, Q, R int) int {
	s := []int{P, Q, R}
	sort.Ints(s)
	return s[0] + s[1]
}

func main() {
	var P, Q, R int

	fmt.Scanf("%d %d %d", &P, &Q, &R)

	output := solve(P, Q, R)

	fmt.Println(output)
}


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

const ll INF = 1e18;

int main(){
	int n;
	cin >> n;
	
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	
	vector<ll> sum(n);
	sum[0] = a[0];
	rep(i,n-1) sum[i+1] = sum[i] + a[i+1];
	
	//rep(i,n) cout << sum[i] << " ";
	//cout << endl;
	
	vector<double> dist(n);
	double mindist = INF;
	//int minp;

	rep(i,n){
		dist[i] = abs(sum[i] - (double)sum.back()/2);
		mindist = min(mindist,dist[i]);
		//if(mindist == dist[i]) minp = i;
	}
  
    ll res = mindist/0.5;
	cout << res << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repri(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;
typedef vector<int> VI;
typedef vector<ll> VL;

void Main() {
	ll n;
	cin >> n;
	ll ans=0;
	if (n==1) cout << 0 << LF;
	else if (n==2) cout << 1 << LF;
	else {
		rep(i,1,n) {
			ans+=i;
		}
		cout << ans << LF;
	}

	return;
}

int main(){
	FAST;
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<double>> X(N, vector<double>(D));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  double dis;
  int ans = 0;
  for(int i = 0; i < N - 1; i++) {
    for(int j = i + 1; j < N; j++) {
      dis = 0;
      for(int k = 0; k < D; k++) {
        dis += pow(X[i][k] - X[j][k], 2.0);
      }
      dis = sqrt(dis);
      if(floor(dis) == dis) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S=input()
bb=S[0]
b=S[1]
flag=False
if bb==b:
    flag=True
    print("1 2")
if len(S)>2:
    for i in range(2,len(S)):
        if flag:
            break
        if S[i]==b or S[i]==bb:
            flag=True
            print(str(i-1)+" "+str(i+1))
            break
        bb,b=b,S[i]
if not flag:
    print("-1 -1")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535

int main (){
    int n,m;
    cin >> n >> m;
    int a[n];
    int count=0;
long  total=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        total += a[i];
    }
 
    for(int i=0;i<n;i++){
        if(a[i] >=  (double)((double)total/(double)(4*m)) )
        count++;
    }

    if(count >= m)
        cout << "Yes"<<endl;
    else
        cout << "No"<<endl;
    return 0;
    
}





Measured memory_bytes: 256
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    N = int(input())
    A = read_list()
    A.sort()
    s = 0
    res = 0
    for a in A:
        if s != 0 and s * 2 < a:
            res = 0
        s += a
        res += 1

    print(res)

        
if __name__ == "__main__":
    main()



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    pair<int,int> v1,v2, ans1, ans2;
    cin>>v1.first>>v1.second;
    cin>>v2.first>>v2.second;
    ans1.first = (v1.second-v2.second)+v2.first;
    ans1.second = -1*(v1.first-v2.first)+v2.second;

    ans2.first =  -1*(v2.second-v1.second) + v1.first;
    ans2.second = (v2.first-v1.first) + v1.second;

    cout<<ans1.first<<" "<<ans1.second<<" "<<ans2.first<<" "<<ans2.second<<endl;
}

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

int main() {
  int n; cin >> n;
  int sum =0;
  int m = 0;
  
  for(int i = 0; i < n; i++){
    int p; cin >> p;
    sum += p;
    m = max(m, p);
  }
  sum -= m/2;
  
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);

		while(scan.hasNext())
		{
			int d = scan.nextInt();
			int ans=0;
			int div = 600/d;

			for(int i=1; i <div; i++)
			{
				ans += funk(d,i);

			}
			System.out.println(ans);
		}
	}

	public static int funk(int d,int i)
	{
		return d*((d*i)*(d*i));
	}

}

Measured memory_bytes: 12000
package main

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

func main() {
	s := nextLine()
	for i := len(s) - 1; i > 0; i-- {
		if i%2 == 0 && s[:i/2] == s[i/2:i] {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(0)
}

const size = 1000000

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

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

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


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String word;
        line = br.readLine();
        if(line.length() > 3 && line != null && !line.isEmpty()) {
                word = line.substring(0, 4);
                if (word.equals("YAKI")) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
        }
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 23252
#include<stdio.h>
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
vector<vector<int> > g(100010);
int n,seen[100010];
mint dp[100010][3];
int dfs(int a){
  int i;
  seen[a]=1;
  dp[a][0]=1;
  dp[a][1]=1;
  for(i=0;i<g[a].size();i++){
    if(seen[g[a][i]]==1){
      continue;
    }
    dfs(g[a][i]);
    dp[a][0]*=dp[g[a][i]][0]+dp[g[a][i]][1];
    dp[a][1]*=dp[g[a][i]][0];
  }
}
int main(){
  int i,x,y;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d %d\n",&x,&y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1);
  printf("%d\n",dp[1][0]+dp[1][1]);
  return 0;
}

Measured memory_bytes: 11264