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

using namespace std;

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

	int a, b, c, d;
	a = n / 1000;
	b = (n / 100) % 10;
	c = (n / 10) % 10;
	d = n % 10;

	if ((a == b) && (b == c) || (b == c && c == d)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5+2;
int n,a[M],b[M],c[M];
int dp[3][M];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    }
    dp[0][1]=a[1];
    dp[1][1]=b[1];
    dp[2][1]=c[1];
    for(int i=2;i<=n;i++){
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
        dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c[i];
    }
    printf("%d",max(max(dp[1][n],dp[0][n]),dp[2][n]));
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,A,B,C,ans;
  ans=0;
  cin>>A>>B>>C;
  a=min(A,min(B,C));c=max(A,max(B,C));b=A+B+C-a-c;
  ans+=(c-a)/2+(c-b)/2;
  a+=((c-a)/2)*2;
  b+=((c-b)/2)*2;
  if(2*c-a-b==2){cout<<ans+1<<endl;}
  else if(2*c-a-b==1){cout<<ans+2<<endl;}
  else{cout<<ans<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool is_pali(int v) {
  if (v / 10000 != v % 10) return false;
  if (v / 1000 % 10 != ((v % 100) / 10)) return false;
  return true;
}

int main()
{
  int A,B,cnt=0;
  cin >> A >> B;
  for(int i=A;i<=B;i++) {
    if (is_pali(i)) cnt++;
  }
  cout<<cnt<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count = 0;
		int[][] a = new int[n][m];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j <m; j++) {
				a[i][j] = 0;
			}
		}
		for(int i = 0; i < n; i++) {
			int k = sc.nextInt();
			for(int j = 0; j < k; j++) {
				int temp = sc.nextInt()-1;
				a[i][temp] = 1;
			}
		}
		for(int i = 0; i < m; i++) {
			boolean flag = true;
			for(int j = 0; j <n; j++) {
				if(a[j][i]==0) {
					flag = false;
					break;
				}
			}
			if(flag) {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

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

    if(n==2){
        cout << "Borys";
    } else {
        if((b-a)%2==0)
            cout << "Alice";
        else
            cout << "Borys";
    }
    cout << endl;

    return 0;
}

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

int main(){
  int n;
  vector<int> x, y;
  
  cin >> n;
  
  vector<int> order(n);
  x.resize(n);
  y.resize(n);
  rep(i, n){
    cin >> x[i];
    cin >> y[i];
    order[i]=i;
  }
  
  double sum=0;
  int cnt=0;
  double xi, xj, yi, yj;
  do
  {
    rep(i, n-1){
      xi = x[order[i]];
      xj = x[order[i+1]];
      yi = y[order[i]];
      yj = y[order[i+1]];
      sum += sqrt(pow(xi-xj, 2) + pow(yi-yj, 2));
    }
    cnt++;
  } while (next_permutation(order.begin(), order.end()));
  
  
  cout << fixed << setprecision(6) << sum/cnt << endl;
  return 0;
}


Measured memory_bytes: 3896
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
int main(){
    int n;
    cin >> n;
    ll ans=1;
    bool Ch=0;
    rep(i,n){
        ll a;
        cin >> a;
        if(a==0){
            cout<<0<<endl;
            return 0;
        }
        ll A=1000000000000000000/ans+1;
        if(ans!=0&&A<=a){
            Ch=1;
            ans=0;
        }
        ans*=a;
    }
    if(Ch==1){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
	Scanner scan = new Scanner(System.in);
	List<String> printList = new ArrayList<String>();

	String str = scan.next();
	int n = scan.nextInt();
	
	for (int i = 0; i < n; i ++) {
		String op = scan.next();
		int start = scan.nextInt();
		int end = scan.nextInt() + 1;
		
		if ("replace".equals(op)) {
			String replaceStr = scan.next();
			str = str.substring(0, start) + replaceStr + str.substring(end, str.length());
		} else if ("reverse".equals(op)) {
			str = str.substring(0, start) + new StringBuffer(str.substring(start, end)).reverse().toString() + str.substring(end, str.length());
		} else if ("print".equals(op)) {
			printList.add(str.substring(start, end));
		}
	}

	for (String s : printList) {
		System.out.println(s);
	}

}
}

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

const ll inf = 1e10;

int main() {
	int n, W;
	cin >> n >> W;
	vector<ll> w(n), v(n);
	for (ll i = 0; i < n; ++i)cin >> w[i] >> v[i];
	vector<vector<ll>> dp(n, vector<ll>(W + 1, 0));
	dp[0][w[0]] = v[0];
	for (ll i = 1; i < n; ++i) {
		dp[i] = dp[i - 1];
		for (ll j = 0; j <= W - w[i]; ++j) {
			dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]);
		}
	}
	cout << *max_element(dp.back().begin(), dp.back().end()) << endl;
}


Measured memory_bytes: 79360
#include <iostream>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main() {
  while (1) {
    int n, ans = 0;
    cin >> n;
		if (n<=0) return 0;
    for (int i = 2; i * (i + 1) <= 2 * n; i++) {
      if (i % 2 == 0 && (n - (i / 2)) % i == 0) {
        ans++;
        // debug(i);
      } else if (i % 2 == 1 && n % i == 0) {
        ans++;
        // debug(i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 2988
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		if(s.charAt(0)==s.charAt(s.length()-1)){
			if((s.length()-2)%2==0){
				System.out.println("First");
			}else{
				System.out.println("Second");
			}
		}else{
			if((s.length()-2)%2==0){
				System.out.println("Second");
			}else{
				System.out.println("First");
			}
		}
	}
}

Measured memory_bytes: 25556
def euclides(a, b):
    r = a%b
    q = 0
    while(r != 0):
        q = a/b
        a = b
        b = r
        r = a%b
    q = a/b
    return b

foo = list(map(int, input().split()))
A = foo[0]
B = foo[1]
K = foo[2]

GCD = euclides(A, B) # GCD
div = 1
while(GCD > 0):
    if div == K:
        break
    GCD -= 1
    if A%GCD == 0 and B%GCD == 0:
        div += 1

print(GCD)



Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int a,b,c;
  char s[1005];
  
  scanf("%s",s);
  a=strlen(s)-1;
  if(s[a]=='s'){
   printf("%ses",s);
    return 0;
  }
  printf("%ss",s);
  return 0;
}





Measured memory_bytes: 2156
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>
//#include <bits/stdc++.h>
#include <cassert>
#include <map>
#include <bitset>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int maxn = 1e5+1;
int n, m;
int cnt[maxn];
bool has[maxn];
int main()
{

  int n, m;
  scanf("%d %d", &n, &m);
  fill(cnt+1, cnt+n+1, 1);
  has[1] = 1;
  for (int i = 0; i < m; ++i)
    {
      int x, y;
      scanf("%d %d", &x, &y);
      if (has[x])
	has[y] = true;
      --cnt[x];
      ++cnt[y];
      if (cnt[x] == 0)
	has[x] = 0;
    }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += has[i];
  printf("%d\n", ans);
}


Measured memory_bytes: 768
unittest
{
	assert( [ "4" ].parse.expand.solve == "3\n1" );
	assert( [ "7" ].parse.expand.solve == "4\n3" );
	assert( [ "1" ].parse.expand.solve == "1" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	// 解く必要がある問題の最大値を計算
	auto i = 1L;
	for( ; i <= n + 1; i++ )
	{
		auto t = ( i * ( i + 1 ) ) / 2;
		if( n <= t ) break;
	}
	
	// 解く必要がある問題を列挙
	auto anss = new long[ n ];
	auto ansi = 0L;
	auto t = 0L;
	for( ; 0 < i && t != n; i-- )
	{
		if( n < t + i ) continue;
		t += i;
		anss[ ansi ] = i;
		ansi++;
	}
	return anss[ 0 .. ansi ].to!( string[] ).join( "\n" );
}


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

using namespace std;

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

  vector<int> vec[N];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }

  for (int i = 0; i < N; i++) {
    cout << vec[i].size() << endl;
  }
}

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

int N;
int imosu[IMOSU_MAX];
int a,b;
int ans;

int main() {
	cin>>N;
	for (int i = 0; i < N; i++) {
		cin>>a>>b;
		imosu[a]++;
		imosu[b+1]--;
	}
	imosu[0]++;
	for (int i = 1; i < IMOSU_MAX; i++) {
		imosu[i]+=imosu[i-1];
		if(i>=ans && imosu[i]>=i)ans=i;
	}
	//for(int i=0;i<10;i++)cout<<" "<<imosu[i];
	cout<<ans-1<<endl;
	//cin>>N;
	return 0;
}

Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,x,y,z) for(int i=x; i<=y; i+=z)

int main(){
	IOS
	// do magic here
	ll n;
	cin>>n;
	vector<ll> v1(n),v2(n),v3(n);
	loop(i,0,n-1,1) cin>>v1[i];
	loop(i,0,n-1,1) cin>>v2[i];	
	// iota(v3.begin(),v3.end(),1);
	loop(i,0,n-1,1) v3[i]=i+1;
	ll c=1;
	ll a=1,b=1;
	do{
		if (v3==v1) a=c;
		if (v3==v2) b=c;
		c++;
	}while(next_permutation(v3.begin(),v3.end()));
	cout<<abs(a-b);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    char c;
    for(int i=1;cin>>c;i++){
        if(c=='A'&&!a)a=i;
        if(c=='Z')b=i;
    }
    cout<<b-a+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct UnionFind{

    LL size;
    vector<LL> set;
    
    UnionFind(LL n):size(n){
        set = vector<LL>(size+1,-1);
    }

    LL parent(LL x){
        if(set[x] < 0) return x;

        return (set[x] = parent(set[x]));
    }

    void unite(LL a,LL b){
        LL a_p = parent(a);
        LL b_p = parent(b);
        if(a_p == b_p){
            return;
        }
        LL a_s = sized(a_p);
        LL b_s = sized(b_p);
        if(a_s > b_s){
            set[a_p] -= b_s;
            set[b_p] = a_p;
        }else{
            set[b_p] -= a_s;
            set[a_p] = b_p;
        }
    }

    LL sized(LL x){
        return abs(set[parent(x)]);
    }

};

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

    LL N,M;
    cin >> N >> M;

    vector<vector<LL>> edge(M+1);

    for(int i = 1; i < N+1; i++){
        LL K;
        cin >> K;
        for(int j = 0; j < K; j++){
            LL x;
            cin >> x;
            edge[x].push_back(i);
        }
    }

    UnionFind uf(N);

    for(int i = 1; i < M+1; i++){
        LL tmp;
        if(edge[i].size() > 0){
            tmp = edge[i][0];
        }
        for(int j = 1; j < edge[i].size(); j++){
            uf.unite(tmp,edge[i][j]);
        }
    }

    bool frag = true;
    LL tmp = uf.parent(1);

    for(int i = 2; i < N+1 && frag; i++){
        if(tmp != uf.parent(i)){
            frag = false;
        }
    }

    if(frag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
int main()
{
    int n;
   scanf("%d", &n);
    vector<int> dp(3);
    for(int day=0;day<n;++day){
            vector<int>newdp(3,0);
            vector<int>k(3);
            for(int i=0;i<3;++i){
               scanf("%d",&k[i]);
            }

            for(int i =0;i<3;++i){
                for(int j=0;j<3;++j){
                   if(i!=j){
                    newdp[j]=max(newdp[j],dp[i]+k[j]);
                }
                }
            }
           dp=newdp;

    }
    printf("%d\n", max({dp[0], dp[1], dp[2]}));


    return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int A, B, K;
	cin >>A >>B >>K;
	for (int i=0; i<K; i++) {
		int I=A+i;
		if (I<=B)
			cout <<I <<endl;
	}
	for (int i=K-1; i>=0; i--) {
		int I=B-i;
		if (I>=A+K)
			cout <<(B-i) <<endl;
	}
	return 0;
}



Measured memory_bytes: 256
from heapq import heappush, heappop
_input = input
V, E, r = map(int, _input().split())
inf = 10**10
edges = [[] for _ in [None]*V]
vertices = [inf]*V
vertices[r] = 0
 
for _ in [None]*E:
    s, t, d = map(int, _input().split())
    edges[s].append((t, d))
 
q = [(0, r)]
rem = V-1
while q and rem:
    cost, v = heappop(q)
    if vertices[v] < cost:
        continue
    rem -= 1
    for dest, _cost in edges[v]:
        newcost = cost + _cost
        if vertices[dest] > newcost:
            vertices[dest] = newcost
            heappush(q, (newcost, dest))
 
print("\n".join([str(n) if n!=inf else "INF" for n in vertices]))

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<long long,long long>>vec(N);
  for (int i=0;i<N;i++){
    cin>>vec[i].first>>vec[i].second;
  }
  sort(vec.begin(),vec.end());//配列を要素１昇順，要素２昇順でソート
  long long ans=0;
  int i=0;
  while(M-vec[i].second>0){
    ans=ans+vec[i].first*vec[i].second;
    M=M-vec[i].second;
    i++;}

  while(M>0){
    ans=ans+vec[i].first;
    M=M-1;
  }
  cout<<ans<<endl;
  return 0;
  
}


Measured memory_bytes: 1792
n = int(input())
txy = []
for _ in range(n):
    t, x, y = map(int, input().split())
    txy.append((t, x, y))
px = py = pt = 0
for t, x, y in txy:
    m = abs(x-px)+abs(y-py)
    dt = t-pt
    if m>dt or (dt-m)%2==1:
        print('No')
        break
    px, py, pt = x, y, t
else:
    print('Yes')

Measured memory_bytes: 17380
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = 0;
    for (auto &c : s) {
        if (c == 'x') r++;
    }

    cout << (r < 8 ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
int n,m;vector<int> g[110000];
int d[110000], ans[110000];

int dfs(int x, int par){
  if(g[x].size() == 1 && x != 0)return d[x] = 1;
  int b = 1;
  for(auto to : g[x]){
    if(to == par)continue;
    b = (b*(dfs(to, x)+1))%m;
  }
  return d[x] = b;
}

void dfs2(int x, int par, int dpar){
  int ret = dpar;
  vector<int> l(g[x].size()+2), r(g[x].size()+2);
  l[0] = r[g[x].size()+1] = 1;
  rep(i,g[x].size()){
    int to = g[x][i];
    l[i+1] = (l[i]*(to == par ? dpar : (d[to]+1))) % m;
    if(to == par)continue;
    ret = (ret*(d[to]+1)) % m;
  }
  for(int i = g[x].size()-1;i >= 0;i--){
    int to = g[x][i];
    r[i+1] = (r[i+2]*(to == par ? dpar : (d[to]+1))) % m;
  }
  ans[x] = ret;
  rep(i,g[x].size()){
    int to = g[x][i];
    if(to == par)continue;
    dfs2(to, x, ((l[i]*r[i+2])+1)%m);
  }
}

signed main(){
  cin>>n>>m;
  rep(i,n-1){
    int xx, yy;cin>>xx>>yy;xx--;yy--;
    g[xx].push_back(yy);
    g[yy].push_back(xx);
  }
  dfs(0, -1);
  dfs2(0,-1, 1);
  rep(i,n){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 21120
#include <iostream>
using namespace std;
#define INF (1ll<<50)
long long wf[100][100];

int main(){
	int n , m;
	while(cin >> n >> m&& n){
		for(int i = 0 ; i < 100 ; i++)
			for(int j = 0 ; j < 100 ; j++)
				wf[i][j] = (i==j?0:INF);
		for(int i = 0 ; i < m ; i++){
			int q; cin >> q;
			if(q){
				int a,b,c;
				cin >> a >> b >> c;
				a--,b--;
				if(wf[a][b] > c){
					wf[a][b] = wf[b][a] = c;
				
					for(int i = 0 ; i < n ; i++){
						for(int j = 0 ; j < n ; j++){
							wf[i][j] = min(wf[i][j],wf[i][a]+wf[a][b]+wf[b][j]);
							wf[i][j] = min(wf[i][j],wf[i][b]+wf[b][a]+wf[a][j]);
						}
					}
					
				}
			}else{
				int a,b;
				cin >> a >> b;
				a--,b--;
				cout << (wf[a][b]==INF?-1:wf[a][b]) << endl;
			}
		}
	}
}

Measured memory_bytes: 944
o,f=998244353,[1]
for i in range(1,2500100):f.append(f[-1]*i%o)
def c(n,k):return f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w,u=3*m,n-1
a=c(w+u,u)-n*c(n+m-2,u)
if u>m:
 for i in range(m+1,min(w,n)+1):
  if w-i+1&1:a-=c(n,i)*c((w-i)//2+u,u)
print(a%o)

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> B(N);
    REP(i, N - 1) cin >> B[i];
    ll ans = 0;
    REP(i, N)
    {
        if (i == 0) ans += B[i];
        else if (i == N - 1) ans += B[i - 1];
        else ans += min(B[i - 1], B[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#include<vector>

#include <algorithm>
#include <tuple>
typedef tuple<string, int, int> mytuple;

int main(){
  int N;
  cin >> N;
  vector<mytuple> T; // S,P,index
  rep(i,0,N){
    string s_temp; int p_temp;
    cin >> s_temp >> p_temp;
    T.push_back(make_tuple(s_temp,-p_temp,i+1));
  }
  sort(T.begin(),T.end(),
	 [](mytuple const &lhs, mytuple const &rhs) {
             if (std::get<0>(lhs) != std::get<0>(rhs)) return std::get<0>(lhs) < std::get<0>(rhs);
             if (std::get<1>(lhs) != std::get<1>(rhs)) return std::get<1>(lhs) < std::get<1>(rhs);
             return std::get<2>(lhs) < std::get<2>(rhs);
         }
	 );
  rep(i,0,N){
    string &c_temp =  get<0>(T[i]);
    int &p_temp = get<1>(T[i]);
    int &i_temp =  get<2>(T[i]);
 
    // cout<<p_temp<<endl;
    cout<< i_temp<< endl;
  }
}


Measured memory_bytes: 256
def bubblesort(a,n,c):
    c=0
    flag=1
    while flag:
        flag=0
        for j in range(n-1,0,-1):
            if a[j]<a[j-1]:
                m=a[j]
                a[j]=a[j-1]
                a[j-1]=m
                flag=1
                c+=1
    return a,c

n=int(input())
a=list(map(int,input().split()))
c=0
ans=bubblesort(a,n,c)
a=ans[0]
c=ans[1]
print(" ".join(map(str,a)))
print(c)



Measured memory_bytes: 5600
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    print(min(A+B+1,C)+B)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


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

#define ll long long int

#define pi 2*acos(0.0)
#define mod 1000000007

#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}

#define pb push_back
#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

//ll Big_Mod(ll v1, ll p, ll md)  { ll res=1; v1=v1%md; while (p > 0){if (p & 1)res = (res * v1) % md; p =p>>1; v1 = (v1 * v1) % md;}return res;}

ll ar[500009],br[500009],cr[500009];
map<ll,ll>mp,mp1;
vector<ll>v;
string s,d;
set<string>st;
int main()
{
    ll a,b,c,i=0,j,k,x,y,z,f,g,h;
    cin>>a;
    while(a--)
    {
        cin>>s;
        st.insert(s);
    }
    cout<<st.size();
}



Measured memory_bytes: 19228
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 1000000009
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    while(1){
        int n,x;
        cin >> n >> x;
        if(n == 0) break;
        ll ans = 0;
        for(int i = 1;i <= n-2;i++){
            for(int j = i+1;j <= n-1;j++){
                for(int s = j+1;s <= n;s++){
                    if(i != j && i != s && j != s && i + j + s == x){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int A, B;
	cin >> A >> B;
	if (B == 1) {
		cout << 0;
	}
	else {
		int sum = A;
		int cnt = 1;
		while (sum < B) {
			sum = sum + A - 1;
			cnt++;
		}
		cout << cnt;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    auto dp = make_vec<int>(1<<n, n+1);
    const int inf = 1001001001;
    fill_v<int>(dp, inf);

    rep(i, n) dp[1<<i][i] = 0;
    
    for (int i = 1; i < 1<<n; ++i) {
        int popcnt = __builtin_popcount(i);
        rep(j, n) {
            int pre = ((popcnt - 1 - j) % 2 == 0 ? a[j] : b[j]);
            rep(k, n) {
                if (i >> k & 1) continue;
                int nxt = ((popcnt - k) % 2 == 0 ? a[k] : b[k]);
                if (pre > nxt) continue;
                int inv = __builtin_popcount(i >> k);
                chmin(dp[i | 1 << k][k], dp[i][j] + inv);
            }
        }
    }
    int ans = inf;
    rep(i, n) chmin(ans, dp[(1<<n)-1][i]);
    cout << (ans == inf ? -1 : ans) << endl;
}


Measured memory_bytes: 34092
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int count = 0;
    while (true) {
        rep(i, N) {
            if (a[i] % 2 == 1) {
                cout << count << endl;
                return 0;
            }
            a[i] /= 2;
        }
        count++;
    }

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

data Relation
    = LG
    | RG
    | Equal
    
instance Show Relation where
    show LG
        = ">"
        
    show RG
        = "<"
        
    show Equal
        = "=="
    
testRelation :: Int -> Int -> Relation

testRelation a b
    | a > b
        = LG
        
    | a < b
        = RG
        
    | otherwise
        = Equal
    
solve :: [Int] -> Relation

solve input
    = testRelation a b where
        a = input !! 0
        b = input !! 1

output :: Relation -> String

output relation
    = "a " ++ show relation ++ " b"
    
main :: IO ()
    
main
    = do
        input <- map read.words <$> getLine
        putStrLn $ output $ solve input

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    set<int> s;
    int a, b, c;
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);

    if(s.size() == 2) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, b;
  scanf("%d", &n);

  // vector<int> A(n);
  vector<int> B(n-1);

  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &b);
    B[i] = b;
  }

  int result = 0;

  // A[0] = B[0];
  // A[n-1] = B[n-2];
  result += B[0];
  result += B[n-2];
  for (int i = 1; i < n-1; i++) {
    // A[i] = min(B[i-1], B[i]);
    result += min(B[i-1], B[i]);
  }

  // for (int i = 0; i < n; i++) {
  //   result += A[i];
  //   cout << A[i] << endl;
  // }

  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int a = 0;
        int b = 0;
        for (int i = 0; i < 3; i++) {
            if (S.charAt(i) == 'A') {
                a++;
            } else {
                b++;
            }
        }
        if (a == 3 || b == 3) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }

}


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

int c[9];
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,ans=0;
	cin >> N;
	vector<int> a(N);
	for(int i=0;i<N;i++)cin >> a[i];
	for(int i=0;i<N;i++){
		for(int j=0;j<8;j++){
			int left;
			if(j==0)left = 1;
			else left = 400*j;
			if(left <= a[i] && a[i]<(j+1)*400)c[j]=1;
		}
			if(a[i]>=3200)c[8]++;
	}
	for(int i=0;i<8;i++){
		if(c[i])ans++;
	}
	if(ans)cout << ans << " " << ans+c[8] << endl;
	else cout << 1 << " " << c[8] << endl;
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	int l = 0, r = N;
	vector<string> seat(N+1);
	string res, left_ideal, right_ideal;
	int left_dis;
	int query = 0;
	int next;

	cout<<query<<endl;
	cin>>res;
	if(res == "Vacant"){return 0;}
	seat[0] = res;
	seat[N] = res;
	query = (r+l)/2;
	while(true){
		cout<<query<<endl;
		cin>>res;
		seat[query] = res;

		if(res == "Vacant"){return 0;}
		left_dis = query-l;
		if(left_dis % 2 == 1){
			if(seat[l] == "Male"){ left_ideal = "Female"; }
			else{ left_ideal = "Male"; }
		}else{
			if(seat[l] == "Male"){ left_ideal = "Male"; }
			else{ left_ideal = "Female"; }
		}

		if(res == left_ideal){
			l = query;
			query = (r+l)/2;
		}else{
			r = query;
			query = (r+l)/2;
		}
	}
	return 0;
}

Measured memory_bytes: 1620
N = int(input())
A = list(map(int, input().split()))

def insec_sort(A, N):

    for i in range(1, N):
        print(*A)
        v = A[i]
        j = i - 1

        while j >= 0 and A[j] > v:
           A[j + 1] = A[j]
           j -= 1

        A[j + 1] = v
    print(*A)


insec_sort(A,N)




Measured memory_bytes: 5980
#include<iostream>
#include<string>
#include<vector>

int main(){
	long long mod= 1000000007;
	std::string s;
	std::cin>>s;

	std::vector<int> numWC(6, 0);
	std::vector<int> initialMod(6, 0);

	int vecIdx= 0;
	for(int i= s.size()-1; i>=0; i--){
		int mpl= 1;
		for(int j=0; j<vecIdx%3; j++)
			mpl*= 10;

		if(s[i]=='?')
			numWC[vecIdx]= numWC[vecIdx]+1;
		else
			initialMod[vecIdx]= (initialMod[vecIdx] + mpl*(s[i]-'0')) % 13;

		vecIdx= (vecIdx+1)%6;
	}

	std::vector<std::vector<std::vector<long long>>> dpDigit(6);

	for(int i=0; i<6; i++){
		dpDigit[i].resize(numWC[i]+1);

		for(int j=0; j< numWC[i]+1; j++)
			dpDigit[i][j].resize(13, 0);
	}


	for(int i=0; i<6; i++)
		dpDigit[i][0][initialMod[i]]= 1;

	for(int i=0; i<6; i++){
		int mpl= 1;
		for(int j=0; j<i%3; j++)
			mpl*= 10;

		for(int j=0; j< numWC[i]; j++){
			for(int k=0; k< 13; k++){
				for(int l=0; l<10; l++){
					dpDigit[i][j+1][(k+mpl*l)%13]= (dpDigit[i][j+1][(k+mpl*l)%13] + dpDigit[i][j][k])% mod;
				}
			}
		}
	}

	std::vector<std::vector<long long>> modList(2);
	for(int i=0; i<2; i++)
		modList[i].resize(13, 0);

	for(int i=0; i<2; i++){
		for(int j0=0; j0<13; j0++){
			for(int j1=0; j1<13; j1++){
				for(int j2=0; j2<13; j2++){
					long long tmp= dpDigit[i*3][numWC[i*3]][j0];
					tmp= (tmp* dpDigit[i*3+1][numWC[i*3+1]][j1]) % mod;
					tmp= (tmp* dpDigit[i*3+2][numWC[i*3+2]][j2]) % mod;

					modList[i][(j0+j1+j2)%13] = (modList[i][(j0+j1+j2)%13] + tmp) %mod;
				}
			}
		}
	}

	std::vector<long long> finallymod(13, 0);

	for(int j0=0; j0<13; j0++){
		for(int j1=0; j1<13; j1++){
			long long tmp= modList[0][j0];
			tmp= (tmp *  modList[1][j1])%mod;

			finallymod[(j0- j1+13)% 13] = (finallymod[(j0- j1+13)% 13] + tmp) %mod;
		}
	}


	std::cout<<finallymod[5]<<std::endl;

	return 0;
}

Measured memory_bytes: 13696
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
bool cmp(const Pll &l,const Pll &r){
    return l.fi<r.fi;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll a,b,q;cin>>a>>b>>q;
    vector<ll>s(a+2),t(b+2);
    for(ll i=1;i<=a;i++)cin>>s[i];
    for(ll i=1;i<=b;i++)cin>>t[i];
    s[0]=-INF;s[a+1]=INF;
    t[0]=-INF;t[b+1]=INF;
    while(q--){
        ll x;cin>>x;
        ll q1=upper_bound(all(s),x)-s.begin();
        ll q2=q1-1;
        ll p1=upper_bound(all(t),x)-t.begin();
        ll p2=p1-1;
        //cout<<q1<<" "<<p1<<endl;
        ll minm=INF;
        //cout<<q1<<" "<<p1<<endl;
        //cout<<s[2]<<endl;
        chmin(minm,mmax(s[q1]-x,t[p1]-x));
        //cout<<minm<<endl;
        chmin(minm,2*mmin(x-s[q2],t[p1]-x)+mmax(x-s[q2],t[p1]-x));
        //cout<<minm<<endl;
        chmin(minm,2*mmin(x-t[p2],s[q1]-x)+mmax(x-t[p2],s[q1]-x));
        //cout<<minm<<endl;
        chmin(minm,mmax(x-s[q2],x-t[p2]));
        cout<<minm<<endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------







Measured memory_bytes: 2944
S=gets
(0..7).each{|s|
  t=s.to_s(2).rjust(3,"0").gsub(/1/,"+").gsub(/0/,"-")
  str="%d%s%d%s%d%s%d"%[S[0],t[0],S[1],t[1],S[2],t[2],S[3]]
  if eval(str)==7 then puts str+"=7";break end
}

Measured memory_bytes: 1788
data1 = []
for i in range(10):
    x = int(input())
    data1.append(x)
list1 = sorted(data1, reverse = True)

a = sum(list1[:3])


del data1[0:9]


data2 = []
for i in range(10):
    y = int(input())
    data2.append(y)
list2 = sorted(data2, reverse = True)

b = sum(list2[:3])


print(a, b)


Measured memory_bytes: 5600
x=int(input())
if(x<=6):
    print(1)
elif(x<=11):
    print(2)
elif(x>11 and x%11==0):
    print((x//11)*2)
elif(x>11 and x%11<=6):
    print((x//11)*2+1)
elif(x>11 and x%11>6):
    print((x//11)*2+2)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
using namespace std;

int dp[100000];

int jumps(int h[],int curr,int k)
{
    int j;
    if(curr==1)
        return 0;
    if(dp[curr]!=-1)
        return dp[curr];
    else
    {
        dp[curr]=abs(h[curr]-h[curr-1])+jumps(h,curr-1,k);
        for(j=2;j<=k && curr-j>0;j++)
            dp[curr]=min(dp[curr],abs(h[curr]-h[curr-j])+jumps(h,curr-j,k));
        return dp[curr];
    }
}

int main()
{
    int i,n,k;
    cin>>n>>k;
    int h[n+1];
    f(i,1,1+n)
    {
        cin>>h[i];
        dp[i]=-1;
    }
    cout<<jumps(h,n,k);
}


Measured memory_bytes: 8832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n;
int a[100005],id[100005];
int sum[400005];
inline void update(int p,int a=1,int b=n,int v=1){
	if (a==b) ++sum[v];
	else{
		int m=a+b>>1;
		if (p<=m) update(p,a,m,v<<1);
		else update(p,m+1,b,v<<1|1);
		sum[v]=sum[v<<1]+sum[v<<1|1];
	}
}
inline int query(int l,int r,int a=1,int b=n,int v=1){
	if (a>=l&&b<=r) return sum[v];
	if (a>r||b<l) return 0;
	int m=a+b>>1;
	return query(l,r,a,m,v<<1)+query(l,r,m+1,b,v<<1|1);
}
ll ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n){
		cin>>a[i];id[a[i]]=i;
	}
	update(id[n]);
	for (int i=n-1;i>=1;--i){
		ll p=id[i];
		ll l1,l2,r1,r2;
		ll l,r;
		// r1
		l=p;r=n+1;
		if (query(p,r-1)>0){
			while(r-l>1){
				ll m=l+r>>1;
				if (query(p,m)==0) l=m;
				else r=m;
			}
		}
		r1=r;
		// r2
		l=r1;r=n+1;
		if (query(p,r-1)>1){
			while(r-l>1){
				ll m=l+r>>1;
				if (query(p,m)<2) l=m;
				else r=m;
			}
		}
		r2=r;
		// l2
		l=0;r=p;
		if (query(l,p)>0){
			while(r-l>1){
				ll m=l+r>>1;
				if (query(m,p)==0) r=m;
				else l=m;
			}
		}
		l1=l;
		// l2
		l=0;r=l1;
		if (query(l,p)>1){
			while(r-l>1){
				ll m=l+r>>1;
				if (query(m,p)<2) r=m;
				else l=m;
			}
		}
		l2=l;
		//printf("Number:%d Place:%lld  %lld,%lld,%lld,%lld\n",i,p,l1,l2,r1,r2);
		// count ans
		ans+=(ll)i*((r2-r1)*(p-l1)+(l1-l2)*(r1-p));
		update(p);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

ll gcd(ll n, ll m){
    while(true){
        if(n<m) swap(n, m);
        if(!m) break;
        n %= m;
    }
    return n;
}

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

    ll X;
    cin >> X;

    cout << 360/gcd(X, 360) << endl;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		float endTime = (float) (t + 0.5);
		int times = (int) (t + 0.5)/a;
		System.out.println(b*times);
	}
}



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

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if (S[0] != S[1] || S[1] != S[2])
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 25888
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define MAX_N 310
#define INF 1000000000000000

using P = pair<long, long>;
#define fi first
#define se second

long L;
int n, m;

// 全対全の距離を求める N^3
long d[MAX_N][MAX_N]; // i->jのコスト あらかじめINF初期化してから入力を反映させる
void warshall_floyd() { 
    for (int k=0; k<n; k++)
        for (int i=0; i<n; i++)
            for (int j=0; j<n; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
    cin >> n >> m >> L;
    fill(d[0], d[n], INF);
    for (int i=0, a, b; i<m; i++) {
        long c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = d[b][a] = c;
    }
    warshall_floyd();
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            d[i][j] = (d[i][j] > L ? INF : 1);
        }
    }
    warshall_floyd();
    int q; cin >> q;
    for (int i=0, s, t; i<q; i++) {
        cin >> s >> t;
        s--; t--;
        cout << (d[s][t] < INF ? d[s][t] - 1 : -1) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using ld=long double;

ld dist(pair<ld, ld> l, pair<ld, ld> r) {
    ld res = powl(l.first-r.first,2);
    res+=powl(l.second-r.second,2);
    return sqrtl(res);
}

int main()
{
    int N;
    cin>>N;
    vector<pair<ld,ld>> xy(N);
    rep(i, N) {
        cin>>xy[i].first>>xy[i].second;
    }
    ld res = 0;
    vector<int> route;
    rep(i,N)route.push_back(i);
    do {
        rep(i, N - 1) {
            auto from = xy[route[i]];
            auto to = xy[route[i+1]];
            res+=dist(from,to);
        }
    }while(next_permutation(route.begin(),route.end()));
    REP(i,1,N+1)res/=i;
    cout<<fixed<<setprecision(12)<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())

diff = float("inf")
ans = 0

for i in range(1, N+1):
    before = sum([L+k-1 for k in range(1, N+1)])
    after = sum([L+j-1 for j in range(1, N+1) if j != i])
	
    if abs(before-after) < diff:
    	diff = abs(before-after)
    	ans = after
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include "rubo.h"

#define dbl double
#define pb push_back
#define SQ(x) (x)*(x)
#define ll long long
#define ull unsigned long long
#define vc vector
#define F first
#define S second
//#define in ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt...) (0)
//#define puts(fmt...) (0)

using namespace std;


int h,w,n;
vc<int> a;

int f[200][200];
int dir = 1;
pii next(int i, int j){
    j += dir;
    if(j < 1 || j > w){
        j-=dir;
        dir *= -1;
        i++;
    }
    return {i,j};
}

int main() {
    cin >> h >> w >> n;
    a.resize(n);
    loop(i,n){
        cin >> a[i];
    }

    int p = 1,i = 1, j = 1;

    for(int k : a){
        loop(kk,k){
            f[i][j] = p;
            pii pr = next(i,j);
            i = pr.F;
            j = pr.S;
        }
        p++;
    }

    for(i = 1; i <= h; i++){
        for(j = 1; j <= w; j++){
            cout << f[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int memo[(int)1e5+10];
int rec(int n){
   if(n==0)return 0;
   if(memo[n]!=-1) return memo[n];
   int res=n;//INF
   for(auto i=v.begin();i!=v.end()&&*i<=n;i++)
     res=min(res,rec(n-*i)+1);
   return memo[n]=res;
}
int main(){
  int n,x=1;
  cin>>n;
  v.push_back(1);
  while((x*=6)<=n)
     v.push_back(x);
  x=1;
  while((x*=9)<=n)
     v.push_back(x);
  sort(v.begin(),v.end());
  fill(memo,memo+n+1,-1);
  cout<<rec(n);
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>

using namespace std;

typedef long long ll;

int main(void){
    ll n;
    cin >> n;
    vector<ll> d(n);
    for(ll i = 0;i < n;i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    ll mid = n / 2;
    if(d[mid - 1] != d[mid]){
        cout << d[mid] - d[mid - 1] << endl;
        return 0;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<limits.h>


int main(void){
    int n, x, l[100]={}, d=0;
    scanf("%d %d", &n, &x);
    for(int i=0; i<n; i++){
        scanf("%d", &l[i]);
    }
    int i = 0;
    while(d<=x){
        if(l[i]==0){
            d=x+1;
            i=n;
        }
        d=d+l[i++];
    }
    printf("%d", i);
    return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (const auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
//#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;

const int N = 3e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;

struct SegmentTree {
    int n;
    vector<int> a, t;

    void init(int x) {
        n = x;
        t.assign(4 * n, 0);
    }

    void init(int x, vector<int> y) {
        n = x;
        a = move(y);
        t.resize(4 * n);
        build(1, 0, n - 1);
    }

    int merge(int x, int y) { return max(x, y); }

    void build(int i, int l, int r) {
        if (l == r) {
            t[i] = merge(t[i], a[l]);
            return;
        }
        int mid = (l + r) / 2;
        build(lc(i), l, mid);
        build(rc(i), mid + 1, r);
        t[i] = merge(t[lc(i)], t[rc(i)]);
    }

    void modify(int i, int l, int r, int pos, int val) {
        if (l == r) {
            t[i] = merge(t[i], val);
            return;
        }
        int mid = (l + r) / 2;
        if (pos <= mid) modify(lc(i), l, mid, pos, val);
        else modify(rc(i), mid + 1, r, pos, val);
        t[i] = merge(t[lc(i)], t[rc(i)]);
    }

    int query(int i, int l, int r, int ql, int qr) {
        if (l > qr || r < ql) return 0;
        if (l >= ql && r <= qr) return t[i];
        int mid = (l + r) / 2;
        return merge(query(lc(i), l, mid, ql, qr), query(rc(i), mid + 1, r, ql, qr));
    }

    void modify(int pos, int val) { modify(1, 0, n - 1, pos, val); }

    int query(int l, int r) { return query(1, 0, n - 1, l, r); }
};

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int n, k;
    cin >> n >> k;
    vi dp(n, 1);
    SegmentTree seg;
    seg.init(N);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int qryL = seg.query(max(0, x - k), x);
        int qryR = seg.query(x, min(x + k, N - 1));
        dp[i] = max({dp[i], qryL + 1, qryR + 1});
//        cout << i + 1 << ": " << qryL << " " << qryR << " " << dp[i] << " " << x << "\n";
        seg.modify(x, dp[i]);
    }
    cout << *max_element(all(dp));
}

Measured memory_bytes: 9020