akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define int long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //

const int MX = 2e5 + 100;
VVI g;

bool vis[MX];


int dfs_count(int c, int p){
	vis[c] = 1;
	int count = 1;
	//debug(c);
	for(auto x : g[c]){
		//debug(x);
		if(!vis[x]){
			//debug(x);
			count += dfs_count(x, c);
		}
	}
	return count;
}


void solve(){
	int n, m;
	cin >> n >> m;
	g.resize(n);
	while(m--){
		int u, v;
		cin>>u>>v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	int ans = 0;
	loop(i, n) {
		//debug(g[i].size());
		if(!vis[i]) ans = max(ans, dfs_count(i, i));
		//debug(ans);
	}
	cout << ans;
}




int32_t main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> a;
    rep(i, m){
        int x, y;
        cin >> x >> y;
        a.push_back(P(x, y));
    }
    vector<P> memo = a;
    sort(memo.begin(), memo.end());
    map<P, int> b;
    b[memo[0]] = 1;
    for(int i = 1; i < m; i++){
        if(memo[i-1].first == memo[i].first){
            b[memo[i]] = b[memo[i-1]] + 1;
        }else{
            b[memo[i]] = 1;
        }
    }
    rep(i, m){
        printf("%06d%06d\n", a[i].first, b[a[i]]);
    }
    return 0;
}

Measured memory_bytes: 10992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int dp[102][102];

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, H); invar(int, W);
  
  vector<string> map(H);
  rep(i, H) {
    cin >> map[i];
  }
  
  rep(i, H) rep(j, W) dp[i][j] = INF / 2;
  
  dp[0][0] = map[0][0] == '#' ? 1 : 0;
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i-1 >= 0) chmin(dp[i][j], dp[i-1][j] + (map[i-1][j] != map[i][j] ? 1 : 0));
      if(j-1 >= 0) chmin(dp[i][j], dp[i][j-1] + (map[i][j-1] != map[i][j] ? 1 : 0));
    }
  }
  
  fin((dp[H-1][W-1] + 1) / 2);
}

Measured memory_bytes: 384
def m():
    N = int(input())
    X = [int(x) for x in input().split()]
    XX = [x for x in X]
    XX.sort()
    first = XX[N//2]
    second = XX[N//2 -1]
    for x in range(N):
        if X[x] <= second:
            print(first)
        else:
            print(second)


m()


Measured memory_bytes: 26772
import math
def myAnswer(N:int):
   return math.ceil(N/1.08) 

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   ans = myAnswer(N)
   if(N == math.floor(ans*1.08)):
      print(ans)
   else:
      print(":(")

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    g = gcd(a, b)

    ans = 1
    for i in range(1, int(g ** 0.5) + 1):
        if g % i == 0:
            if is_prime(i):
                ans += 1
            if is_prime(g // i):
                ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 41580
#!/usr/bin/env python3
n = int(input())
s = input()
e = [0]*n
w = [0]*n
for i in range(n):  
    if s[n-1-i] == "E":e[i] = e[i-1]+1
    else: e[i] = e[i-1]
    if s[i] == "W":w[i] = w[i-1]+1
    else: w[i] = w[i-1]
#print(e,w,s)
ans = e[n-2]
for i in range(1,n):
    #print(i,ans)
    if i == n-1:
        ans = min(ans,w[i-1])
    else: ans = min(ans,w[i-1]+e[n-2-i])
print(ans)


Measured memory_bytes: 17652
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];



void solve() {
  int x,y,z;
  cin >> x >> y >> z;
  if (x == y && y ==z && x == z) cout << 1 << endl;
  else if ((x == y && y!=z) || (x!=y && y==z) || (x==z && z!=y)) cout << 2 << endl;
  else cout << 3 << endl;
  
}


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

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

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

const LL mod = (LL)1e9 + 7;


int main() {
	int N;
	LL x;
	cin >> N >> x;
	vector<LL> A(N);
	REP(i, N) { cin >> A[i]; }

	LL ans = 0;
	for (int i = 1; i < N; i++) {

		LL over = A[i - 1] + A[i] - x;
		if (over>0) {

			if (A[i] >= over) {
				A[i] -= over;
			}
			else {
				A[i - 1] -= over - A[i];
				A[i] = 0;
			}
			ans += over;
		}

	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

deque<int> pos[28];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	pbds T;
	for(int i=0;i<s.length();i++) pos[s[i]-'a'].pb(i);
	ll ans = 0; int cnt=0; int bad=0;
	for(int i=0;i<s.length();i++)
	{
		if(T.find(i)!=T.end()) continue;
		char c = s[i];
		if(pos[c-'a'].size()==1)
		{
			if(bad){cout<<-1<<'\n'; return 0;}
			pos[c-'a'].pop_back(); T.insert(i);
			if(int(s.length())%2==1)
			{
				cnt++; bad=1;
				continue;
			}
			else
			{
				cout<<-1<<'\n'; return 0;
			}
		}
		pos[c-'a'].pop_front();
		int p = pos[c-'a'].back(); pos[c-'a'].pop_back();
		ans += int(s.length())-1-p - (T.size()-T.order_of_key(p+1));
		ans+=bad;
		T.insert(i); T.insert(p);
		cnt++;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 9876
function main(input) {
  const points = input.slice(1).map(x => x.split(' ').map(Number));

  var sum = 0;
  for (var i = 0; i < points.length; i++) {
    for (var j = i+1; j < points.length; j++) {
	  var len = length(sub(points[i], points[j]));
      if (isInteger(len)) {
        sum++;
      }
    }
  }

  console.log(sum);
}

const sub = (p1, p2) => {
  return p1.map((x, i) => x - p2[i]);
};

const length = (p) => {
  return Math.sqrt(p.map(x => x*x).reduce((acc, x) => acc + x, 0));
};

const isInteger = (n) => {
  const i = Math.floor(n);
  const eps = 0.0000001;

  return n-i < eps;
};

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'));


Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007


int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(2001, vector<char>(2001));
  rep(i, H) {
    rep(j, W) {
      cin >> S[i][j];
    }
  }

  vvi a(2001, vi(2001, 0)), hashx(2001, vi(2001, 0));
  rep(i, H) {
    int res = 0;
    rep(j, W) {
      if (S[i][j] == '#') {
        res++;
      }
      else if (S[i][j] == '.') {
        a[i][j] = res;
        hashx[i][res]++;
      }
    }
  }

  vvi b(2001, vi(2001, 0)), hashy(2001, vi(2001, 0));
  rep(j, W) {
    int res = 0;
    rep(i, H) {
      if (S[i][j] == '#') {
        res++;
      }
      else if (S[i][j] == '.') {
        b[i][j] = res;
        hashy[res][j]++;
      }
    }
  }
  int ans = 1;
  rep(i, H) {
    rep(j, W) {
      if (S[i][j] == '.') {
        int tmp = hashx[i][a[i][j]] + hashy[b[i][j]][j] - 1;
        ans = max(tmp, ans);
      }
    }
  }
  cout << ans << endl;

}





Measured memory_bytes: 69120
#!/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():
    m, d = rli()
    ans = 0
    for i in range(1, m+1):
        for j in range(1, d+1):
            d1 = j % 10
            d2 = j // 10
            if d1 < 2 or d2 < 2:
                continue
            if i == d1*d2:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

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

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

string s;


int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    srand(time(NULL));
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    cin >> s;
    int n = s.size();
    ll ans = 0;
    int sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'W') {
            ++sum;
            continue;
        }
        ans += sum;
    }
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 720
price = [int(input()) for _ in range(5)]

price = sorted(price, key=lambda x: x % 10)
ret = float('inf')

for i in range(5):
    s = sum(map(lambda x: x // 10 * 10 + (10 if x % 10 > 0 else 0), price[:i] + price[i + 1:])) + price[i]

    ret = min(ret, s)

print(ret)


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

int main() {
    int N; cin >> N;
    bool flag = false;
    for(int i = 1; i < 10; i++) {
        for(int j = 1; j < 10; j++){
            if (i * j == N) {
                flag = true;
            }
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main() {
  
  int n;
  
  REP(i,5) {
    cin >> n;
    if(n == 0) {
      cout << i+1 << endl;
      break;
    }
  }
}

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

int main()
{
	int K,X,Y;
	cin>>K>>X>>Y;
	if(abs(X) + abs(Y) == K)
	{
		cout<<"1\n"<<X<<" "<<Y<<endl;
		return 0;
	}
	int xsign=1,ysign=1;
	bool sw=false;
	if(X<0)
	{
		X *= -1;
		xsign=-1;
	}
	if(Y<0)
	{
		Y *= -1;
		ysign=-1;
	}
	if(X<Y)
	{
		swap(X,Y);
		sw=true;
	}
	int D=X+Y;
	int A=max(2,(D+K-1)/K);
	int L=A * K;
	if((L-D)%2)
	{
		A++;
		L += K;
		if((L-D)%2)
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	int R=(L-D)/2;
	vector<pair<int,int>> ans;
	bool ok=true;
	int px=0,py=0;
	for(int i=1; i<=A; i++)
	{
		int l=i*K;
		int x,y;
		if(l <= Y+R)
		{
			x=0;
			y=l;
		}
		else if(l <= Y+R+X)
		{
			l-=Y+R;
			x=l;
			y=Y+R;
		}
		else
		{
			l-=Y+R+X;
			x=X;
			y=Y + (R - l);
		}
		if(abs(px-x) + abs(py-y) == K)
		{
			ans.emplace_back(x,y);
			px=x;
			py=y;
		}
		else
		{
			ok=false;
			ans.clear();
			break;
		}
	}
	if(!ok)
	{
		int a=(K+D)/2;
		int b=R-a;
		for(int i=1; i<=A; i++)
		{
			int l=i*K;
			if(l <= a)
				ans.emplace_back(-l,0);
			else if(l <= a+Y+b)
			{
				l-=a;
				ans.emplace_back(-a,l);
			}
			else if(l <= a+Y+b+a+X)
			{
				l-=a+Y+b;
				ans.emplace_back(l-a,b+Y);
			}
			else
			{
				l-=a+Y+b+a+X;
				ans.emplace_back(X,Y + (b-l));
			}
		}
	}
	if(sw)
		for(int i=0; i<A; i++)
			swap(ans[i].first,ans[i].second);
	cout<<A<<endl;
	for(auto& p : ans)
		printf("%d %d\n",p.first*xsign,p.second*ysign);
	return 0;
}


Measured memory_bytes: 3952
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n; cin >> n;
	VI p(n); rep(i, n)cin >> p[i];

	int ans = INT_MAX;
	rep(i, p[0] + 1) {
		int cnt = 0;
		VI a = p;

		cnt += i; a[0] -= i;
		rep(i, n - 1) {
			cnt += a[i] * 2;
			a[i + 1] = max(0, a[i + 1] - a[i]);
			a[i] = 0;
		}
		cnt += a[n - 1];
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}


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

using namespace std;
int p[100000];


int main(){
    int N, ans = 0;
    cin >> N;
    for(int i=0; i<N; i++) cin >> p[i];

    for(int i=0; i<N-1; i++) {
        if(p[i] == i+1) {
            swap(p[i], p[i+1]);
            ans++;
        }
    }
    if(p[N-1] == N) ans++;
    cout << ans << endl;

    return 0;
}

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

int main(){
     int a,b,c,cnt=0;
     cin >> a >> b >> c;
    //bool can = false;
     for (int i =a;i <= b;i+=a){
         cnt++;
         //cout << i << endl;
         if(cnt==c) {
             //cnt == c;
             break;
         }

     }
     cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
//i ll be the king
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[3][2];
	for(ll i=0;i<2;i++)
	for(ll j=0;j<3;j++)
	cin>>arr[j][i];
	vector<ll> dp(n+1,0);
	for(ll j=0;j<3;j++)
	for(ll i=1;i<=n;i++)
	if(i>=arr[j][0])
	dp[i]=max(dp[i],dp[i-arr[j][0]]+arr[j][1]-arr[j][0]);
	n+=dp[n];
	vector<ll> dp2(n+1,0);
	for(ll j=0;j<3;j++)
	for(ll i=1;i<=n;i++)
	if(i>=arr[j][1])
	dp2[i]=max(dp2[i],dp2[i-arr[j][1]]-arr[j][1]+arr[j][0]);
	cout<<n+dp2[n];
}
	

Measured memory_bytes: 195584
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
const int MOD = 1e9 + 7;
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int ans=0;
    rep(i,n) {
        cin >> a[i];
        ans+=a[i]-1;
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }
    int out = max(dp[n-1][0], dp[n-1][1]);
    out = max(dp[n-1][2], out);
    cout << out << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 305;
const int inf = 1e18;

int n, m, l;
int dist[N][N], dp[N][N];

void FloydWarshall()
{
	for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

void work()
{
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(dist[i][j] <= l)
				dp[i][j] = 0;
	for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				if(dp[i][k] < inf && dp[k][j] < inf)
					dp[i][j] = min(dp[i][j], 1 + dp[i][k] + dp[k][j]);
}

int32_t main()
{
	IOS;
	cin >> n >> m >> l;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(i != j)
				dist[i][j] = dp[i][j] = inf;
	for(int i = 1; i <= m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		if(w <= l)
			dist[u][v] = dist[v][u] = min(dist[u][v], w);
	}
	FloydWarshall();
	work();
	int q;
	cin >> q;
	while(q--)
	{
		int s, t;
		cin >> s >> t;
		int ans = dp[s][t];
		if(ans > 1e9)
			ans = -1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)

class UnionFind{
    //par[i] = jの時、iの親がjに相当
    vector<int> par, rank, size;
public:
    
    UnionFind(int N) //par(N)を全て根として初期化
    : par(N), rank(N), size(N)
    {
        rep(i,0,N){
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) 
    {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        //rxが常に根に来るようにする。
        if(rank[rx] < rank[ry]) swap(rx,ry);
        if(rank[rx] == rank[ry]) rank[rx]++;
        par[ry] = rx;
        return true;
    }
    bool isSame(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    UnionFind UF(N);
    rep(i,0,M){
        int x, y, z;
        cin >> x >> y >> z;
        UF.unite(x-1, y-1);//0-index
    }
    set<int> s;
    rep(i,0,N) s.insert(UF.root(i));
    cout << s.size() << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <queue>
#include <map>

using namespace std;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
int main() {
  int N, A[3];
  ins(N, A[0], A[1], A[2]);
  map<string, pair<int, int>> m = {
    {"AB", {0, 1}},
    {"AC", {0, 2}},
    {"BC", {1, 2}},
  };

  if (A[0] + A[1] + A[2] == 0) {
    cout << "No\n";
    return 0;
  }
  string s[N];
  rep(i, N) { cin >> s[i]; }

  if (A[m[s[0]].first] + A[m[s[0]].second] == 0) {
    cout << "No\n";
    return 0;
  }

  queue<int> q;
  if (A[0] + A[1] + A[2] == 1) {
    rep(i, N) {
      int fst = m[s[i]].first, snd = m[s[i]].second;
      if (A[fst] + A[snd] == 0) {
        cout << "No\n";
        return 0;
      }
      q.push(A[fst] == 0 ? fst : snd);
      swap(A[fst], A[snd]);
    }
    cout << "Yes\n";
    while (!q.empty()) {
      cout << (char)(q.front() + 'A') << endl;
      q.pop();
    }
    return 0;
  }

  cout << "Yes\n";
  rep(i, N) {
    int fst = m[s[i]].first, snd = m[s[i]].second;
    if (A[fst] == 0)
      swap(fst, snd);
    else if (A[snd] != 0) {
      if (A[0] + A[1] + A[2] == 2) {
        if (i == N-1) {
          q.push(fst);
          continue;
        }
        if (s[i+1] != s[i] && (m[s[i+1]].first == fst || m[s[i+1]].second == fst))
          swap(fst, snd);
      } else if (A[fst] < A[snd])
        swap(fst, snd);
    }
    q.push(snd);
    --A[fst]; ++A[snd];
  }
  while (!q.empty()) {
    cout << (char)(q.front() + 'A') << endl;
    q.pop();
  }
  return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int nx[N],u[N];
vector<int> G[N];
vector<int> cycles[N];
int ct[N],cy[N],ln[N];ll dp[N];
int main(){
  int n; scanf("%d",&n);
  REP(i,n){
    scanf("%d",&nx[i]); nx[i]--;
  }
  int tl=0;
  ll ans=1;
  REP(i,n) if(u[i]==0){
    u[i]=i+1;
    int x=nx[i];
    while(u[x]==0){
      u[x]=i+1; x=nx[x];
    }
    if(u[x]==i+1){
     // printf("%d\n",x+1);
      cycles[tl].pb(x);
      int t=nx[x]; cy[x]=1;
      while(t!=x){
        cy[t]=1; cycles[tl].pb(t); t=nx[t];
       // printf("%d\n",t);
      }
      tl++;
    }
  }
 // printf("h\n");
  REP(i,n) if(cy[i]==0) G[nx[i]].pb(i);
  REP(i,n) if(G[i].size()>1) ans=0;
  if(ans==0) {printf("0\n"); exit(0);}
  FILL(u,0);
  REP(i,n) if(cy[i]){
    ln[i]=0;
    int c=i;
    while(G[c].size()){
      c=G[c][0]; ln[i]++;
    }
  }
 // printf("lol\n");
  REP(i,tl){
    int fl=0;
    REP(j,cycles[i].size()) if(G[cycles[i][j]].size()) fl=1;
    if(fl==0) ct[cycles[i].size()]++;
    else{
      int cr = 0;
      while(G[cycles[i][cr]].size()==0) cr++;
      int tk=cr;
      int lg=0,n=cycles[i].size();
      while(lg<n){
        int pv=(tk-1+n)%n,ex=1;
        while(ln[cycles[i][pv]]==0) pv=(pv-1+n)%n,ex++;//,printf("%d %d\n",pv,);
        if(ln[cycles[i][tk]]>ex) ans=0;
        else if(ln[cycles[i][tk]] <ex) ans=ans*2%mod;
     //   printf("%d %d %d %lld\n",cycles[i][tk]+1,ln[cycles[i][tk]],ex,ans);
        tk=pv; lg+=ex;
      }
    }
  }
  REP(i,n+1) if(ct[i]){
    dp[0]=1;
   // printf("%d %d\n",i,ct[i]);
    REPP(j,1,ct[i]+1){
      if(i%2&&i>1) dp[j]=dp[j-1]*2%mod;
      else dp[j]=dp[j-1];
      if(j>1) dp[j]=(dp[j]+dp[j-2]*(j-1)%mod*i%mod)%mod;
    }
    ans=ans*dp[ct[i]]%mod;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 56064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();

		long ans = 0;
		for (long i = 1; i < N; i++){
			ans += i;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template<uint64 MOD>
class modint {
public:
	uint32 a;
	modint(uint32 x = 0) :a(x < MOD ? x : x%MOD) {}
	modint operator+(const modint o) const{
		if (a + o.a < MOD) return modint(a + o.a);
		return modint(a + o.a - MOD);
	}
	modint &operator+=(const modint o) {
		a += o.a;
		if (a >= MOD) a -= MOD;
		return *this;
	}
	modint operator-(const modint o) const{
		if (a < o.a) return modint(a + MOD - o.a);
		return modint(a - o.a);
	}
	modint &operator-=(const modint o) {
		if (a < o.a) a += MOD;
		a -= o.a;
		return *this;
	}
	modint operator*(const modint o) const{
		return modint((uint64)a*(uint64)o.a%MOD);
	}
	modint &operator*=(const modint o) {
		a = (uint64)a*(uint64)o.a%MOD;
		return *this;
	}
	modint operator/(const modint o) const {
		return *this*~o;
	}

	modint operator-() const{
		if (a) return modint(MOD - a);
		return modint(0);
	}
	modint operator++() {
		++a;
		if (a == MOD) a = 0;
		return *this;
	}
	modint operator++(int) {
		if (a == MOD - 1) {
			a = 0;
			return modint(MOD - 1);
		}
		++a;
		return modint(a - 1);
	}
	modint operator--() {
		if (a) {
			--a;
		}
		else {
			a = MOD - 1;
		}
		return *this;
	}
	modint operator--(int) {
		if (a) {
			--a;
			return modint(a + 1);
		}
		a = MOD - 1;
		return modint(0);
	}
	modint operator~() const {
		int64 x = a, y = MOD, u = 1, v = 0, t;
		while (y) {
			t = x / y;
			x -= t*y;
			std::swap(x, y);
			u -= t*v;
			std::swap(u, v);
		}
		return modint(u);
	}
	bool operator!() const{
		if (a) return false;
		return true;
	}
	bool operator==(const modint o) const{
		return a == o.a;
	}
	bool operator!=(const modint o) const{
		return a != o.a;
	}
	bool operator<(const modint o) const{
		return a < o.a;
	}
	bool operator<=(const modint o) const{
		return a <= o.a;
	}
	bool operator>(const modint o) const{
		return a > o.a;
	}
	bool operator>=(const modint o) const{
		return a >= o.a;
	}
};

using mint = modint<1000000007>;
int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n;
	std::string s;
	std::cin >> n >> s;
	mint dp[5003][5003] = {};
	dp[0][0] = mint(1);
	for (uint32 i = 1;i <= n;++i) {
		dp[i][0] = dp[i - 1][1] + dp[i - 1][1] + dp[i - 1][0];
		for (uint32 j = 1;j <= i;++j) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] + dp[i - 1][j + 1];
		}
	}
	std::cout << dp[n][s.length()].a << "\n";
	return 0;
}

Measured memory_bytes: 195840
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <tuple>
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> tup;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
int n, m, l, k, a, h;
bool reitou[110];
vector<pair<int, int> > G[110];
//dist[u][t] :=????????¨????????????u??§???????????????t???????????????????????????
int dist[110][110];

void dijkstra(int start){
    rep(i, 110)rep(j, 110){
    	dist[i][j] = INF;
    }
    priority_queue<tup, vector<tup>, greater<tup> >  q;
    q.push(make_tuple(0, start, m));//??????????????¨????????????????????????

    while(!q.empty()){
        int cost, u, t;//????????§???????????£????????? ?????¨?????????????§£???????????§???????????????
        tie(cost, u, t) = q.top(); q.pop();
        if(dist[u][t] < cost) continue;
        for (auto tmp : G[u]){
            int v = tmp.first, time = tmp.second;//??£??\???????????? ?????????????????§????????????
            if(reitou[u]){//????????????
            	for (int i = 0; i <= m; ++i){//i?????????????????????
            		if(t + i > m) break;//????§?????????????????????????
            		if(t + i - time < 0) continue;
            		if(cost + i + time < dist[v][t + i - time]){//??????????????´??°
                		dist[v][t + i - time] = cost + i + time;
                		q.push(make_tuple(dist[v][t + i - time], v, t + i - time));
            		}
            	}
            }else{
            	if(t - time < 0) continue;
            	if(cost + time < dist[v][t - time]){//??????????????´??°
                	dist[v][t - time] = cost + time;
                	q.push(make_tuple(dist[v][t - time], v, t - time));
            	}
            }
        }
    }
}

int main(void){
	while(1){
		cin >> n >> m >> l >> k >> a >> h;
		if(n == 0) return 0;
		rep(i, 110) reitou[i] = false;
		rep(i, 110) G[i].erase(G[i].begin(), G[i].end());
		rep(i, l){
			int tmp; cin >> tmp;
			reitou[tmp] = true;
		}

		rep(i, k){
			int u, v, c; cin >> u >> v >> c;
			G[u].push_back(make_pair(v, c));
			G[v].push_back(make_pair(u, c));
		}

		dijkstra(a);
		int ans = INF;
		for (int i = 0; i <= m; ++i){
			ans = min(ans, dist[h][i]);
		}
		if(ans == INF){
			printf("Help!\n");
		}else{
			printf("%d\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 3448
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.math;

private{
alias real F;
bool eq(F[] a, F[] b){ return a[0]==b[0] && a[1]==b[1]; }
F norm2(F[] a){ return a[0]^^2+a[1]^^2; }
F dist2(F[] a, F[] b){ return (a[0]-b[0])^^2+(a[1]-b[1])^^2; }
F cross(F[] a, F[] b){ return a[0]*b[1]-b[0]*a[1]; }
F[] circumcenter(F[] a, F[] b, F[] c)
{
    F[] vb = [2*(b[0]-a[0]),2*(c[0]-a[0])];
    F[] vc = [2*(b[1]-a[1]),2*(c[1]-a[1])];
    F[] vd = [norm2(a)-norm2(b),norm2(a)-norm2(c)];
    F cbc = cross(vb,vc);
    return [cross(vc,vd)/cbc, cross(vd,vb)/cbc];
}
}

void main()
{
    for(int n; 0!=(n=readln().chomp().to!int()); )
    {
        auto ps = iota(n).map!(_=>readln().chomp().split(",").map!(to!F).array()).array();
        auto s = new bool[][](n,n);
        foreach(i;0..n-1)
            foreach(j;i+1..n)
                if(!eq(ps[i],ps[j]) && dist2(ps[i],ps[j])<=4)
                    s[i][j]=s[j][i]=true;
        size_t m=1;
        foreach(i;0..n-1) foreach(j;i+1..n)
        {
            {
                auto c = [(ps[i][0]+ps[j][0])/2,(ps[i][1]+ps[j][1])/2];
                m=max(m,ps.count!(p=>dist2(p,c)<=1)());
            }
            if(!s[i][j]) continue;
            m=max(m,2);
            foreach(k;j+1..n) if(s[i][k]&&s[j][k])
            {
                auto c = circumcenter(ps[i],ps[j],ps[k]);
                m=max(m,ps.count!(p=>dist2(p,c)<=1)());
            }
        }
        writeln(m);
    }
}

Measured memory_bytes: 2040
//https://atcoder.jp/contests/dp/tasks/dp_l

#include <bits/stdc++.h>
#define ALL(e) e.begin(), e.end()
#define RALL(e) e.rbegin(), e.rend()
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define dbg(x) (cerr << #x << ":" << x)
#define mid (l + r) / 2
#define fi first
#define sc second
#define N 1000000009

using namespace std;

typedef long long int lli;

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector <lli> ar(n);
	for(int i=0; i<n; i++) cin >> ar[i];

	lli dp[n+5][n+5];

	memset(dp, 0, sizeof dp);

	for(int l=n-1; l>=0; l--){
		for(int r=l; r<n; r++){
			dp[l][r] = max(ar[l] - dp[l+1][r], ar[r] - dp[l][r-1]);
		}
	}

	cout << dp[0][n-1];

	return 0;
}

Measured memory_bytes: 70784
n, t = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]
items.sort()
ma = items[-1][0]
dp = [0] * (t+ma)

for a, b in items:
    for i in range(t+ma-1, a-1, -1):
        if i-a < t:
            dp[i] = max(dp[i], dp[i-a] + b)

print(max(dp))


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

int main() {
    int64_t a;
    cin >> a;
    string b;
    cin >> b;
    string c = "";
    c.push_back(b.at(0));
    c.push_back(b.at(2));
    c.push_back(b.at(3));
    int64_t d = stoi(c);
    int64_t e = a * d / 100;
    cout << e << endl;
}

Measured memory_bytes: 3628
using System;

namespace abc116_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int s;
            string[] array = Console.ReadLine().Split(' ');
            int ab = int.Parse(array[0]);
            int bc = int.Parse(array[1]);
            int ca = int.Parse(array[2]);
            s = ab * bc / 2;
            Console.WriteLine(s);
        }
    }
}


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

int main () {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < N-2; i++){
    bool abc = true;
    if (S.at(i) != 'A') abc = false;
    else if (S.at(i+1) != 'B') abc = false;
    else if (S.at(i+2) != 'C') abc = false;
    if (abc) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
    val sc = new java.util.Scanner(System.in)

    val n = sc.nextInt
    val k = sc.nextInt
    val a = IndexedSeq.fill(n)(sc.nextInt)
    for (i <- k until n) {
        println(if (a(i) > a(i-k)) "Yes" else "No")
    }

}

Measured memory_bytes: 65996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		while (true)
		{
			var S = Console.ReadLine();
			if (string.IsNullOrEmpty(S))
			{
				return;
			}
			var arr = new int[10,10];
			for (int i = 0; i < 10; i++)
			{
				arr[0,i] = S[i] - '0';
			}
			for (int i = 0; i < 9; i++)
			{
				for (int j = 0; j + i < 9; j++)
				{
					arr[i+1,j] = (arr[i,j] + arr[i,j+1]) % 10;
				}
			}
			Console.WriteLine(arr[9,0]);
		}
	}
}

Measured memory_bytes: 9008
import sys
input = sys.stdin.readline
def print_ans(a, b):
    """Test Case
    >>> print_ans(4, 3)
    3333
    >>> print_ans(7, 7)
    7777777
    """
    if a > b:
        print(str(b) * a)
    else:
        print(str(a) * b)


if __name__ == '__main__':
    a, b = map(int, input().rstrip().split())
    print_ans(a, b)




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

int main() {
  int n;

  cin >> n;

  vector<int> b, a;

  for (int i = 0; i < n - 1; i++) {
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }

  int ans = b.at(0) + b.at(n - 2);

  for (int i = 0; i < n - 2; i++) {
    ans += min(b.at(i), b.at(i + 1));
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}
 
signed main() {
    int d, e;
    while(cin >> d >> e, d || e) {
        double mi = INF;
        repq(i,0,d) {
            double x = i, y = d - i;
            // printf("x = %f, y = %f, dist = %f\n", x, y, abs(sqrt((x * x + y * y)) - e));
            mi = min(mi, abs(sqrt((x * x + y * y)) - e));
        }
        cout << fixed << setprecision(10) << mi << endl;
    }
    return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>c(n,0),s(n,0),f(n,0);
    for(ll i=0;i<n-1;i++){
        cin >> c[i] >> s[i] >> f[i];
    }
    vector<ll>ans(n,0);
    for(ll i=0;i<n;i++){
        ll j=i+1;
        ll time=c[i]+s[i];
        while(j<n-1){
            if(time<s[j]){
                time=s[j];
            }
            if(time%f[j]!=0){
                ll dt=f[j]-(time%f[j]);
                time+=dt;
            }
            time+=c[j];
            j++;
        }
        ans[i]=time;
    }
    for(ll i=0;i<n;i++){
        cout << ans[i] << endl;
    }
}


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

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}

double power(double vol, double k, int b){
       //double ans1 = 1.0;
       for(int i = 0; i < b; i++){
           vol -= vol*k;
       }
       return vol;
}

double pi = 3.14;

int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    //cin.sync_with_stdio(false);
    //cin.tie(0); cout.tie(0);
    int a, b, c, d;
    cin >> a >>b >> c >> d;
    int s = max(a, c);
    int e = min(b, d);
    if(e-s < 0){
       cout << 0;
    }
    else{
       cout << e-s;
    }
    return 0;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll arr[maxn], prefix[maxn];
ll check(int val, int n) {
    ll cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int pos = lower_bound(arr + 1, arr + 1 + n, val - arr[i]) - arr;
        cnt += n + 1 - pos;
    }
    return cnt;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; ll m; cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    sort(arr + 1, arr + 1 + n);
    for (int i = 1; i <= n; ++i) prefix[i] = prefix[i - 1] + arr[i];
    int left = 0, right = 2 * maxn; ll res = 0;
    while (left <= right) {
        ll mid = (left + right) / 2; ll cnt;
        if ((cnt = check(mid, n)) < m)
            right = mid - 1;
        else {
            left = mid + 1, res = 0;
            for (int i = 1; i <= n; ++i) {
                int pos = lower_bound(arr + 1, arr + 1 + n, mid - arr[i]) - arr;
                res += (ll)(n + 1 - pos) * arr[i] + prefix[n] - prefix[pos - 1];
            }
            if (cnt > m) res -= (cnt - m) * mid;
        }
    }
    cout << res << '\n';
}

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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() { 
	
	string S;
	cin >> S;
	int A = S[0] - '0',B = S[1] - '0',C = S[2] - '0',D = S[3] - '0';
	int a[4];
  	a[0] = A;
  	a[1] = B;
  	a[2] = C;
  	a[3] = D;
	for(int i = 0; i < 2; i++) {
		a[1] *= -1;
		for(int j = 0; j < 2; j++) {
			a[2] *= -1;
			for(int k = 0; k < 2; k++) {
				a[3] *= -1;
				int sum = a[0] + a[1] + a[2] + a[3];
					if(sum == 7) {
						cout << a[0];
						for(int i = 1; i < 4; i++) {
							if(a[i] >= 0) {
								cout << '+' << a[i];
							}else {
								cout << a[i];
							}
						}
						cout << '=' << 7 << endl;
						return 0;
					}
				}
			}
		}
    return 0;
}


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

int main() {
  int N; 
  int judge = 0;
  string S;
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    cin >> S;
    if(S == "Y")
      judge = 1;
  }
  if(judge == 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}


Measured memory_bytes: 256
N,T=map(int,input().split())
ans=-1
for i in range(N):
    c,t=map(int,input().split())
    if t<=T:
        if ans==-1:
            ans=c
        else:
            if ans>c:
                ans=c
if ans==-1:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3064
N = int(input())
H = [int(e) for e in input().split()]
count_max = 0
i = 0
while i < N:
  judge = True
  count = 0
  tmp = i
  for j in range(tmp,N):
    if j < N-1:
      if H[j] >= H[j+1]:
        count += 1
      else:
        break;

  #print(count)
  if count_max < count:
    count_max = count
  if judge == True:
    i += count + 1

print(count_max)

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

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

int main(){
    ll k;
    cin >> k;
    if(k==0){
        cout << 2 << endl;
        cout << "1 1" << endl;
        return 0;
    }
    int n = 50;
    ll x = k/50;
    ll r = k%50;

    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        a[i] = i+x;
    }

    for(int i = 0; i < r; i++){
        vector<ll>::iterator min = min_element(a.begin(), a.end());
        size_t minIndex = distance(a.begin(), min);
        for(int j = 0; j < n; j++){
            if(j==minIndex){
                a[j] += n;
            }else{
                a[j] -= 1;
            }
        }
    }
    cout << n << endl;
    for(int i = 0; i < n; i++){
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;

}


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

int main() {
	ll n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(ll i=0;i<n;i++){
		cout << s[i]<<t[i];
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <cmath>

using namespace std;

bool is_prime(int num);

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

	if (a == 1 && b == 1) {
		cout << 1 << endl;
		return 0;
	}

	int ans = 1;
	for (int i = 2; i <= sqrt(a) + 1; i++) {
		if (a % i == 0 && b % i == 0) {
			ans += is_prime(i) ? 1 : 0;
			while (b % i == 0) {
				b /= i;
			}
		} else if (b % i == 0) {
			while (b % i == 0) {
				b /= i;
			}
		}
	}

	if (a % b == 0 && b >= sqrt(a)) {
		ans++;
	}
	cout << ans << endl;

	return 0;
}

bool is_prime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum + 1; i += 2) {
		if (num % i == 0) {
			return false;
		}
	}

	return true;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

  array<int,3> l;
  for(auto& x:l) x=in();
  sort(ALL(l));
  
  cout << ((l[0]*l[1])/2) << endl;
  return 0;
}


Measured memory_bytes: 256