akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,c[200005],ans[200005],ent[200005],s[200005],tim;
vi a[200005],f[200005];
void dfs(int node,int par){
    ent[node]=++tim;
    s[node]=1;
    for(auto i:a[node]){
        if(i!=par){
            dfs(i,node);
            int w=s[i];
            while(sz(f[c[node]]) and ent[f[c[node]].back()]>=ent[node]) w-=s[f[c[node]].back()],f[c[node]].pop_back();
            s[node]+=s[i];
            ans[c[node]]+=w*(w+1)/2;
        }
    }
    f[c[node]].pb(node);
}
void solve(){
    cin>>n;
    rep(i,1,n+1) cin>>c[i];
    rep(i,0,n-1){
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    dfs(1,0);
    rep(i,1,n+1){
        int w=n;
        while(sz(f[i])) w-=s[f[i].back()],f[i].pop_back();
        ans[i]+=w*(w+1)/2;
        cout<<n*(n+1)/2-ans[i]<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

money = 1000
kabu = 0
toku = 0
min_val = 10000

for i in range(N):
    if (A[i] < min_val):
        min_val = A[i]

    if (A[i] > min_val):
        money += (money // min_val) * (A[i] - min_val)
        min_val = A[i]

print(money)


Measured memory_bytes: 61948
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 'None'

s = input()
alfa = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for x in alfa:
    if not(x in s):
        neko = x
        break
print(neko)

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

int main() {
  int n,m; 
  cin >> n>> m ;
   if (n>=m)cout << 0 << endl;
    else {
	    vector <int> a;
		vector <int> b ;
		
	    for(int i=0; i< m;i++){
		    int c;
		 	cin >> c;
			a.push_back(c); 
			 
		}
		sort (a.begin(),a.end());
		for(int i=0;i<m-1;i++){
		     b.push_back(a.at(i+1)-a.at(i));
		}
		sort(b.begin(),b.end());
		int r=0;
		for(int i=0;i<m-n;i++){
		    r+= b.at(i);
		}
	   cout << r << endl;
    } 
  
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
int N, M, num, mi;
  cin >> N >> M;
int a[N];
int b[N];
int c[M];
int d[M];
  
  for(int i = 0;i < N;i++){
  cin >> a[i];
  cin >> b[i];  
  }
  for(int i = 0;i < M;i++){
  cin >> c[i];
  cin >> d[i]; 
  }
  
  for(int j = 0;j < N;j++){
    mi = 400000001;
  for(int i = 0;i < M;i++){
  if(mi > abs(a[j] - c[i]) + abs(b[j] - d[i])){
  num = i + 1;
  mi = abs(a[j] - c[i]) + abs(b[j] - d[i]);  
  }
  }
        cout << num << endl;
  }
  
  return 0;
  
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
string N;
int main(){
   cin >> N;
   ll ans = -1;
   vector<ll> s(N.size() + 1, 0);
   REP(i, N.size()){
      s[i + 1] = s[i] + (N[i] - '0');
   }
   ans = s[N.size()];
   REP(i, N.size()){
      if(N[i] == '0') continue;
      ll temp = s[i + 1] - 1 + 9 * (N.size() - i - 1);
      chmax(ans, temp);
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	string s1, s2, s3;
	char c = 'A' - 'a';
	cin >> s1 >> s2 >> s3;
	printf("%c%c%c\n", s1[0] + c, s2[0] + c, s3[0] + c);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int r, c;
	while (cin >> r >> c) {
		if (r == 0 && c == 0) break;
		if ((r * c) % 2 == 1) cout << "no\n";
		else cout << "yes\n";
	}
	return 0;
}

Measured memory_bytes: 0
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    const Int INF = 1LL << 60;

    Int n, k;
    cin >> n >> k;
    vector<Int> h(n), dp(n + 105, INF);
    for (Int i = 0; i < n; i++) {
        cin >> h[i];
    }

    dp[0] = 0;
    for (Int i = 0; i < n; i++) {
        for (Int j = 1; j <= k; j++) {
            if (0 <= i + j && i + j < n) {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main (void)
{
    int a;
    int b;
    
    scanf("%d %d",&a,&b);
    
    if(a<b) printf("a < b\n");
     
    if(a>b) printf("a > b\n");
     
    if(a==b) printf("a == b\n");
     
return 0;     
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    ll k;
    cin>>k;
    ll x=7,ans=1;
    map<ll,ll> m;
    if(k%2==0){
      cout<<-1;
      return 0;
    }
    while(x%k!=0){
      x=x%k;
      if(m[x]==0) m[x]++;
      else if(m[x]>0) {
        cout<<-1;
        return 0;
      }
      ans++;
      x=x*10 + 7;
    }
    cout<<ans<<endl;
  
return 0;
    
 }  

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

int main() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == T[i]) cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
int main() {
	//入力
	long K,S,x=0,y=0,z=0,ans=0;
	cin >> K >> S;
	//処理
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
				if (S-(i + j) >= 0 && S-(i+j) <= K) {
					ans++;
				}
		}
	}
	//出力
	cout << ans << endl;
}


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

#define fr first
#define sc second
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define forn(i, b, n) for (int i = b; i < n; ++i)
#define endl '\n'

using namespace std;
const int MAXN = 300 + 2, INF = 1e9 + 9, MOD = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vi mas(n), uv;
    forn(i, 0, n)
        cin >> mas[i];
    int c = 1;
    uv.pb(mas[0]);
    forn(i, 1, n) {
        if (mas[i] != mas[i - 1])
            uv.pb(mas[i]);
    }
    if (uv.size() == 1) {
        cout << 1;
        return 0;
    }
    n = uv.size();
    bool flUp = (uv[0] <= uv[1]);
    forn(i, 2, n) {
        if (flUp && uv[i - 1] > uv[i]) {
            ++c;
            if (i >= n - 1)
                break;
            flUp = (uv[i] < uv[i + 1]);
        } else if (!flUp && uv[i - 1] < uv[i]) {
            ++c;
            if (i >= n - 1)
                break;
            flUp = (uv[i] < uv[i + 1]);
        }
//        cout << i << ' ' << c << ' ' << (flUp ? "Up" : "Down") << endl;
    }
    cout << c;
}


Measured memory_bytes: 2168
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;
int main(){
    int n, m;
    cin >> n >> m;
    int a(n);
    vb dng(n+1, false);
    for(int i = 0; i < m; i++){
        int x;
        cin >> x;
        dng[x] = true;
    }
    vi dp(n+1, 0);
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        if(i - 1 >= 0)
            if(!dng[i-1])
                dp[i] += dp[i-1];
        if(i - 2 >= 0)
            if(!dng[i-2])
                dp[i] += dp[i-2];
        dp[i] %= INF;
    }
    cout << dp[n];
}   

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int mod  = 100003;
const int maxn = 1e5+10;

struct yao
{
	ll val,tim;
};
ll dp[maxn];
yao p[110];
int main()
{
	memset(dp,0,sizeof(dp));
	int t,m;
	cin>>m>>t;
	for (int i=1;i<=m;i++)
		cin>>p[i].tim>>p[i].val;
	for (int i=1;i<=m;i++)
	{
		for (int j=t;j>=1;j--)
		{
			if (j>=p[i].tim)
				dp[j]=max(dp[j],dp[j-p[i].tim]+p[i].val);
		}
	}
	cout<<dp[t];
    return 0;
}


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

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

  long min = 0, max = 0, sum = 0, dat = 0;

  for( int i = 0; i < n; i++ ) {
    cin >> dat;

    if( i == 0 ) {
      min = dat;
      max = dat;
    }
    if( dat < min ) {
      min = dat;
    }
    if( dat > max ) {
      max = dat;
    }

    sum += dat;
  }

  cout << min << " " << max << " " << sum << endl;

  return 0;
}

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

using namespace std;

using ll = long long;
const ll INF = 1LL<<60;

void setmin(ll& a, ll b) {
  if (a > b) a = b;
}

int main() {
  ll n, K;
  cin >> n >> K;
  vector<ll> h(n + 1);
  rep(i, n) cin >> h[i + 1];

  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) rep(j, n) rep(k, i) {
    setmin(dp[i][j + 1], dp[k][j] + max(0LL, h[i] - h[k]));
  }
  ll ans = INF;
  rep(i, n + 1) setmin(ans, dp[i][n - K]);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
typedef long long ll;
vector<long long> vec;
void quicksort(vector<long long> &a, ll left, ll right)
{
	ll mid = a[(left + right) / 2];
	int left_arrow = left, right_arrow = right;
	do
	{
		while (a[left_arrow] > mid)
			left_arrow++;
		while (a[right_arrow] < mid)
			right_arrow--;
		if (left_arrow <= right_arrow)
		{
			ll temp = a[left_arrow];
			a[left_arrow] = a[right_arrow];
			a[right_arrow] = temp;
			left_arrow++;
			right_arrow--;
		}
	} while (left_arrow <= right_arrow);
	if (left < right_arrow)
		quicksort(a, left, right_arrow);
	if (left_arrow < right)
		quicksort(a, left_arrow, right);
}

int main()
{
	vector<long long> A, B, C;
	ll x, y, z, K, temp;
	cin >> x >> y >> z >> K;
	for (int i = 0; i < x; i++) { cin >> temp; A.push_back(temp); }
	for (int i = 0; i < y; i++) { cin >> temp; B.push_back(temp); }
	for (int i = 0; i < z; i++) { cin >> temp; C.push_back(temp); }
	quicksort(C, 0, z - 1);
	quicksort(A, 0, x - 1);
	quicksort(B, 0, y - 1);
	for (int i = 0; i < x; i++)
	{
		for (int j = 0; j < y; j++)
		{
			for (int k = 0; k < z; k++)
			{
				if ((i + 1)*(j + 1)*(k + 1) <= K)
					vec.push_back(A[i] + B[j] + C[k]);
				else
					break;
			}
		}
	}
	quicksort(vec, 0, vec.size() - 1);
	for (int i = 0; i < K; i++)
	{
		printf("%lld\n", vec[i]);
	}
	
	return 0;
}


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

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

map<string, string> S;
rep(i, N){
string s;
cin >> s;
S.insert(make_pair(s, s));
}

cout << S.size();

return 0;

}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  double sum=0;
  for (int i=0;i<N;i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int slctd=0;
  for (int i=0;i<N;i++){
    if (vec.at(i) >= sum/(4*M)){
      slctd += 1;
    }
    else{
      slctd += 0;
    }
  }
  if (slctd >= M){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int par[N], rnk[N], sz[N];
int findroot(int node) {
  if (par[node] == node)
    return node;
  else {
    par[node] = findroot(par[node]);
    return par[node];
  }
}
void dounion(int x, int y) {
  if (rnk[x] > rnk[y]) {
    par[y] = x;
    sz[x] += sz[y];
  }
  else if (rnk[x] < rnk[y]) {
    par[x] = y;
    sz[y] += sz[x];
  }
  else {
    par[x] = y;
    sz[y] += sz[x];
    rnk[y]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    sz[i] = 1;
    par[i] = i;
  }
  pair<int, int> edg[m];
  for (int i = 0; i < m; i++) {
    cin >> edg[i].first >> edg[i].second;
    edg[i].first--;
    edg[i].second--;
  }
  long long ans[m], cnt = (n - 1LL) * n / 2;
  for (int i = m - 1; i >= 0; i--) {
    ans[i] = cnt;
    int x = findroot(edg[i].first);
    int y = findroot(edg[i].second);
    if (x != y) {
      cnt -= 1LL * sz[x] * sz[y];
      dounion(x, y);
    }
  }
  for (int i = 0; i < m; i++)
    cout << ans[i] << ' ';
  return 0;
}


Measured memory_bytes: 6376
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b.sort()
if len(set(a))>=4:
    print('No')
elif b==[0]:
    print('Yes')
elif len(b)==2:
    c_1=a.count(0)
    c_2=a.count(b[1])
    if 2*c_1==c_2:
        print('Yes')
    else:
        print('No')
elif len(b)==3:
    c_1=a.count(b[0])
    c_2=a.count(b[1])
    c_3=a.count(b[2])
    if c_1==c_2==c_3 and b[0]^b[1]^b[2]==0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int main(){
    int n, i, same=0;;
    cin >> n;
    string str[n];

    for(i=0;i<n;i++){
        cin >> str[i];
    }

    sort(str, str+n);

    for(i=0;i<n-1;i++){
        if(str[i] == str[i+1]){
            same++;
        }
    }

    cout << n-same << endl;
    return 0;
}

Measured memory_bytes: 9888
import Control.Monad
import Control.Monad.ST
import Data.STRef
import qualified Data.ByteString.Char8 as C
import Data.Ord
import Data.Vector.Unboxed
import qualified Data.Vector.Unboxed.Mutable as UM
import Data.Vector.Algorithms.Intro
import Prelude hiding (head, tail, zipWith, (++), enumFromTo)

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = kruskal n (ex++ey)
  where
  n = head v
  u = tail v
  vs = generate n id
  ex = es x $ modify (sortBy (comparing x)) vs
  ey = es y $ modify (sortBy (comparing y)) vs
  x i = u!(2*i)
  y i = u!(2*i+1)
  es f is = zipWith (\i j -> (f i-f j,i,j)) (tail is) is

data UnionFind s = UnionFind {ids :: UM.STVector s Int, szs :: UM.STVector s Int}

newUF n = liftM2 UnionFind (unsafeThaw $ enumFromTo 0 (n-1)) (UM.replicate n 1)

findUF uf p q = liftM2 (==) (rootUF uf p) (rootUF uf q)

rootUF uf i = do
  p <- UM.unsafeRead (ids uf) i
  if p==i
    then return i
    else do
      gp <- UM.unsafeRead (ids uf) p
      if gp==p
        then return p
        else do
          UM.unsafeWrite (ids uf) i gp
          rootUF uf i

uniteUF uf p q = do
  i <- rootUF uf p
  j <- rootUF uf q
  si <- UM.unsafeRead (szs uf) i
  sj <- UM.unsafeRead (szs uf) j
  if si<sj
    then do
      UM.unsafeWrite (ids uf) i j
      UM.unsafeWrite (szs uf) j (si+sj)
    else do
      UM.unsafeWrite (ids uf) j i
      UM.unsafeWrite (szs uf) i (si+sj)

kruskal n = go n . modify sort

go n es = runST $ do
  uf <- newUF n
  a <- newSTRef 0
  foldM'_ upd (uf,a) es
  readSTRef a

upd (uf,a) (c,i,j) = do
  b <- findUF uf i j
  unless b $ do
    uniteUF uf i j
    modifySTRef' a (+c)
  return (uf,a)

Measured memory_bytes: 23456
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    int x; cin >> x;
    cout << x+x*x+x*x*x << endl;
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

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

    if ((X >= 400) && (X <= 599))
        cout << 8 << endl;
    else if ((X >= 600) && (X <= 799))
        cout << 7 << endl;
    else if ((X >= 800) && (X <= 999))
        cout << 6 << endl;
    else if ((X >= 1000) && (X <= 1199))
        cout << 5 << endl;
    else if ((X >= 1200) && (X <= 1399))
        cout << 4 << endl;
    else if ((X >= 1400) && (X <= 1599))
        cout << 3 << endl;
    else if ((X >= 1600) && (X <= 1799))
        cout << 2 << endl;
    else if ((X >= 1800) && (X <= 1999))
        cout << 1 << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

vector<ll> graph[200010];
ll vertice;
ll intime[200010];
ll outtime[200010];
ll value[200010];
ll time1=0;
map<ll,ll>position;

void DFS(ll start,ll parent)
{
    time1++;
    intime[start]=time1;
    position[start]=time1;
    ll size=graph[start].size();
    ll store;
    for(ll i=0;i<size;i++)
    {
        store=graph[start][i];
        if(store==parent)
        {
            continue;
        }
        DFS(store,start);
    }
    outtime[start]=time1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
    
    ll q1;
    cin>>vertice>>q1;
    ll vert1,vert2,vert,increment;
    for(ll i=1;i<vertice;i++)
    {
        cin>>vert1>>vert2;
        graph[vert1].push_back(vert2);
        graph[vert2].push_back(vert1);
    }
    DFS(1,-1);
    memset(value,0,sizeof(value));
    while(q1--)
    {
        cin>>vert>>increment;
        value[intime[vert]]+=increment;
        value[outtime[vert]+1]-=increment;
    }
    for(ll i=1;i<200010;i++)
    {
        value[i]+=value[i-1];
    }
    for(ll i=1;i<=vertice;i++)
    {
        cout<<value[position[i]]<<" ";
    }
    return 0;
}

Measured memory_bytes: 46208
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int maxn=5e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;
int k;
int top=0;
int tmp[maxn];

void dfs(int u,int num,int now){
	if(now==num){
		top++;tmp[now]=u;
		if(top==k){
			for(int i=1;i<=num;i++){
				printf("%d",tmp[i]);
			}
		}
	}
	else{
		tmp[now]=u;
		for(int i=max(0,u-1);i<=min(9,u+1);i++){
			dfs(i,num,now+1);
		}
	}
}

int main(){
	scanf("%d",&k);
	while(1){
		for(int i=1;;i++){
			for(int j=1;j<=9;j++){
				dfs(j,i,1);
				if(top>=k) return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
require "prime"
n = gets.chomp.to_i

prime_factors = n.times.inject({}) do |res, i|
  res.merge(Prime.prime_division(i + 1).to_h) do |key, v0, v1|
    v0 + v1
  end
end 

ge_74 = prime_factors.select {|_k, v| v >= 74}.size
ge_24 = prime_factors.select {|_k, v| v >= 24}.size
ge_14 = prime_factors.select {|_k, v| v >= 14}.size
ge_4 = prime_factors.select {|_k, v| v >= 4}.size
ge_2 = prime_factors.select {|_k, v| v >= 2}.size

if ge_4 < 2
  puts 0
else
  # 75の分解の仕方として
  # a: 75, b: 25 * 3, c: 15 * 5, d: 5 * 5 * 3の4通りがある
  a = ge_74
  b = ge_24 * (ge_2 - 1)
  c = ge_14 * (ge_4 - 1)
  d = ge_4 * (ge_4 - 1) / 2 * (ge_2 - 2)
  puts (a + b + c + d)
end


Measured memory_bytes: 14368
N,D = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(N)]
count = 0

for j in range(N):
	for k in range(j):
		total = sum((lis[j][m] - lis[k][m]) ** 2 for m in range(D))
		sqr = total ** 0.5
		if sqr.is_integer():
			count += 1
print(count)

Measured memory_bytes: 3060
import java.util.Scanner;

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

		int cnt = 0;

		for(int i = 0; i <= 2 ; i++) {

			if (judge[i].equals("1")) {
				cnt++;
			}else {
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 20948
x, y, z, k = gets.split.map(&:to_i)
ones = gets.split.map(&:to_i).sort { |a, b| b <=> a }
twos = gets.split.map(&:to_i).sort { |a, b| b <=> a }
threes = gets.split.map(&:to_i).sort { |a, b| b <=> a }

answers = []
ones.each do |one|
  twos.each do |two|
    changed = false
    threes.each do |three|
      sum = one + two + three
      if answers.size < k || sum > answers.first
        index = answers.bsearch_index { |item| item > sum }
        index ||= -1
        answers.insert(index, sum)
        changed = true
        answers.shift if answers.size > k
      else
        break
      end
    end
  break unless changed
  end
end
answers.reverse.each { |answer| puts answer }


Measured memory_bytes: 1912
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            ll=[l[i],l[j],l[k]]
            if len(set(ll))!=3:
                continue
            ll.sort()
            if ll[0]+ll[1]>ll[2] and ll[1]+ll[2]>ll[0] and ll[2]+ll[0]>ll[1]:
                ans+=1           
print(ans)


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

vi normarize(const vi &v)
{
    vector<vi> r(4);
    rep(i,4)
    {
        vi t(4);
        rep(j,4) t[j]=v[(i+j)%4];
        r[i]=t;
    }
    sort(all(r));
    return r[0];
}

inline ll DIM(const vi &v)
{
    if(v[0]==v[1] && v[1]==v[2] && v[2]==v[3]) return 4;
    if(v[0]==v[2] && v[1]==v[3]) return 2;
    return 1;
}

int main()
{
    ll P[401][5]={0};
    for(int i=1; i<=400; ++i)
    {
        P[i][1]=i;
        for(int j=2; j<=min(4,i); ++j) P[i][j]=P[i][j-1]*(i-j+1);
    }

    ll POW[5][5];
    rep(i,5)
    {
        POW[i][0]=1;
        for(int j=1; j<5; ++j) POW[i][j]=POW[i][j-1]*i;
    }

    int n;
    scanf(" %d", &n);

    vector<vi> c(n,vi(4));
    rep(i,n)rep(j,4) scanf(" %d", &c[i][j]);

    map<vi,int> ct;
    rep(i,n)
    {
        c[i]=normarize(c[i]);
        if(ct.find(c[i])==ct.end()) ct[c[i]]=1;
        else ++ct[c[i]];
    }

    ll ans=0;
    // 上面i, 下面j, 下面の向きを設定
    rep(i,n)rep(j,i)rep(k,4)
    {
        vi u(4);
        rep(x,4) u[x]=c[j][(k+x)%4];
        swap(u[1],u[3]);

        vector<vi> sides(4);
        rep(x,4)
        {
            vi t(4);
            t[0]=c[i][(x+1)%4];
            t[1]=c[i][x];
            t[2]=u[x];
            t[3]=u[(x+1)%4];
            sides[x]=normarize(t);
        }
        sort(all(sides));

        ll add=1;
        int idx=0, st=0;
        while(1)
        {
            while(idx<4 && sides[st]==sides[idx]) ++idx;
            vi key=sides[st];
            int value=idx-st;

            // 使ってないタイルのうち当てはめられる個数
            int num=ct[key];
            if(c[i]==key) --num;
            if(c[j]==key) --num;

            if(num<value)
            {
                add=0;
                break;
            }

            // 選び方、向き、位置
            add*=P[num][value]*POW[DIM(key)][value];

            if(idx==4) break;
            st=idx;
        }
        ans+=add;
    }

    // 向かい合う面の個数ぶん重複する
    cout << ans/3 << endl;
    return 0;
}


Measured memory_bytes: 35200
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll n;
set<ll> P;
vector< pair< pair<ll,ll> , ll> > a;
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++)
        {
                ll x , y;
                cin >> x >> y;
                a.pb(make_pair(make_pair(x , y), 0));
        }
        for(ll i =1 ; i<= n ; i++)
        {
                ll x , y;
                cin >> x >> y;
                a.pb(make_pair(make_pair(x , y), 1));
        }
        sort(a.begin() , a.end());
        ll cnt = 0;
        for(auto i : a)
        {
                if(i.second == 0) {
                        P.insert(i.first.second);
                }else {
                        ll Y = i.first.second;
                        auto it = P.lower_bound(Y);
                        if(it == P.begin()) continue;
                        else {
                                it--;
                                cnt++;
                                P.erase(it);
                        }
                }
        }
        cout << cnt << endl;
        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define MOD 1000000007
#define long long long
// x^n mod
long mod_pow(long x, long n, long mod){
  long res=1;
  x %= mod;
  while(n>0){
    if(n&1) res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

int main(){
  int n;
  cin>>n;
  vector<int> a(n, 0);
  rep(i,n){
    int d;
    scanf("%d", &d);
    a[d]++;
  }

  int d;
  if(n%2==1){
    if(a[0]!=1){
      cout<<0<<endl;
      return 0;
    } else d=2;
  } else {
    d=1;
  }
  rep(i,n/2) if(a[d+i*2]!=2){
    cout<<0<<endl;
    return 0;
  }

  cout << mod_pow(2,n/2,MOD) << endl;

  return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int k;
  cin >> k;
  int odds = 0;
  int evens = 0;
  for (int i = 1; i <= k; ++i) {
    if (i % 2 ==0) evens++;
    else odds++;
  }
  cout << odds * evens << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
 
int main(){
  int A, B;
  std::cin >> A >> B;
  for(int i = 0; i < 10000; ++i){
    if(std::floor(i*0.08) == A && std::floor(i*0.10) == B ){
      std::cout << i;
      return 0;
    }
  }
  std::cout << "-1";
  return 0;
}

Measured memory_bytes: 256
/**********************************************************************************************

?§£???
	???????????????[i]??????????¨????????????°??????
	????????°????????¨???????´?????????§??????
	?????????????????????
	???????????????[i]??¨???[i - 1]????°??????????(-1)???+1,??§?????????(-1)???-1??????
	??????????????¨??¨??§??????????´??????????cnt[i]+=cnt[i - 1]?????????
	???ans??????a[i]*cnt[i]??¨b[i]*cnt[i]+c[i]????????????????¬?*?????°???or???IC+IC??????*?????°???

**********************************************************************************************/
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

struct COST {
	long long int a;
	long long int b;
	long long int c;
};

int p[100000];
COST cost[100000];
long long int cum[100000];
long long int cnt[100000];
long long int ans;

int main() {
	memset(cum, 0, sizeof(cum));
	memset(cnt, 0, sizeof(cnt));

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < n - 1; ++i) {
		cin >> cost[i].a >> cost[i].b >> cost[i].c;
	}
	for (int i = 1; i < m; ++i) {
		long long int x = p[i], y = p[i - 1];
		if (x > y) { swap(x, y); }
		x--; y--;
		cnt[x]++; cnt[y]--;
	}
	for (int i = 1; i < n; ++i) {
		cnt[i] += cnt[i - 1];
	}
	for (int i = 0; i < n - 1; ++i) {
		ans += min(cost[i].a * cnt[i], cost[i].b * cnt[i] + cost[i].c);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7408
n,m=map(int,input().split())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
ans=0
for v in range(1,n+1):
 for u in g[v]: #i番目の展望台から1本の道を通っていけるすべての展望台と高さを比較する
   if arr[u]>=arr[v]:
     break
 else: #i番目の展望台の高さが他のすべての展望台の高さより真に大きければ答えを1増やす
   ans+=1
print(ans)

Measured memory_bytes: 29424
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

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

  //sort(all(s));

  int cnt = 0;

  for (int i = 0; i < q; ++i) {
    cnt += binary_search(all(s), t[i]);
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 3384
#include <iostream>

using namespace std;

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

        int k=1,t=1;
        bool ei=true,el=true;
        for(int j=1;j<10;j++)
        {
            if(a[j]>b[k-1])
            {
                b[k]=a[j];
                k++;
            }
            else if(a[j]>c[t-1])
            {
                if(ei)
                {
                    c[0]=a[j];
                    ei=false;
                }
                else
                {
                    c[t]=a[j];
                    t++;
                }
            }
            else
            {
                el=false;
                break;
            }
        }
        if(el)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        n=n-1;

    }
    return 0;
}



Measured memory_bytes: 3116
#
# 150C Count Order
#
import itertools
import sys

n = input()
p = input()
q = input()

if p==q:
    print(0)
    sys.exit()

p = p.replace(' ', ', ')
p = "(" + p + ")"

q = q.replace(' ', ', ')
q = "(" + q + ")"

a = [int(i)+1 for i in range(int(n))]
b = list(itertools.permutations(a))

pcount = 0
qcount = 0
pf = False
qf = False

for i in range(len(b)):
    if str(b[i])==p:
        pcount = i+1
        pf = True
    if str(b[i])==q:
        qcount = i+1
        qf = True
    if pf and qf:
        break

print(abs(pcount-qcount))

Measured memory_bytes: 14012
// SeeAlso: https://atcoder.jp/contests/abc151/tasks/abc151_d

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int h,w;

ll ans = 0;
int arr[4][2] = { 
    {0, 1},
    {0, -1},
    {1, 0},
    {-1, 0} 
};

int rec(const vector<string> &v, int x, int y) {
    
    int H = v.size(), W = v[0].size();
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int,int>> que;

    int res = 0;
    que.push({x, y});
    dist[x][y] = 0;
    while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        rep(i, 4) {
            int nx = x + arr[i][0];
            int ny = y + arr[i][1];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    return res;
}

int main() {
    cin >> h >> w;
    vector<string> v(h);
    rep(i, h) {
        cin >> v[i];
    }

    int ans = 0;
    rep(i, h) {
        rep(j,w) {
            if (v[i][j] == '#') continue;
            ans = max(ans, rec(v,i,j));    
        }
    }    
    print(ans);
    return 0;
}


Measured memory_bytes: 256
/*
中間試験、期末試験のいずれかを欠席した場合成績は F。
中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 
 ただし、再試験の点数が 50 以上ならば成績は C。
中間試験と期末試験の合計点数が 30 未満ならば成績は F。
*/
#include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int test1, test2, test3;
        cin >> test1 >> test2 >> test3;
        
        if(test1 == -1 && test2 == -1 && test3 == -1)
        { break; }
        
        if(test1 == -1 || test2 == -1)
        { cout << "F" << endl; }
        else if(test1 + test2 >= 80)
        { cout << "A" << endl; }
        else if(65 <= test1 + test2 && test1 + test2 < 80)
        { cout << "B" << endl; }
        else if(50 <= test1 + test2 && test1 + test2 < 65)
        { cout << "C" << endl; }
        else if( 30 <= test1 + test2 && test1 + test2 < 50) 
        { 
            if(50 <= test3)
            { cout << "C" << endl; }
            else
            { cout << "D" << endl; }
        }
        else if( test1 + test2 < 30)
        { cout << "F" << endl; }
        
        
        
    }
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int main(void)
{
	int w, a;
	
	while(scanf("%d", &w) != EOF && w != -1){
		
		int rates = 1150;
		
		if(w > 30){
			rates += (1250 + 1400);
			rates += (w - 30) * 160;
		}
		else{
			if(w > 20){
				rates += 1250;
				rates += (w - 20) * 140;
			}
			else if(10 < w && w <= 20){
				rates += (w - 10) * 125;
			}
		}
		
		printf("%d\n", 4280 - rates);
	}
		
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
long long memo[100];

long long Lucas(int N)
{
    if(memo[N] != -10)
        return memo[N];
    
    if(N == 0)
        return 2;
    
    if(N == 1)
        return 1;

    return memo[N] = Lucas(N - 1) + Lucas(N - 2);
}

int main()
{
    int N;
    cin >> N;
    for(int i = 0;i < 99;i++)
        memo[i] = -10;
    cout << Lucas(N) << endl;
}


Measured memory_bytes: 384
n = gets.chomp.to_i
b = gets.chomp.split(' ').map(&:to_i)
a = 0

if n == 2 then
    a += b[0] * 2
else
    a += b[0]
    for i in 0..n-3 do
        if b[i] < b[i+1] then
            a += b[i]
        else
            a += b[i+1]
        end
    end
    a += b[n-2]
end

puts a

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
//#define f first
//#define s second
//#define mp make_pair
#define gg return 0;
#define pii pair < int, int>
 
using namespace std;
 
const int maxn = 132675;
const int INF = (int)1e9;
 
ll a,b[maxn],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;
 
ll x[maxn],y[maxn],x2[maxn],y2[maxn];
 
bool u[maxn], m, f;
 
vector <int> v;
 /*
void forn( int s, int f, int inter){
	for(int i = s; i <= f; i += inter){
		b[i] = i;
	}
}
*/ 
ll ans;
 
ll pref;
 
//vector <int> g[maxn],d[maxn];
 
ll lvlc,lvl[maxn];
/*
void dfs(int v){
	lvlc++;
	lvl[v] = lvlc;
	d[lvl[v]].pb(v);
	u[v] = 1;
	for(int i = 0; i < g[v].size(); ++i){
		int to = g[v][i];
		if(!u[to]){
			dfs(to);
		}
	}
	lvlc--;
}*/

map <int, int> mp; 
 
char ch;

string s; 

int main()
{
	int t;
	cin >> a >> t;
	for(int i = 1; i <= a; ++i){
		cin >> b[i];
	}
	for(int i = 1; i <= a; ++i){
		mn = min(mn,b[i]);
		mp[b[i] - mn]++;
	}
	cout << mp.rbegin() -> second;
	gg
}

Measured memory_bytes: 7552
#include <stdio.h>

int main (){
	int H, A;
	scanf("%d %d", &H, &A);
	int kali = 0;
	
	while (H > 0){
		H = H - A; // 6 - 4 = 2
		kali++; // 1
	}	
	printf("%d", kali);
	
//	int kali = ceil ((double) H / (double) A);
//	printf("%d", kali);
	return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int a,b,k;
	cin >> a >> b >> k;
	int count =0;
	for (int i =100; i > 0; i--) {
		if (a % i == 0 && b %i == 0) {
			count++;
			if (count == k) {
				cout << i << endl;
				return 0;
			}
		}
	}

}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    rep(i, N) cin >> W[i];
    
    vector<int> S(N + 1, 0);
    rep(i, N) S[i + 1] = S[i] + W[i];
    
    int ans = 1000000000;
    rep(T, N - 1) {
        int S1 = S[T + 1];
        int S2 = S[N] - S[T + 1];
        ans = min(abs(S1 - S2), ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

# https://atcoder.jp/contests/abc090/tasks/arc091_b
# 15:26-


def main():
    N, K = map(int, input().split())

    ans = 0
    for b in range(K+1, N+1):
        if (N+1) % b == 0:
            ans += (N//b+1) * (b-K)
        else:
            ans += N // b * (b-K)
            if N % b >= K:
                ans += N % b - K + 1
        if K == 0:
            ans -= 1

    return ans


print(main())


Measured memory_bytes: 3060
n,q = map(int,input().split())
r = [[] for i in range(n)]
v = [0 for i in range(n)]

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

for i in range(q):
    p,x = map(int,input().split())
    v[p-1] += x


bfs = [0]
visit = [False for i in range(n)]
while len(bfs) != 0:
    tmp = []
    for i in bfs:
        for y in r[i]:
            if not visit[y]:
                v[y] += v[i]
                tmp.append(y)
        visit[i] = True
    bfs = tmp

#print(" ".join(map(str,v)))
print(*v)

Measured memory_bytes: 55808
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

N, M = MI()
city = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    city[a - 1].append(b - 1)
    city[b - 1].append(a - 1)
    
for c in city:
    print(len(c))

Measured memory_bytes: 62024
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <fstream>
#include <bitset>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define sort1(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> p;
bool paircom (pair<int,int> p,pair<int,int> q){
return p.second<q.second;
}

void count(vector<int> v,vector<int>& ans){
    sort1(v);
    int n=v.size();
  int k=1;
  int i=1;
  bool bl=true;
    while(true){
    while(bl){
        if(v[i-1]==v[i]){
        k++;    
      }else{
          bl=false;
      }
      i++;
      }
      ans.push_back(k);
      if(i>=(n-1))break;
      k=1;
      bl=true;
    }
    }




int main() {

int x,ans;
cin >> x;
ans=10-x/200;
cout <<ans;
}

    

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en,h) for(int i=st; i<=en; i+=h)
#define eb emplace_back
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,ans,p,q;
string s;

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

  cin>>n>>m; Pr(Int) a;
  rep(i,n){
    cin>>p; a.push(p);
  }
  for (int j = 0; j < m; j++){
    q=a.top(); a.pop();
    q/=2; a.push(q);
  }
  while(!a.empty()){
    q=a.top(); ans+=q; a.pop();
  }
  END
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "No";
    if (a==b+c || b==a+c || c==a+b) ans = "Yes";
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    string s;
    int sum = 0;
    cin >> s;

    for(int i = 0; i<s.size();i++) sum += s[i] - '0';
    if(sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  set<int> st = {1, 9, 7, 4};
  int N;
  rep(i, 4) {
    cin >> N;
    st.erase(N);
  }

  if (st.size() == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  long long X, res = 2;
  cin >> X;
  REP(i,X) res = (res + 1) * 2;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3616