akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "-1\n"; return;}

void solve() {
    int a[8] = { 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };
    int x; cin >> x;
    loop(i, 8)
        if (x < a[i]) {
            cout << 8 - i; break;
        }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

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

    VI a(n), w(n);
    cin >> a; cin >> w;
    VI l, r;
    FOR(i, 0, n) {
        if (a[i] == 0)r.push_back(w[i]);
        else l.push_back(w[i]);
    }
    bool ng = false;
    if (l.empty())ng = true;
    else SORT(l);
    if (r.empty())ng = true;
    else SORT(r);
    cout << (ng ? 0 : l[0] + r[0]) << "\n";
}


Measured memory_bytes: 3236
--
local N, M = io.read("n", "n")

-- from ABC120
local parents = {}
for i=1,N do
    parents[i] = -1
end
local function find_root(x)
    while parents[x] > 0 do
        x = parents[x]
    end
    return x
end
local function find_union(a, b, update)
    local x, y = a, b
    while parents[x] > 0 do
        x = parents[x]
    end
    while parents[y] > 0 do
        y = parents[y]
    end
    local size_a, size_b = -parents[x], -parents[y]
    if update and x ~= y then
        if size_b > size_a then
            x, y = y, x
        end
        -- size(x) > size(y)
        -- x is new root of y
        parents[x] = parents[x] + parents[y]
        parents[y] = x
    end
    return x == y, size_a, size_b
end

for i=1,M do
    local a,b,z = io.read("n", "n", "n")
    find_union(a,b,true)
end

local set = {}
for i=1,N do
    local r = find_root(i)
    set[r] = true
end
local count = 0
for _ in pairs(set) do
    count = count + 1
end
print(count)

Measured memory_bytes: 5000
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#include<cstdlib>
#include <queue>
#include <cmath>
#include <iomanip>
#include<list>
#include <utility>
#include <functional>
#include<map>
#include<stack>
#define T long long
const double PI=3.14159265358979323846;

int main(){
	int a,b,h,m;
	std::cin >>a >>b >>h >>m;
	double xdiff = a*std::sin(2*PI/12.0*(h+m/60.0))-b*std::sin(2*PI*m/60.0);
	double ydiff = a*std::cos(2*PI/12.0*(h+m/60.0))-b*std::cos(2*PI*m/60.0);
	std::cout << std::fixed << std::setprecision(11) << std::sqrt(xdiff*xdiff+ydiff*ydiff) << std::endl;
}


Measured memory_bytes: 4072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder ans = new StringBuilder();

        for(int i=0; i<s.length(); i++){
            String input = String.valueOf(s.charAt(i));

            if((i+1) % 2 != 0){
                ans.append(input);
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 30064
#include <bits/stdc++.h>
#define MOD 1000000007
#define INT long long int
using namespace std;
INT n, t, h, ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>h;
    for(int i = 0 ; i < n ; i++ )
        cin>>t, (t>=h?ans++:ans);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
	for(int n; cin >> n, n;){
		vector<string> in(n);
		for(auto & e : in) cin >> e;

		for(auto & e : in){
			int len = e.size();
			string code;
			bool ok = true;
			string T = "aiueo";
			rep(i, len){
				if(ok) code.push_back(e[i]);
				ok = false;
				rep(j, 5) if(e[i] == T[j]) ok = true;
			}
			e = code;
		}

		int res = -1;
		rep(k, 1, 51){
			set<string> s;

			bool ok = true;
			for(auto & code : in){
				if(not s.insert(code.substr(0, k)).second){
					ok = false;
					break;
				}
			}
			if(ok){
				res = k;
				break;
			}
		}

		cout << res << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

const double eps=1e-5;
const long long INF=(LL)(1e9)*(LL)(1e9);



int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s;
    cin>>s;
    s+="0";
    vector<int> dp(n+2);
    int z1=-1,z2=-1,z3=-1;
    REP(i,n+1)
    {
        if(s[i]=='0')
        {
            if(z2==-1)
            {
                z2=i;
                continue;
            }
            z3=i;

            if(z1+1==z2)
            {
                dp[z2+2]=max(dp[z2+2], dp[z1+1]);
                dp[z2+2]=max(dp[z2+2], dp[z1+2]);
    
                dp[z3]=max(dp[z3], dp[z2-1]);
                dp[z3-1]=max(dp[z3-1], dp[z2-1]);
    
                dp[z2+2]=max(dp[z2+2], dp[z2-1]);
                dp[z2+1]=max(dp[z2+1], dp[z2]);
            }
            else if(z2+1==z3)
            {
                dp[z2+2]=max(dp[z2+2], dp[z1+1]);
                dp[z2+2]=max(dp[z2+2], dp[z1+2]);
    
                dp[z3]=max(dp[z3], dp[z2-1]);
                dp[z3-1]=max(dp[z3-1], dp[z2-1]);
    
                dp[z2+2]=max(dp[z2+2], dp[z2-1]);
                dp[z2+1]=max(dp[z2+1], dp[z2]);
            }
            else
            {
            dp[z2+2]=max(dp[z2+2], dp[z1+1]+z2-z1-1);
            dp[z2+2]=max(dp[z2+2], dp[z1+2]+z2-z1-2);

            dp[z3]=max(dp[z3], dp[z2-1]+z3-z2-1);
            dp[z3-1]=max(dp[z3-1], dp[z2-1]+z3-z2-2);

            dp[z2+2]=max(dp[z2+2], dp[z2-1]+1);
            dp[z2+1]=max(dp[z2+1], dp[z2]);

            
            }
            
            int mx=0;
            for(int j=z2+1;j<=z3;j++)
            {
                mx=max(dp[j],mx);
                dp[j]=max(dp[j],mx);
            }

            z1=z2;
            z2=z3;
        }
    }
    //REP(i,n+1)
    //cout<<dp[i]<<endl;
    int ans=0;
    REP(i,n+2)
        ans=max(dp[i],ans);
    cout<<ans<<endl;
}

Measured memory_bytes: 2820
N, *D = map(int, open(0).read().split())
D = list(zip(*[iter(D)]*2))
D = sorted(D, key=lambda x:x[1])
t = 0
f = True
for d in D:
  if t + d[0] <= d[1]:
    t += d[0]
  else:
    f = False
    break
print('Yes' if f else 'No')

Measured memory_bytes: 49116
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

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

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

typedef struct unionfind{
  vector<int> par,treesize;
  unionfind(int N) :par(N){
    for(int i=0;i<N;i++)par[i]=i;
    treesize.resize(N);
    for(int i=0;i<N;i++)treesize[i]=1;
  }
  int root(int x){
    int r;
    if(par[x]==x)return x;
    r=root(par[x]);
    if(par[x]!=r){
      treesize[r]+=treesize[x];
      treesize[x]=0;
      par[x]=r;
    }
    return r;
  }
  void unite(int x,int y){
    int px=root(x);
    int py=root(y);
    if(px!=py){
      par[px]=py;
      treesize[py]+=treesize[px];
      treesize[px]=0;
    }
  }
  bool parcheck(int x,int y){
    int px=root(x);
    int py=root(y);
    return px==py;
  }
  int size(int x){
    int px=root(x);
    return treesize[px];
  }
};



int main(){
  ll i,j,N,M,x,tr=0,ans=1;
  cin>>N;
  vector<data> a(2*N);
  unionfind tree(N);
  rep(i,2*N){
    cin>>a[i].first;
    if(i<N){a[i].second=1;}
    else{a[i].second=-1;}
  }
  vsort(a);
  rep(i,2*N){
    if(tr*a[i].second>=0){
      tr+=a[i].second;
    }else{
      x=labs(tr);
      ans=(ans*x)%mod;
      tr+=a[i].second;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4096
def examA():
    S = SI()
    if len(S)%2==1:
        print("No")
        return
    for i in range(len(S)//2):
        if S[i*2:i*2+2]!="hi":
            print("No")
            return
    print("Yes")
    return

def examB():
    a, b, M = LI()
    A = LI()
    B = LI()
    D = [LI()for _ in range(M)]
    ans = min(A) + min(B)
    for x,y,c in D:
        cur = A[x-1]+B[y-1]-c
        ans = min(ans,cur)
    print(ans)
    return

def examC():
    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = nowW + 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        a, b = LI()
        a -= 1
        b -= 1
        V[a].append(b)
        V[b].append(a)
    L = bfs(N,0,V)
    #print(L)
    odd = 0
    for l in L:
        if l==-1:
            print(-1)
            return
        if l%2==1:
            odd += 1
    G = []
    if odd*2<N:
        for i in range(N):
            if L[i]%2==1:
                G.append(i)
    else:
        for i in range(N):
            if L[i]%2==0:
                G.append(i)

    used = [False]*(N+1)
    ans = [0]*N
    if N//3>=len(G):
        cur = 3
        for g in G:
            ans[g] = cur
            used[cur] = True
            cur += 3
        cur = 1
        for i in range(N):
            if ans[i]!=0:
                continue
            while(used[cur]):
                cur += 1
            ans[i] = cur
            used[cur] = True
    else:
        cur = 1
        for g in G:
            ans[g] = cur
            used[cur] = True
            cur += 3
            if cur>N:
                cur = 3
        cur = 1
        for i in range(N):
            if ans[i]!=0:
                continue
            while(used[cur]):
                cur += 1
            ans[i] = cur
            used[cur] = True
    print(" ".join(map(str,ans)))
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

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

int main(){
  string s,t;cin>>s>>t;
  int n=s.size();
  string ans="No";
  for(int i=0;i<n;i++){
    if(s==t){ans="Yes";break;}
    s=s[n-1]+s.substr(0,n-1);
  }
  cout<<ans;
}


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

int main(){
    long long n, a, b;
    cin >> n;
    for(long long i = sqrt((double)n) + 1; i >= 1; i--){
        if(n % i == 0){
            a = i;
            b = n / a;
            break;
        }
    }

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

Measured memory_bytes: 256
grades = ['A','B','C','D','F']

while True:

    m, f, r = map(int, input().split())

    if m == -1 and f == -1 and r == -1:
        break

    if m ==-1 or f ==-1:
        print(grades[4])
    elif m + f >= 80:
        print(grades[0])
    elif m + f >= 65:
        print(grades[1])
    elif m + f >= 50:
        print(grades[2])
    elif m + f >= 30:
        if r >= 50:
            print(grades[2])
        else:
            print(grades[3])
    else:
        print(grades[4])



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

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

#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	vector<pii>v;
	rep(i,0,n){
		ll a,b;cin>>a>>b;
		v.pb({b,a});
	}
	sort(all(v));
	bool ok=1;
	ll rem=v[0].fi-v[0].se;
	if(rem<0)ok=0;
	rep(i,1,sz(v)){
		rem+=(v[i].fi-v[i-1].fi)-(v[i].se);
		if(rem<0)ok=0;
	}
	if(!ok)cout<<"No";
	else cout<<"Yes";
	
	
	
	return 0;
}



Measured memory_bytes: 6512
# coding: utf-8

def main():
	# ４つの整数を入力
	A, B, C, D = map(int, input())

	# 計算結果が７になるよう計算します。
	for op in range(0x7):
		a = A
		if ((op & 0x1) == 0):
			a += B
		else:
			a -= B
		if ((op & 0x2) == 0):
			a += C
		else:
			a -= C
		if ((op & 0x4) == 0):
			a += D
		else:
			a -= D
		if a == 7:
			print(
				'%d%s%d%s%d%s%d=7' % (
					A,
					'+' if ((op & 0x1) == 0) else '-',
					B,
					'+' if ((op & 0x2) == 0) else '-',
					C,
					'+' if ((op & 0x4) == 0) else '-',
					D
				)
			)
			break


if __name__ == '__main__':
	main()



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

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> maze(H);
    vector<vector<int>> h(H, vector<int>(W, 0));
    vector<vector<int>> w(H, vector<int>(W, 0));

    for (int i = 0; i < H;i++)
        cin >> maze[i];

    int ans = 0;
    for (int i = 0; i < H;i++){
        for (int j = 0; j < W;j++){
            if(maze[i][j] == '#'){
                h[i][j] = 0;
                w[i][j] = 0;
                continue;
            }else{
                if(i > 0 && maze[i][j] == '.' && h[i-1][j] > 0){
                    h[i][j] = h[i - 1][j];
                }else{
                    int t = i + 1;
                    while(t < H && maze[t][j] == '.')
                        t++;
                    h[i][j] = t - i;
                }

                if(j > 0 && maze[i][j] == '.' && w[i][j-1] > 0){
                    w[i][j] = w[i][j - 1];
                }else{
                    int t = j + 1;
                    while(t < W && maze[i][t] == '.')
                        t++;
                    w[i][j] = t - j;
                }
                ans = max(ans, h[i][j] + w[i][j] - 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n, q;
int A[2010], M[2010];

// 用第i个元素后面的元素能得出m时返回true 
// 从输入值M中减去所选元素的递归函数 
bool solve(int i, int m)
{
	if(m == 0)	return true;
	if(i >= n)	return false;
	return solve(i + 1, m) || solve(i + 1, m - A[i]);	// 不使用第i个元素 + 使用第i个元素 
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; ++ i)
	{
		cin >> A[i];
	}
	cin >> q;
	for(int i = 0; i < q; ++ i)
	{
		cin >> M[i];
		if(solve(0, M[i]))
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    
    int n;
    cin >> n;
    
    vector<int> a(n), idx(n);
    rep(i, n) { cin >> a[i]; a[i]--; }
    
    rep(i, n) idx[a[i]] = i;
    
    set<int> s;
    ll ans = 0;
    rep(i, n) {
        int x = idx[i];
        s.insert(x);
        
        auto it = s.find(x);
        int r = n - 1, l = 0;
        if (it != s.begin()) {
            it--;
            l = *it;
            l++;
        }
        it = s.find(x);
        it++;
        if (it != s.end()) {
            r = *it;
            r--;
        }
        // cout << l << " " << r << '\n';
        ll c = (ll)(r - x + 1) * (x - l + 1);
        ans += (ll)(i + 1) * c;
        // cout << ans << '\n';
    }
    cout << ans << '\n';
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>
#include <list>

#define MOD (1000000000 + 7)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 

vector<ll> divisor;
void list_divisor(ll n) {
    divisor.clear();
    for(int i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            divisor.push_back(i);
            if(i*i != n) divisor.push_back(n/i);
        }
    }
    sort(divisor.begin(), divisor.end());
}

vector<bool> Eratosthenes(ll N) {
    vector<bool> primes(N, true);
    vector<ll> ret;
    primes[0] = false;
    primes[1] = false;
    for (ll i=2; pow(i,2)<=N; i++) {
        if (primes[i]) {
            for(int j=2; i*j<=N; j++) primes[i*j] = false;
            ret.push_back(primes[i]);
        }
    }
    return primes;//ret;
}


int main() {
    ll Q;
    cin >> Q;

    vector<bool> primes = Eratosthenes(100000);

    vector<ll> cum_primes(100001, 0);
    ll temp = 0;
    for(ll i = 0; i < cum_primes.size(); i++) {
        // cout << i << ":" << primes[i] <<  primes[(i+1)/2] << endl;
        cum_primes[i] = primes[i] && primes[(i+1)/2] ? ++temp : temp;
    }

    // for(ll i = 0; i < 100; i++) {
    //     cout << i << ":" << cum_primes[i] << endl;
    // }

    for(ll i = 0; i < Q; i++) {
        ll l, r;
        cin >> l >> r;

        cout << cum_primes[r] - cum_primes[l-1] << endl;
    }





}


Measured memory_bytes: 4068
use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{stdin, Read};
use std::os::raw::{c_double, c_float};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);

    // let n = read::<usize>();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[1000001];
bool isperfectsquare(ld x)
{
    return (ceil(sqrt(x))==floor(sqrt(x)));
}
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    ll flag=0;
    go(i,0,(ll)s.size()-1)
    {
        if(s[i]==s[i+1])
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        show("Bad");
    }
    else
    {
        show("Good");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    if(N%1000 == 0){
        cout << 0 << endl;
    }else{
        cout << 1000-N%1000 << endl;
    }
    


    return 0;
    

}

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

#define llong long long/*{{{*/
#define ii pair<int, int>
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )

template<class x> vector<typename x::value_type> tovec(const x& a) { return vector<typename x::value_type>(a.begin(), a.end()); }
#define ptrtype(x) typename iterator_traits<x>::value_type
template<class u> vector<ptrtype(u)> tovec(u a, u b) { return vector<ptrtype(u)>(a, b); }

template<typename x> ostream& operator<<(ostream& cout, const vector<x>& a) {
  cout << "[";
  if (len(a)) cout << a[0];
  rep1(i, len(a) - 1) cout << ", " << a[i];
  return cout << "]";
}

template<typename u, typename v> ostream& operator<<(ostream& cout, const pair<u, v>& a) {
  return cout << "(" << a.xx << ", " << a.yy << ")";
}/*}}}*/

#define rem 924844033
#define maxn 2020

int n, k;
bool endOfChain[maxn * 2] = {0};
llong dp[maxn * 2][maxn] = {0};

vector<llong> dfac(1, 1);
llong fac(int i) {
  while (len(dfac) <= i) dfac.push_back((dfac.back() * len(dfac)) % rem);
  return dfac[i];
}

int main(void) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> k;

  int l = k * 2;

  int pos = 0;
  endOfChain[pos] = 1;
  rep1(i, min(l, n)) {
    if (i - k < 1 and i + k > n) continue;
    int chainLength = (n - i) / l + 1;
    int last = (chainLength - 1) * l + i;
    int nEdge = chainLength * 2;
    if (i - k < 1) --nEdge;
    if (last + k > n) --nEdge;
    //clog << i << ' ' << last << ' ' << chainLength << ' ' << nEdge << endl;
    pos += nEdge;
    endOfChain[pos] = 1;
  }

  //clog << tovec(endOfChain, endOfChain + pos + 1) << endl;

  dp[0][0] = 1;
  rep1(i, pos) {
    int back = i - 1 - !endOfChain[i - 1];    // the previsous edge we should pick if we pick the current one.
    rep(f, n + 1) {
      dp[i][f] = dp[i - 1][f];                // not pick the current edge
      if (f == 0) continue;
      if (back < 0) continue;
      (dp[i][f] += dp[back][f - 1]) %= rem;  // pick the current edge
    }
    //clog << i << ' ' << tovec(dp[i], dp[i] + n + 1) << endl;
  }

  llong* m = dp[pos];                          // the array M in the editorial
  llong ans = 0;
  int sign = 1;
  fac(10);
  //clog << dfac << endl;
  rep(i, n + 1) {
    (ans += sign * m[i] * fac(n - i)) %= rem;
    if (ans < 0) ans += rem;
    //clog << i << ' ' << ans << ' ' << m[i] << endl;
    sign = -sign;
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 63744
N = int(input())
UV = [list(map(int, input().split())) for _ in range(N-1)]
ans = 0
for i in range(N):
    ans += (i+1) * (N-i)
for u, v in UV:
    if u > v:
        u, v = v, u
    ans -= u * (N-v+1)
print(ans)


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
        if(i*j==n){
            cout<<"Yes";
            return 0;
        }
    }
    }
    cout<<"No";
    
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++) cin >> S[i];
    for(int h = 0; h < H; h++) for(int w = 0; w < W; w++) {
        if(S[h][w] != '#') {
            for(int i = h - 1; i <= h + 1; i++) for(int j = w - 1; j <= w + 1; j++) {
                if(i == h && j == w) continue;
                else if(i < 0 || j < 0 || i >= H || j >= W) continue;
                else {
                    if(S[i][j] == '#') {
                        if(S[h][w] == '.') S[h][w] = '1';
                        else {
                            
                            S[h][w]++;
                        }
                    }
                }
            }
        }
        if(S[h][w] == '.') S[h][w] = '0';
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cout << S[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=(a+d-1)/d, y=(b+c-1)/b;
    if(x>=y) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  for (int h = 1;;) {
    if (h > n) break;
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int i = G.size()-1; i >= 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  cnt = 0;

  shellSort(A, n);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if (i) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for (int i = 0; i < n; i++) printf("%d\n", A[i]);
}


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




























int main() {
    long long N, W;
    cin >> N >> W;

    vector<long long> weight(N+1), value(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> weight[i] >> value[i];
    }

    long long value_sum = 0;
    rep(i, N) value_sum += value[i+1];

    vector<vector<long long>> dp(N + 1, vector<long long> (value_sum + 1, INT64_MAX / 2)); //第一成分は荷物の番号，第二成分は価値の総和
    
    rep (i, N+1) {
        dp[i][0] = 0;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= value_sum; j++) {
            if (j - value[i] < 0) {
                dp[i][j] = dp[i-1][j];
            }
            else {
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-value[i]] + weight[i]);
            }
        }
    }
    long long ans = 0;
    for (long long i = 0; i <= value_sum; i++) {
        if (dp[N][i] <= W) {
            ans = i;
        }
    }
    cout << ans << endl;
}

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

void solve(void) {
  int N;
  cin >> N;
  vector<int> B(N-1);
  for (int i = 0; i < N-1; ++i) cin >> B[i];

  int res = B[0] + B[N-2];
  for (int i = 1; i < N-1; ++i) res+= min(B[i], B[i-1]);

  cout << res << endl;
}
int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int n,m,res,p;
    cin>>n>>m;
    vector<long int>a(m);
    for(int i=0;i<m;i++){
    	cin>>a[i];
	}
	p=accumulate(a.begin(),a.end(),0);
	res=n-p;
	if(res>=0)cout<<res;
	else cout<<"-1";
}


Measured memory_bytes: 3736
s=input()
n=int(len(s))
cnt=int(s)
s=list(map(int,s))
if n==1:
    cnt=cnt
elif n==2:
    cnt+=s[0]+s[1]
else:
    cnt=0
    cnt+=s[0]*10**(n-1)
    for i in range(0,n-1):
        cnt+=(10**i)*(sum(s[:n-i])+s[n-i-1])*2**(n-i-2)
print(cnt)

Measured memory_bytes: 3064
import math
import itertools

if __name__ == '__main__':
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    for x in itertools.combinations(X,2):
        m = math.sqrt(sum( [ ((x[0][i] - x[1][i]) ** 2) for i in range(D)] ))
        if m.is_integer():
            count += 1
    print(count)

Measured memory_bytes: 3064
//frog1
#include<bits/stdc++.h>
using namespace std;
int n,k;
int height[100005];
int func(){
	int dp[100005];
	dp[0]=0;
	dp[1]=abs(height[1]-height[0]);
	for(int i=2;i<n;i++){
		int val=INT_MAX;
		for(int j=i-1;j>=(i-k) && j>=0;j--){
			val=min(val,dp[j]+abs(height[i]-height[j]));
		}
		dp[i]=val;
		//cout<<dp[i]<<endl;
	}
	return dp[n-1];
}
int main(){
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>height[i];
	cout<<func()<<endl;
	return 0;
}

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

int main()
{
	int n,c;
   c=0;

   cin >> n;

   for(int i=1; i<=n; i++){
      if( (to_string(i).length()) % 2 != 0){
         c++;
      }      
   }

   cout << c << endl;

	return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int ans=0;
		for(int a=0;a<10;a++){
			for(int b=0;b<10;b++){
				for(int c=0;c<10;c++){
					for(int d=0;d<10;d++){
						if(a+b+c+d==n)ans++;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;

int n,m,a[200005],cnt[200005],seg[200005],ans;

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);
		a[i]=x;
		cnt[x]++;
		int p=x-cnt[x]+1;
		if (p>0) seg[p]++;
	}
	for (int i=1;i<=n;i++) if (seg[i]==0) ans++;
//	cout<<ans<<endl;
	while (m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int p=a[x]-cnt[a[x]]+1;
		if (p>0)
		{
			seg[p]--;
			if (seg[p]==0) ans++;
		}
		cnt[a[x]]--;a[x]=y;cnt[y]++;
		p=y-cnt[y]+1;
		if (p>0)
		{
			if (seg[p]==0) ans--;
			seg[p]++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n = 0, d = 0;
    cin >> n >> d;
    long long int ct = 0;
    for (long long int i = 0; i < n; i++)
    {
        long long int x = 0, y = 0;
        cin >> x >> y;
        long long int sqx = x * x;
        long long int sqy = y * y;
        if (sqx + sqy <= d * d)
        {
            ct++;
        }
    }
    cout << ct << endl;
    return 0;
}

Measured memory_bytes: 3672
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var n, k int
var t []task
var dp [][]int

type task struct {
	a int
	b int
	c int
}

func main() {
	n = readInt()
	t = make([]task, n)
	for i := range t {
		t[i] = task{
			a: readInt(),
			b: readInt(),
			c: readInt(),
		}
	}
	dp = make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, 3+1)
	}

	for i := 1; i <= n; i++ {
		for j := 0; j < 3; j++ {
			if j == 0 {
				dp[i][j] = max(dp[i-1][1], dp[i-1][2]) + t[i-1].a

			}
			if j == 1 {
				dp[i][j] = max(dp[i-1][0], dp[i-1][2]) + t[i-1].b

			}
			if j == 2 {
				dp[i][j] = max(dp[i-1][0], dp[i-1][1]) + t[i-1].c

			}
		}
	}

	fmt.Println(max(dp[n][0], max(dp[n][1], dp[n][2])))
}


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

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
// #define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

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

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 112345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

int arr[MAXN];

int32_t main() {
    $
    int n, m;
    cin >> n >> m;
    if (n >= m) {
        cout << "0\n";
        return 0;
    }
    for (int i = 0; i < m; ++i) {
        cin >> arr[i];
    }
    sort (arr, arr + m);
    vi rarr;
    for (int i = 1; i < m; ++i) {
        rarr.push_back(arr[i] - arr[i - 1]);
    }
    sort (all(rarr), greater<int>());
    int ans = 0;
    m = rarr.size();
    for (int i = n - 1; i < m; ++i) {
        ans += rarr[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1276
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, op, B = readline().split()
    A, B = int(A), int(B)
    if op == '+':
        print(A + B)
    else:
        print(A - B)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/

void build(){

}
LL n , m;
void init(){
  n = getint();
  m = getint();
}
void solve(){
  LL ans = min( n , m / 2 );
  n -= ans; m -= ans + ans;
  ans += m / 4;
  cout << ans << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
  int n;
  int h[100005];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  a[0]=0;
  a[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++){
    a[i]=min(abs(h[i]-h[i-1])+a[i-1],abs(h[i]-h[i-2])+a[i-2]);
  }
  cout<<a[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define PI (4*atan(1))

const int prime = 1e9+7;

int mod(int a) { a %= prime; return (a+prime)%prime; }

int xpo(int a, int b) { if(!b) return 1; int temp = xpo(mod(a*a), b/2); if(b&1) temp = mod(temp*a); return temp; }

const int maxn = 1e4+10;

vector<int> g[maxn];
int c[maxn];

int ans[maxn];
int cur;

int total;

void dfs(int aa = 1, int aaa = 0)
{
	++cur;
	ans[aa] = c[cur];
	if(aaa)
		total += min(ans[aa], ans[aaa]);
	for(int a : g[aa])
		if(a != aaa)
			dfs(a, aa);
}

int32_t main()
{
	IOS;

	int n;
	cin >> n;

	for(int i = 1; i < n; ++i)
	{
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}

	for(int i = 1; i <= n; ++i)
		cin >> c[i];

	sort(c+1, c+n+1, greater<int>());

	dfs();

	cout << total << '\n';
	for(int i = 1; i <= n; ++i)
		cout << ans[i] << ' ';

	return 0;
}

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

int main() {
 int N,M,S;
 cin >> N >> M >> S;
 int count = 0;
  
 if(N+M >= S){
   count = S+M;
 }else{
   count = (N+M)*2 -N+1;
 }
  cout << count << 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 height = sc.nextInt();
		int width = sc.nextInt();

		int ret1 = height * width;
		int ret2 = (height * 2) + (width * 2);

		System.out.println(ret1 + " " + ret2);

		sc.close();

	}

}


Measured memory_bytes: 26036