akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        b.at(i)=a.at(i);
    }
    sort(b.begin(),b.end());
    vector<int>odd1;
    vector<int>even1;
    vector<int>odd2;
    vector<int>even2;
    for(int i=0;i<n;i++){
        if(i%2==0){
            even1.push_back(a.at(i));
        }
        else{
            odd1.push_back(a.at(i));
        }
    }
    for(int i=0;i<n;i++){
        if(i%2==0){
            even2.push_back(b.at(i));
        }
        else{
            odd2.push_back(b.at(i));
        }
    }
    sort(odd1.begin(),odd1.end());
    sort(even1.begin(),even1.end());
    int cnt=0;

    for(int i=0;i<odd1.size();i++){
        int left = 0, right = odd1.size();
        while (right - left > 1) {
            int mid = left + (right - left) / 2; // 区間の真ん中

            if (odd1.at(i)>=odd2.at(mid)) left = mid;
            else right = mid;
        }
        if(odd1.at(i)!=odd2.at(left)){
            cnt++;
        }
    }

    for(int i=0;i<even1.size();i++){
        int left = 0, right = even1.size();
        while (right - left > 1) {
            int mid = left + (right - left) / 2; // 区間の真ん中

            if (even1.at(i)>=even2.at(mid)) left = mid;
            else right = mid;
        }
        if(even1.at(i)!=even2.at(left)){
            cnt++;
        }
    }

    cout<<cnt/2<<endl;





    return 0;
}


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

#define ll long long
#define ar array

int main() {

    ios::sync_with_stdio(false);
	
	int a, b, x;
	
	cin >> a >> b >> x;
	
	if (a > x || a+b < x){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
int a[100005];
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int s=0;
    for(int i=0;i<n;)
    {
        if(a[i]==a[i+1])
        {
            i=i+2;
        }
        else
        {
            s++;
            i++;
        }
    }
    printf("%d\n",s);
    return 0;
}



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

int main() {

    int A, B, C;
    cin >> A >> B >> C;

if(A==B&&B!=C||B==C&&C!=A||C==A&&A!=B){
    cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}

}

Measured memory_bytes: 256
class Observatory:
    def __init__(self, height, around=[]):
        self.height = height
        x = []
        self.around = x
    def is_good(self, li, dic):
        flag = True
        for i in self.around:
            o = li[i-1]
            if o.height >= self.height:
                flag = False
            else:
                dic[i-1] = False
        return flag

n, m = map(int, input().split())
h = [int(i) for i in input().split()]
observatories = [Observatory(h[i]) for i in range(n)]
dic = {}
for i in range(n):
    dic[i] = True

for i in range(m):
    a, b = map(int, input().split())
    observatories[a-1].around.append(b)
    observatories[b-1].around.append(a)
    
ans = 0

for i in range(n):
    o = observatories[i]
    if dic[i]:
        if o.is_good(observatories, dic):
            ans += 1

print(ans)


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pnn=pair<int ,int>;

#define ft first
#define sd second
#define fn front
#define pb push_back
#define it insert
#define count ct
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))

string yes="Yes",no="No";

int main() {
  int n,m;
  cin>>n>>m;
  Graph G(n);
  rep(i,m){
      int a,b;
      cin>>a>>b;
      a--; b--;
      G[a].pb(b);
      G[b].pb(a);
  }
  int ans=-1;
  vbl seen(n,0);
  rep(i,n){
      if(seen[i]) continue;
      seen[i]=true;
      ans++;
      queue<int> q;
      q.push(i);
      while(!q.empty()){
          int j=q.front();
          q.pop();
          for(auto x:G[j]){
              if(seen[x]) continue;
              seen[x]=true;
              q.push(x);
          }
      }
  }
  cout<<ans<<endl;
   
}


Measured memory_bytes: 8540
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define PB push_back
const int N=1e5+10;
int main(){
    vector<int> v,t;
    int minus=0,n,a[N];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)if(a[i]==-1){
        minus=i;
        break;
    }
    for(int i=1;i<=n;i++)if(a[i]==2)v.PB(i);
    else if(a[i]==-2)t.PB(i);
    if(t.size()&1){
        if(minus>0){
            v.PB(minus);
            for(int i:t)v.PB(i);
        }
        else{
            for(int i:t)v.PB(i);
            v.pop_back();
        }
    }
    else for(int i:t)v.PB(i);
    sort(v.begin(),v.end());
    printf("%ld\n",v.size());
    for(int i:v)printf("%d\n",i);
}


Measured memory_bytes: 2824
# coding: utf-8

import math
import re
import numpy as np

line = input().split(" ")

h1 = int(line[0])
m1 = int(line[1])
h2 = int(line[2])
m2 = int(line[3])
k = int(line[4])

#分に変換
wake_up = h1*60 + m1
sleep = h2*60 + m2

diff = sleep - wake_up
ans = diff - k

print(ans)



Measured memory_bytes: 26992
def f(a,b):
  a=str(a)
  b=str(b)
  return max(len(a),len(b))
n=int(input())
ans=10**10
for i in range(1,int(n**0.5)+1):
  if n%i:continue
  ans=min(ans,f(n%i,n//i))
print(ans)

Measured memory_bytes: 39024
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define inf 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	queue<char> q;
	rep(i,0,n){
		char tmp;
		cin >> tmp;
		q.push(tmp);
	}
	stack<char> st;
	string ans = "";
	
	while( !q.empty() ){
		char c = q.front();
		q.pop();
		
		if(st.empty()){
			if( c == '(' ){
				st.push(c);
				ans += '(';
			}
			else{
				ans += ')';
				ans.insert(0,"(");
			}
		}else{
			if( st.top() == '(' && c == ')' ){
				ans += ')';
				st.pop();
			}
			else{
				st.push(c);
				ans += '(';
			}
		}
	}

	rep(i,0,st.size())
		ans += ')';

	P(ans);	
	
	ret 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N), B(N + 1);
  for (int i = 0; i < N; i++) cin >> A[i];

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    B[i + 1] = B[i] + A[i];
  }

  for (int i = 1; i <= N; i++) {
    B[i] = (B[i] - i) % K;
  }

  map<ll, ll> m;
  for (int i = 0; i <= N; i++) {
    if (i - K >= 0) m[B[i - K]]--;
    ans += m[B[i]];
    m[B[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 18784
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

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

  int h, w;
  cin >> h >> w;

  vector<string> v(h);
  rep(i, 0, h) cin >> v[i];

  vector<vector<int>> dp(h, vector<int>(w, 1e9));
  if (v[0][0] == '#')
    dp[0][0] = 1;
  else
    dp[0][0] = 0;

  rep(i, 0, h) {
    rep(j, 0, w) {
      rep(k, 0, 2) {
        int ni = i + dx[k], nj = j + dy[k];
        if (ni >= h || nj >= w)
          continue;
        int add = 0;
        if (v[ni][nj] == '#' && v[i][j] == '.')
          add = 1;
        chmin(dp[ni][nj], dp[i][j] + add);
      }
    }
  }

  cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 3660
N,A,B=map(int,input().split())

result = 0

if (A-B)%2 == 0:
    #差が偶数
    result = (B - A) // 2
else:
    #差が奇数
    result = min(A-1,N-B)+1+(B-A-1)//2

print(int(result))


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

int main(){
    int a[5],k;
    rep(i,5) cin >> a[i];
    cin >> k;
    bool flag = true;
    rep(i,5){
        for(int j = i + 1; j < 5; j++) {
//            cout << a[j] - a[i] << endl;
            if((a[j] - a[i]) > k) flag = false;
        }
    }
    cout << (flag ? "Yay!" : ":(") << endl;

}


Measured memory_bytes: 256
// Solitaire LIS
#include <algorithm>
#include <cstdio>
using namespace std;

int decks[100010];
int main() {
  fill(decks, decks + 100010, 1 << 31);
  int n, ndecks = 0;
  scanf("%d", &n);
  for (int i = 0, x; i < n; ++i) {
    scanf("%d", &x);
    int k = lower_bound(decks, decks + ndecks, x) - decks;
    decks[k] = x;
    ndecks = max(ndecks, k + 1);
  }
  printf("%d\n", ndecks);
}


Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        
        System.out.println(e - a > k ? ":(" : "Yay!");
	}	
}

Measured memory_bytes: 20820
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int h,w;
    cin>>h>>w;
    char a[h+10][w+10];
    int b[h+10][w+10];
    rep(i,h) rep(j,w) cin>>a[i][j];
    rep(i,h+10) rep(j,w+10) b[i][j]=0;
    b[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#') b[i][j]=0;
            else if(i==0&&j==0) continue;
            else if(i==0) b[0][j]=b[0][j-1];
            else if(j==0) b[i][0]=b[i-1][0];
            else b[i][j]=(b[i-1][j]+b[i][j-1])%MOD;
        }
    }
    /*
    rep(i,h+1){
        rep(j,w+1){
            cout<<b[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    cout<<b[h-1][w-1]<<endl;
    
}

Measured memory_bytes: 9216
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	int n;
	cin >> n;
	cin.get();
	for(int i=0;i<n;i++)
	{
		string s;
		getline(cin,s);
		for(int j=6;j<s.size();j++)
		{
			if(s.substr(j-6,7)=="Hoshino")
			{
				s.at(j)='a';
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>

using namespace std;

int n, s;

int cal(int a, int b, int c)
{
	int hoge = 0;

	if (a == 1 && b >= c && b < 10)
	{
		return 1;
	}
	if (a == 1)
	{
		return 0;
	}



	for (int i = c; i < 10 && i < b; i++)
	{
		hoge += cal(a - 1, b - i, i + 1);
	}

	return hoge;


}

int main(void)
{
	while (cin >> n >> s,1)
	{
		if (n==0&&s==0)
		{
			break;
		}

		cout << cal(n, s, 0) << endl;
	}

	return 0;
}




Measured memory_bytes: 3052
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int a,b;cin>>a>>b;
  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
class Dice:
    
    def __init__(self, val):
        self.top = val[0]
        self.flat1 = val[3]
        self.flat2 = val[1]
        self.flat3 = val[2]
        self.flat4 = val[4]
        self.bottom = val[5]
        
    def doSouth(self):
        temp = self.bottom
        self.bottom = self.flat2
        self.flat2 = self.top
        self.top = self.flat4
        self.flat4 = temp

    def doNorth(self):
        temp = self.bottom
        self.bottom = self.flat4
        self.flat4 = self.top
        self.top = self.flat2
        self.flat2 = temp

    def doWest(self):
        temp = self.top
        self.top = self.flat3
        self.flat3 = self.bottom
        self.bottom = self.flat1
        self.flat1 = temp


    def doEast(self):
        temp = self.top
        self.top = self.flat1
        self.flat1 = self.bottom
        self.bottom = self.flat3
        self.flat3 = temp
    
    def doget(self):
        list = [self.top, self.flat2, self.flat3, self.flat1, self.flat4, self.bottom]
        return(list)

def transform(dice, motion):
    if motion == 'S':
        dice.doSouth()
    elif motion == 'N':
        dice.doNorth()
    elif motion == 'W':
        dice.doWest()
    elif motion == 'E':
        dice.doEast()

N = input().split()
dice = Dice(N)
motion = input()
for i in range(len(motion)):
    transform(dice, motion[i])
print(dice.top)


Measured memory_bytes: 5572
n = int(input())
s = [int(input()) for _ in range(n)]

ans = sum(s)
x = []

for i in s:
    if i % 10 != 0:
        x.append(i)
x = sorted(x)

for i in x:
    if ans % 10 == 0:
        ans = ans - i
if ans % 10 == 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int g[510][510];

void f(int l, int r, int v) {
	if (r - l <= 1) { return; }
	int m = (r + l) / 2;
	for (int i = l; i < m; ++i) {
		for (int j = m; j < r; ++j) {
			g[i][j] = v;
		}
	}
	f(l, m, v + 1);
	f(m, r, v + 1);
}

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

	memset(g, 0, sizeof(g));
	f(0, N, 1);
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			cout << g[i][j] << (j < N - 1 ? " " : "\n");
		}
	}

	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int t=0;
    int o=0;
    while(a>0){
        a-=d;
        o++;
    }
    while(c>0){
        c-=b;
        t++;
    }
    if(t<=o){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    println!("{}", n * 800 - n / 15 * 200);
    
} 


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

int
main (void)
{
  int n, m, a, i;
  int data[1000][100];
  while (1)
    {
      scanf ("%d%d%d", &n, &m, &a);
      if ((n | m | a) == 0)
	exit (0);
      memset (data, 0, 1000 * 100 * sizeof (int));
      while (1)
	{
	  int h, from, to;
	  scanf ("%d%d%d", &h, &from, &to);
	  if ((h | from | to) == 0)
	    exit (0);
	  data[h - 1][from - 1] = to;
	  data[h - 1][to - 1] = from;
	  if (m-- <= 1)
	    break;
	}
      for (i = 1000; i > 0; i--)
	{
	  if (data[i - 1][a - 1] == 0)
	    continue;
	  a = data[i - 1][a - 1];
	}
      printf ("%d\n", a);
    }
}

Measured memory_bytes: 996
#include<iostream>
using namespace std;
#define max 100000

int partition(int a[], int p, int r) {
	int x = a[r];
	int i = p - 1;
	for (int j = 0; j < r; j++) {
		if (a[j] <= x) {
			i++;
			int tmp;
			tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}
	}
	int tmpp;
	tmpp = a[i + 1];
	a[i + 1] = a[r];
	a[r] = tmpp;

	return i + 1;
}

int main()
{
	int n;
	int a[max];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int num1 = partition(a, 0, n-1);
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		if (i == num1) cout << "[";
		cout << a[i];
		if (i == num1) cout << "]";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3468
N = int(input())
A = list(map(int, input().split()))
MOD, ans = 10**9 + 7, 0
Asum = sum(A)

for i in range(N):
    Asum -= A[i]
    ans = (ans + A[i] * (Asum % MOD)) %MOD

print(ans)

Measured memory_bytes: 31604
import collections

n, m = map(int, input().split())
dic = collections.defaultdict(lambda:[])
for _ in range(m):
  a, b = map(int, input().split())
  dic[a].append(b)
  dic[b].append(a)
  
ans = [None] * n
bfs = [(1,dic[1])]
visited = set()
get = 0
while bfs and get < n:
  now, nexts = bfs.pop(0)

  for i in nexts:
    if i in visited:
      continue
    ans[i-1] = now
    get += 1
    bfs.append((i,dic[i]))
    visited.add(i)
      
print('Yes')  
for i in range(1, n):
  print(ans[i])

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

using namespace std;

bool isAllocatable(int[], int, int, int);

int funcBinominal(int[], int, int);

int main()
{
    int n, k;
    int W[100000];

    cin >> n >> k;

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

    cout << funcBinominal(W, n, k) << endl;
}

bool isAllocatable(int W[], int n, int k, int P)
{
    int weightOfTrack = 0;
    int allocatedTrack = 0;

    for (int i = 0; i < n; i++) {
        
        if (W[i] > P) return false;

        if ((W[i] + weightOfTrack) > P) {
            allocatedTrack++;
            weightOfTrack = W[i];
        } else weightOfTrack += W[i];

        if (allocatedTrack >= k) return false;
    }
    return true;
}

int funcBinominal(int W[], int n, int k)
{
    int min = 1;
    int max = pow(10, 9);

    while(true) {  
        if (min == max) return min;
        int mid = (min + max) / 2;
        if (isAllocatable(W, n, k, mid)) max = mid;
        else min = mid + 1;
    }

    exit(1);
}


Measured memory_bytes: 3496
#include<stdio.h>

int GCD(int a,int b);

/*int GCD(int a,int b)
{
	int i=a,max;
	for(;i>=1;i--)
		if(a%i==0&&b%i==0)
		{
			max=i;
			break;
		}
	return max;
}*/

int GCD(int a,int b)
{
	int temp,yu;
	if(a<b)
	{
		temp=a;
		a=b;
		b=temp;
	}
	if(a%b)
	{
		yu=a%b;
		yu=GCD(b,yu);
	}
	else
		return b;				
	return yu;	
} 

int main(void)
{
	int a,b,max=1;
	scanf("%d%d",&a,&b);
	max=GCD(a,b);
	printf("%d\n",max);	
	return 0;
}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
set<int> pos[256];
int main(){
   //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    string s;
    cin>>n>>s;

    for(int i=0;i<n;i++){
        pos[s[i]].insert(i+1);
    }
    int q;cin>>q;
    rep(i,1,q){
        int op;cin>>op;
        if(op==1){
            int x;char c;
            cin>>x>>c;
            pos[s[x-1]].erase(x);
            pos[c].insert(x);
            
            s[x-1]=c;
        }else{
            int x,y;cin>>x>>y;
            int ret=0;
            rep(c,'a','z'){
               auto it=pos[c].lower_bound(x);
                //debug(*it);
               if(it!=pos[c].end()&&*it<=y)ret++;
            }
            cout<<ret<<endl;
        }
    }
}
/* 
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
 */

Measured memory_bytes: 25752
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;

int n;
vector<double>v;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		double tmp = 0;
		cin >> tmp;
		v.push_back(tmp);
	}
	double ans = -1.0;
	sort(v.begin(), v.end());
	for (int i = 1; i <= n-1; i++) {
		if (i == n-1) {
			double b = v[i] - v[i - 1];
			double s = v[i - 2] + v[i - 3];
			ans = max(ans, s / b);
		}
		else if (i == n - 2) {
			double b = v[i] - v[i - 1];
			double s = v[i + 1] + v[i - 2];
			ans = max(ans, s / b);
		}
		else {
			double b = v[i] - v[i - 1];
			double s = v[n - 1] + v[n - 2];
			ans = max(ans, s / b);
		}
	}
	printf("%.10f\n", ans);
}


Measured memory_bytes: 3272
#include <iostream>

using namespace std;

int main()
{
    int x,y,temp;
    while(1){
        cin >> x >> y;
        if(x==0 && y==0) break;
        if(x < y){
            cout << x << " " << y << endl;
        }
        else{
            temp=x;
            x=y;
            y=temp;
            cout << x << " " << y << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void){

int in=0;
int h=0;
int m=0;
int s=0;
scanf("%d",&in);

while(in>=3600){
in-=3600;
h++;
}
while(in>=60){
in-=60;
m++;
}
s=in;
printf("%d:%d:%d\n",h,m,s);

    return 0; // ???????????¨??±????????????
}

Measured memory_bytes: 2752
using System;
using System.Linq;

namespace D___Integer_Cards
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            var N = read[0];
            var M = read[1];

            var Ai = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            Array.Sort(Ai);

            var BiCi = new BC[M];
            for(int i = 0 ; i < M ; i++)
            {
                read = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
                BiCi[i] = new BC();
                BiCi[i].B = read[0];
                BiCi[i].C = read[1];
            }
            BiCi = BiCi.OrderByDescending(BC => BC.C).ToArray();

            long count = 0;
            for(int i = 0 ; i < M ; i++)
            {
                for(int j = 0 ;j < BiCi[i].B ; j++)
                {
                    if(count>=N) break;
                    if(Ai[count] < BiCi[i].C)
                    {
                        Ai[count] = BiCi[i].C;
                        count++;
                    }else{
                        break;
                    }
                }
            }
            Console.WriteLine(Ai.Sum());
        }
    }
    public struct BC
    {
        public long B{get;set;}
        public long C{get;set;}
    }
}


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

int main(){
	// sengen
	int a,b,c,d;
	// nyuryoku
	cin >> a >> b >> c >> d;
	// keisan
	int sum1 = 0,sum2=0;
	if(c%b==0){
		sum1 = c/b;
	}else{
		sum1 = c/b +1;
	}
	if(a%d==0){
		sum2 = a/d;
	}else{
		sum2 = a/d + 1;
	}
	if(sum1 <= sum2 ){
		cout << "Yes";
	}else{
		cout << "No";
	}
	// syutsuryoku
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a[100];
    int N;
    cin>>N;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }
    int counter=0;
        for(int i=0;i<N;i++)
        {
            while(a[i]>0){
                counter++;
                for(int j=i;j<N;j++)
            {
                if(!a[j]){
                    break;
                }
                a[j]--;
            }
            }
        }
    cout<<counter;
}


Measured memory_bytes: 384
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    c=list(input())
    count=INFI
    #allW
    count=c.count("R")

    #allR
    temp=c.count("W")
    count=min(count,temp)

    #RRR...WWW
    top=0
    bot=n-1
    temp=0
    while top<bot:
        while top < bot:
            if c[top] == "R":
                top+=1
            else:
                temp += 1
                break
        while top<bot:
            if c[bot]=="W":
                bot-=1
            else:
                temp += 1
                break

        top+=1
        bot-=1
#    print(temp)
    temp=temp//2
    count=min(count,temp)
    print(count)



if __name__ == "__main__":

    main()


Measured memory_bytes: 82640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<vector>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int MAX = 105;
static const string DIR = "NESW";
static const int di[4] = {-1, 0, 1, 0};
static const int dj[4] = {0, 1, 0, -1};

int H, W, pi, pj, dir;
long long L;
char G[MAX][MAX];

void input(){
  REP(i, 1, H+1) REP(j, 1, W+1){
    cin >> G[i][j];
    if ( G[i][j] != '.' && G[i][j] != '#' ){
      pi = i; pj = j;
      rep(r, 4)	if ( G[i][j] == DIR[r] ) dir = r;
      G[i][j] = '.';
    }
  }
}

void simulate(){
  int v[MAX][MAX][4];
  rep(i, H+2) rep(j, W+2) rep(r, 4) v[i][j][r] = -1;
  long long pos = 0;
  v[pi][pj][dir] = pos++;
  for (bool cycle = false;  pos <= L; pos++ ){
    int ni = pi + di[dir];
    int nj = pj + dj[dir];
    while(G[ni][nj] == '#'){
      dir = (dir+1)%4;
      ni = pi + di[dir];
      nj = pj + dj[dir];
    } 
    pi = ni;
    pj = nj;
    if ( v[pi][pj][dir] == -1 || cycle ) {
      v[pi][pj][dir] = pos;
    } else {
      long long cycle_len = pos - v[pi][pj][dir];
      long long remain = L - pos;
      pos = L - remain%cycle_len;
      cycle = true;
    }
  }

  cout << pi << " " << pj << " " << DIR[dir] << endl;
}

main(){
  while(1){
    cin >> H >> W >> L;
    if ( H == 0 ) break;
    rep(i, H+2) rep(j, W+2 ) G[i][j] = '#';
    input();
    simulate();
  }
}

Measured memory_bytes: 1392
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
        int h,w,d;
        cin >> h >> w >> d;

        int x[h*w],y[h*w],n;
        for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                        cin >> n;
                        x[n-1]=j; y[n-1]=i;
                }
        }

        int dp[h*w];
        for(int i=0;i<d;i++) dp[i]=0;
        for(int i=d;i<h*w;i++){
                dp[i]=dp[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
        }

        int q,l,r;
        cin >> q;

        for(int i=0;i<q;i++){
                int power=0;
                cin >> l >> r;
                power=dp[r-1]-dp[l-1];
                cout << power << endl;
        }

        return 0;
}


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

int main(){
    int n, k; cin >> n >> k;
    vector<int> lis(n+1, 0);
    for(int i = 0; i < n; i++){
        int k; cin >> k;
        lis[k]++;
    }
    sort(lis.begin(), lis.end(), greater<>());
    int mid = 0;
    for(int i = 0; i < k; i++){
        mid += lis[i];
    }
    cout << n - mid << endl;
}

Measured memory_bytes: 1024
#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

int C,D,W,X;
int E[15][30],F[15][30];

int dp[31][51][15][6];
int dfs(int day, int cost, int place, int two)
{
    if(dp[day][cost][place][two]>=0) return dp[day][cost][place][two];
    if(day==D) return 0;

    int ret=0;

    // ??????????????????
    rep(i,C) ret=max(ret,dfs(day+1,cost,i,two));

    if(E[place][day]>0)
    {
        // 1????????????
        if(cost+F[place][day]<=W)
        {
            rep(i,C) ret=max(ret,dfs(day+1,cost+F[place][day],i,two)+E[place][day]);
        }

        // ?????°????????????
        if(two<X)
        {
            int tcost=cost+F[place][day];
            int tE=E[place][day];
            int now=place-1;
            while(now>=0)
            {
                if(E[now][day]==0) break;
                if(tcost+F[now][day]>W) break;

                tcost+=F[now][day];
                tE+=E[now][day];
                rep(i,C) ret=max(ret,dfs(day+1,tcost,i,two+1)+tE);

                --now;
            }

            tcost=cost+F[place][day];
            tE=E[place][day];
            now=place+1;
            while(now<C)
            {
                if(E[now][day]==0) break;
                if(tcost+F[now][day]>W) break;

                tcost+=F[now][day];
                tE+=E[now][day];
                rep(i,C) ret=max(ret,dfs(day+1,tcost,i,two+1)+tE);
                ++now;
            }
        }
    }

    dp[day][cost][place][two]=ret;
    return ret;
}

int main()
{
    while(scanf(" %d %d %d %d",&C,&D,&W,&X),C)
    {
        rep(i,C)rep(j,D) scanf(" %d", &E[i][j]);
        rep(i,C)rep(j,D) scanf(" %d", &F[i][j]);

        memset(dp,-1,sizeof(dp));
        int ans=0;
        rep(i,C) ans=max(ans,dfs(0,0,i,0));
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3780
def gcd(a, b):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)
def sum_of_gcd(k):
  ans = 0
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      for k in range(1, k + 1):
        if i < j and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j < k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans
 
n = int(input())
print(sum_of_gcd(n))

Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n" 
#define MOD 1000000009

const int MAXN = 3e5 +15;
 
using namespace std;

int R[MAXN], C[MAXN];

void solve(){    
    int n,m,q; cin>>n>>m>>q;
    int mrc = 0, mcc = 0, mr, mc;
    map<pair<int,int>, bool> mp;
    for(int i=0; i<q; i++){
        int a,b; cin>>a>>b;
        R[a]++;
        C[b]++;
        if(C[b] > mcc){
            mcc = C[b];
            mc = b;
        }
        if(R[a] > mrc){
            mrc = R[a];
            mr = a;
        }
        mp[{a,b}] =1;
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        ans = max(ans, mcc+R[i+1] - mp[{i+1,mc}]);
    }
    for(int i=0; i<m; i++){
        ans = max(ans, mrc+C[i+1] - mp[{mr,i+1}]);
    }
    cout<<ans;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);    
    cout<<fixed<<setprecision(12);

    int t =1; //cin>>t;
    for(int i=1; i<= t; i++){
        solve();
        cout<<"\n";
    }
    
    return 0;
}   

Measured memory_bytes: 62256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n;cin>>n;ll steps=0;
	ll h[n];
	for(ll i=0;i<n;i++)
	{
		cin>>h[i];
	}
	for(ll i=1;i<n;i++)
	{
		if(h[i]<h[i-1])
		{
			steps=steps+h[i-1]-h[i];
			h[i]=h[i]+(h[i-1]-h[i]);
		}
	}
	cout<<steps<<"\n";
}

Measured memory_bytes: 5128
import java.util.Scanner;

public class Main{
  static int n, k;
  static int[] x, y;
  static final long INF = Long.MAX_VALUE / 2;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    k = sc.nextInt();
    x = new int[n];
    y = new int[n];
    for(int i = 0; i < n; i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }

    long min = INF;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        for(int kk = 0; kk < n; kk++){
          for(int l = 0; l < n; l++){
            int x1 = Math.min(x[i], x[j]);
            int x2 = Math.max(x[i], x[j]);
            int y1 = Math.min(y[kk], y[l]);
            int y2 = Math.max(y[kk], y[l]);
            int count = 0;
            for(int m = 0; m < n; m++){
              if(x1 <= x[m] && x[m] <= x2 &&
                y1 <= y[m] && y[m] <= y2){
                ++count;
              }
            }
            if(count >= k){
              min = Math.min(min, (long)(x2 - x1) * (long)(y2 - y1));
            }
          }
        }
      }
    }

    System.out.println(min);
  }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

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


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes": "No") << endl;

	return 0;
}



Measured memory_bytes: 256
n,k,q=map(int, input().split())
a = [0]*(n+1)
for i in range(q):
  a[int(input())] += 1
  
for i in range(1, n+1):
  a[i] += k-q
  if a[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 7880
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

LL mod = 1e9 + 7;

int n; 
int a[200005];

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  sort(a, a + n);
  multiset<LL> st;
  st.insert(a[n - 2]);
  st.insert(a[n - 2]);
  LL ans = a[n - 1]; 
  for (int i = n - 3; i >= 0; i--) {
    auto iter = st.end();
    iter--;
    int w = *iter;
    st.erase(iter);
    st.insert(a[i]);
    st.insert(a[i]);
    ans += w;
  }
  cout << ans << endl;

    
#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 13852
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <fstream>

using namespace std;

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


int N,M;
int SS[400];
int LS[400];
int PS[400];
int WS[400];
int dp[401];

int main(){

  cin>>N;
  for(int i=0;i<N;i++){
    cin>>SS[i]>>LS[i]>>PS[i];
  }
  cin>>M;
  for(int i=0;i<M;i++)
    cin>>WS[i];
  for(int j=0;j<=400;j++){
    int res=-1;
    if(j==0)res=0;
    else{
      for(int k=0;k<N;k++){
        for(int l=SS[k];l<=LS[k];l++){
          if(j-l>=0){
            if(dp[j-l]!=-1){
              res=max(res,dp[j-l]+PS[k]);
            }
          }
        }
      }
    }
    dp[j]=res;
  }
  vector<int> res;
  for(int i=0;i<M;i++){
    if(dp[WS[i]]==-1){
      cout<<-1<<endl;
      return 0;
    }
    else{
      res.push_back(dp[WS[i]]);
    }
  }
  for(int i=0;i<(int)res.size();i++){
    cout<<res[i]<<endl;
  }
  
  return 0;
}

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

int main(void) {
	int n[1000];
	int sum[1000];
	int count[1000] = {};
	int point;

	for (int i = 1; i <= 1000; i++) {
		cin >> n[i] >> sum[i];
		if ((n[i] == 0) && (sum[i] == 0)) {
			point = i-1;
			break;
		}
	}

	for (int i = 1; i <= 1000; i++) {
		for (int t = 1; t <= n[i]-2; t++) {
			for (int s = t + 1; s <= n[i]-1; s++) {
				for (int u = s + 1; u <= n[i]; u++){
					if ((t + s + u) == sum[i]) {
						count[i]++;
					}
				}
			}
		}
	}

	for (int i = 1; i <= point; i++) {
		cout << count[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int N, H[105], diff[105] = {0}, ans=0;

int main(){
    cin >> N;

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

    diff[0] = H[0];
    for(int i = 1; i < N; i++)
        diff[i] = H[i] - H[i-1];
    
    for(int i = 0; i < N; i++){
        if(diff[i] > 0) ans += diff[i];
    }
    cout << ans << endl;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll res = 0;
    rep(i,n){
        if(a[i] > 0){
            int num = min(a[i],b[i]);
            a[i] -= num;
            b[i] -= num;
            res+= num;
        }
        if(b[i] > 0 && a[i+1] > 0){
            int num = min(a[i+1],b[i]);
            a[i+1] -= num;
            b[i] -= num;
            res+= num;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1792
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

int main()
{
    int n1, n2;
    std::cin >> n1 >> n2;
    
    if (n1 <= 8 && n2 <= 8) {
        printf("Yay!");
    } else {
        printf(":(");
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int w,h,x,y;
    cin>>w>>h>>x>>y;
    double area;
    int z;
    area = (double)w*h/2;
    if(x+x == w&& y+y == h)
        z = 1;
    else 
        z = 0;
    cout<<area<<" "<<z;
    return 0;
}

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

#define FAST ios_base::sync_with_stdio(false); \
			 cin.tie(nullptr);                 \
	         cout.tie(nullptr)

vector<long long> data;

long long t, a, b, k, n, m, tmp, ans = 0;





int main()
    {
    FAST;


    cin >> n >> t >> a;

    t*= 1000;
    a*= 1000;

    data.resize(n);


    int min_ = 1e9;
    int min_ind = -1;

    for (int i = 0; i < n; i++)
        {
        cin >> data[i];
        data[i] = t - data[i]*6;

        if (abs(a-data[i]) < min_)
            {
            min_ = abs(a-data[i]);
            min_ind = i+1;
            }
        }




    cout << min_ind << endl;

    return 0;
    }


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

int main()
{
  int n, k;

  cin>>n>>k;

  for(int i = 1; i <= n; i += 2)
    k--;

  if(k <= 0)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  

  

  return 0;
}


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

int main () {

	long long m, k;
	cin >> m >> k;

	if ((1LL << m) <= k) {
		cout << -1 << endl;
	} else if (m == 1 && k == 1) {
		cout << -1 << endl;
	} else if (m == 1 && k == 0) {
		cout << "0 0 1 1" << endl;
	} else {
		vector <int> s, t;
		for (int i = 0; i < (1 << m); ++i) {
			if (i != k)
				printf ("%d ", i);
		}
		printf ("%lld ", k);
		for (int i = (1 << m) - 1; i >= 0; --i) {
			if (i != k)
				printf ("%d ", i);
		}
		printf ("%lld\n", k);
	}

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>

using namespace std;

int main () {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed << sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) << endl;
}


Measured memory_bytes: 3288
#include<stdio.h>

int main(void){
	int n,k,c,cc,tmp,c_max;
	int card[102];
	int i,j,l,m;

	while(~scanf("%d %d",&n,&k)){
		if(n+k==0) break;
		for(i=0;i<n;i++)
			scanf("%d",&card[i]);
		c_max=0;
		cc = 0;
		tmp = 1;
		for(i=0;i<=n-k;i++){
			for(j=i;j<k+i;j++){
				tmp*=card[j];
			}
			if(tmp > cc)
				cc = tmp;
			tmp=1;
		}

		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				tmp = card[i];
				card[i] = card[j];
				card[j] = tmp;

				c = 1;
				for(l=0;l<=n-k;l++){
					for(m=l;m<k+l;m++){
						c*=card[m];
					}
					if(c > c_max)
						c_max = c;
					c=1;
				}

				tmp = card[i];
				card[i] = card[j];
				card[j] = tmp;
			}
		}
	
		if(c_max - cc >= 0)
			printf("%d\n",c_max-cc);
		else
			printf("NO GAME\n");
	}
	return 0;
}

Measured memory_bytes: 1028