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

using namespace std;


int main() {

  int n;

  char str[11];


  while(cin >> n) {

    if(n==0) break;

    sprintf(str,"%o",n);

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

      if(str[i]=='4') str[i]='5';

      else if(str[i]>'4') str[i]+=2;

    }

    cout << str << endl;

  }
  
  return 0;

}

Measured memory_bytes: 888
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
ans = []

for i in a:
    add = c
    for j in range(m):
        add += i[j]*b[j]
    if add > 0:
        ans.append(add)

print(len(ans))


Measured memory_bytes: 3060
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int A,B;
    cin>>A>>B;
    cout<<(A-1)*(B-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define NEWMAT(N, M, ini) MAT(N, vector<lint>(M, ini))
#define MOD 1000000007

typedef long long lint;
typedef pair<lint, lint> P;
typedef vector<lint> V;
typedef vector<vector<lint>> MAT;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint A; cin >> A;
    lint B; cin >> B;
    lint C; cin >> C;

    lint res = 0;

    if (A==B && B==C) {
      PRINT("Yes");
    } else {
      PRINT("No");
    }

    return 0;
}


Measured memory_bytes: 256
n, l = map(int, input().split())
t = [l+i for i in range(n)]
s = sum(t)
df = float('inf')
ans = 0
for i in range(n):
  pie = s - t[i]
  if abs(s - pie) < df:
    df = abs(s - pie)
    ans = pie
print(ans)

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

int main(void){
    int N;
    cin >> N;
    string s;
    int AB{0}, BA{0}, A{0}, B{0};

    for(int i{0}; i<N; ++i){
        cin >> s;
        for(int j{1}; j<s.size(); ++j){
            if(s[j-1]=='A' and s[j]=='B')
                ++AB;
        }
        if(s[0]=='B' and s[s.size()-1]=='A'){
            ++BA;
        }
        else if(s[0]=='B'){
            ++B;
        }
        else if(s[s.size()-1]=='A'){
            ++A;
        }
    }
    if(BA==0)
        cout << AB + min(A, B) << endl;
    else if(A+B>0)
        cout << AB + BA + min(A, B) << endl;
    else
        cout << AB + BA -1 << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <stack>

int main(void)
{
	char s[100];
	std::stack<int> st;
	while(scanf("%s", s) != EOF) {
		if(s[0] == '+') {
			int a = st.top(); st.pop();
			int b = st.top(); st.pop();
			st.push(b + a);
		}else if(s[0] == '*') {
			int a = st.top(); st.pop();
			int b = st.top(); st.pop();
			st.push(b * a);
		}else if(s[0] == '-') {
			int a = st.top(); st.pop();
			int b = st.top(); st.pop();
			st.push(b - a);
		}else{
			st.push(std::atoi(s));
		}
	}
	printf("%d\n", st.top());
	return 0;
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
const int mod = 1e9+7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
inline bool read(ll &num) {
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    } 
    if(IsN) num=-num;
    return true;
}
priority_queue<ll> q;
int main(){
   // freopen("1.in", "r", stdin);
    int n,m;
    ll x;
    cin>>n>>m;
    rep(i,1,n){
        cin>>x;
        q.push(x);
    }
    while(m--){
        ll now=q.top();q.pop();
        q.push(now/2);
    }
    ll ans=0;
    while(!q.empty()){
        ans+=q.top();q.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;


    ll    x=n/500;
    //cout<<x<<endl;
    ll    y=n%500;
    ll    z=(y/5)*5;
    //cout<<z<<endl;

    cout<<(x*1000)+z<<endl;


    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(x, y):
    return (x * y) // gcd(x, y) #math.gcd(x, y)

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = B//C - (A-1)//C
n_D = B//D - (A-1)//D

n_CD = B // CD - (A-1) // CD
    
ans = int()#- n_C - n_D + 
print('{}'.format(B-A+1-(n_C+n_D-n_CD)))


Measured memory_bytes: 12416
#include<bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define fi first
#define se second
using namespace std;
template <class T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;

int n,k,c;
string s;
vector<int> b,e;

int main()
{
	cin>>n>>k>>c>>s;
	c++;
	int day=0,i=1;
	b.pb(-inf);
	while(true)
	{
		while(day<sz(s)&&(s[day]=='x'||day-b.back()<c)) day++;
		if(day>=sz(s)) return 0;
		b.pb(day);
		i++;
		if(i>k) break;
		day++;
	}
	e.pb(inf);
	day=sz(s)-1,i=1;
	while(true)
	{
		while(day<sz(s)&&(s[day]=='x'||e.back()-day<c)) day--;
		if(day>=sz(s)) return 0;
		e.pb(day);
		i++;
		if(i>k) break;
		day--;
	}
	reverse(all(e));
	e.pop_back();
	b.erase(b.begin());
	for(int i=0;i<k;i++)
		if(b[i]==e[i])
			cout<<b[i]+1<<endl;
	return 0;
}

Measured memory_bytes: 5716
import math
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,X,T=mi()
    print(T*math.ceil(N/X))





if __name__ == "__main__":
    main()

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};

void solve() {
  int n;
  cin >> n;
  int prev = -1;
  rep(i, n) {
    int h;
    cin >> h;
    if (prev == h) continue;
    if (prev > h) no();
    prev = --h;
  }
  yes();
}


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

const int MAX = 40;

int l[MAX], r[MAX];

void dfs(int v, vector<int>& res) {
	if (l[v] != -1) dfs(l[v], res);
	if (r[v] != -1) dfs(r[v], res);
	res.push_back(v);
}

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i]; p[i]--;
	}
	vector<int> c(n), rc(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i]; c[i]--;
		rc[c[i]] = i;
	}
	fill(l, l + n, -1);
	fill(r, r + n, -1);
	int id = 0;
	set<int> vs;
	for (int i = 1; i < n; i++) {
		vs.insert(rc[p[id]]);
		while (true) {
			auto it = vs.upper_bound(min(rc[p[i]], rc[p[id]]));
			if (it == vs.end() || *it >= max(rc[p[i]], rc[p[id]])) break;
			id--;
		}
		if (rc[p[id]] > rc[p[i]]) {
			l[p[id]] = p[i];
		}
		else {
			r[p[id]] = p[i];
		}
		id = i;
	}
	vector<int> res;
	dfs(p[0], res);
	for (int i = 0; i < n; i++) {
		cout << res[i] + 1 << " \n"[i + 1 == n];
	}
	return 0;
}

Measured memory_bytes: 3160
n, l = map(int, input().split())

s = (l + n - 1) * (l + n) // 2 - (l - 1) * l // 2

if l <= 0 and l + n > 0:
    eat = 0
else:
    if l < 0:
        eat = l + n - 1
    else:
        eat = l

print(s - eat)


Measured memory_bytes: 38384
#include<iostream>

using namespace std;

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

int n, m;
int memo[10000000];
int maxnum;

int main() {
    while(1) {
        cin >> n >> m;
        if (n==0) break;

        if (m < 1000) {
            maxnum = 100000;
        } else {
            maxnum = 7368800;
        }

        REP(i, maxnum) {
            memo[i] = 0;
        }

        int output;
        for (int i=n; i<maxnum; i++) {
            if (memo[i]==0) {
                if (m==0) {
                    output = i;
                    break;
                }

                m--;
                REP(j, maxnum/i) {
                    memo[i+i*j] = 1;
                }
            }
        }
        cout << output << endl;
    }
}




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

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x; return is;
}

typedef long long ll;
typedef vector<int> vi;  // vi x(n);
typedef vector<ll> vll; // vll x(n);
typedef vector<pair<int,int>> vpi;  // vpi x(n); x[i]={a,b};
typedef vector<pair<ll,ll>> vpll;  // vpll x(n); x[i]={a,b};
typedef vector<vector<int>> vvi;  // vvi x(m,vi(n)); x[i][j]=a;
typedef vector<vector<ll>> vvll; // vvll x(m,vi(n)); x[i][j]=a;

#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main(){
    int n, d, l, a;
    cin >> n >> d;

    vvi x(n,vi(d));
    REP(i,n){
        REP(j,d){
            cin >> x[i][j];
        }
    }

    a = 0;
    FOR(i,0,n-1){
        FOR(j,i+1,n){
            l = 0;
            REP(k,d) l += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            REP(k,l+1){
                if(k*k == l){
                    a++;
                    break;
                }
                else if(k*k > l) break;
            }
        }
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
function f()
    input1 = map(x -> parse(Int, x), split(chomp(readline()), " "))
    input2 = map(x -> parse(Int, x), split(chomp(readline()), " "))

    H = input1[1]
    W = input1[2]
    h = input2[1]
    w = input2[2]

    ret = (H - h) * (W - w)
    print(ret)
end
f()

Measured memory_bytes: 170436
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll n;
    cin>>n;
    ll a[n];
    vector<ll> pref_sum(n, 0);
    for(ll i = 0; i < n; i++)
    {
        cin>>a[i];
        if(i == 0)
        {
            pref_sum[i] = a[i];
        }
        else
        {
            pref_sum[i] = pref_sum[i - 1] + a[i];
        }
    }
    vector< vector<ll> > dp(n, vector<ll>(n, LLONG_MAX));
    for(ll i=0; i<n; i++)
    {
        dp[i][i] = 0;
    }
    for(ll chain = 2; chain <= n; chain += 1)
    {
        for(ll i=0; (i + chain) <= n; i++)
        {
            ll j = i + chain - 1;
            // cout<<i<<" "<<j<<'\n';
            for(ll k = i; k < j; k++)
            {
                ll val = pref_sum[j];
                if(i > 0)
                {
                    val -= pref_sum[i - 1];
                }
                dp[i][j] = min( val + dp[i][k] + dp[k + 1][j], dp[i][j]); 
            }
            // cout<<dp[i][j]<<'\n';
        }
    }
    cout<<dp[0][n-1]<<'\n';
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef tuple<int,int,int> iii;
typedef tuple<ll,int,int> lii;
const ll INF = 1000000000000000;
int n,m,s;
vector<iii> adjlist[55];
int C[55], D[55];
ll t[55][2555];
priority_queue<lii, vector<lii>, greater<lii> > pq;
int main(){
    scanf("%d%d%d",&n,&m,&s);
    for (int i = 0; i < m; i++){
        int u,v,a,b;
        scanf("%d%d%d%d",&u,&v,&a,&b);
        adjlist[u].emplace_back(v,a,b);
        adjlist[v].emplace_back(u,a,b);
    }
    for (int i = 1; i <= n; i++){
        scanf("%d%d",&C[i],&D[i]);
    }
    for (int i = 1; i <= 50; i++){
        for (int j = 0;  j <= 2500; j++){
            t[i][j] = INF;
        }
    }
    s = min(s,2500);
    t[1][s] = 0;
    pq.emplace(0,1,s);
    while (pq.size()){
        ll d;
        int u,c;
        tie(d,u,c) = pq.top(); pq.pop();
        if (d > t[u][c]) continue;
        ll newd = d + D[u];
        if (c+C[u] <= 2500 && t[u][c+C[u]] > newd){
            //printf("%d %d -> %d %d %lld\n",u,c,u,c+C[u],newd);
            t[u][c+C[u]] = newd;
            pq.emplace(newd,u,c+C[u]);
        }
        for (auto it : adjlist[u]){
            int v,a,b;
            tie(v,a,b) = it;
            if (c < a) continue;
            newd = d + b;
            if (t[v][c-a] > newd){
                //printf("%d %d -> %d %d %lld\n",u,c,v,c-a,newd);
                t[v][c-a] = newd;
                pq.emplace(newd,v,c-a);
            }
        }
    }
    for (int i = 2; i <= n; i++){
        ll ans = INF;
        for (int j = 0; j <= 2500; j++){
            //printf("%lld ",t[i][j]);
            ans = min(ans,t[i][j]);
        }
        printf("%lld\n",ans);
    }



}


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

int main(){
    int n, a, b, count = 0;
    bool inRow = false;
    cin >> n;
    while(n--){
        cin >> a >> b;
        if(a == b)  count++;
        else count = 0;

        if(count >= 3)  inRow = true;
    }
    if(inRow)  cout << "Yes";
    else    cout << "No";
}

Measured memory_bytes: 3632
#include<iostream>
// Need start
#include<vector>
#include<queue>
// Need end
using namespace std;

// Copy start
template <typename T>
class Dijkstra {
    private:
        using P = pair<T, int>;
        struct edge {
            int to;
            T cost;
        };
        T identity_;
        vector<vector<edge>> graph_;
        vector<T> dist_;
    public:
        Dijkstra(int node_num, T identity):
        identity_(identity), graph_(vector<vector<edge>>(node_num)), dist_(vector<T>(node_num, identity)) {}
        void addEdge(int from, int to, T cost) {
            edge now_edge = {to, cost};
            graph_[from].push_back(now_edge);
        }
        void calcShortestPath(int start_node) {
            priority_queue<P, vector<P>, greater<P>> pque;
            dist_[start_node] = 0;
            pque.push(P(0, start_node));
            while (!pque.empty()) {
                P now = pque.top();
                pque.pop();
                int now_node = now.second;
                if (dist_[now_node] < now.first) continue;
                for (int i = 0; i < graph_[now_node].size(); ++i) {
                    edge e = graph_[now_node][i];
                    if (dist_[e.to] > dist_[now_node] + e.cost) {
                        dist_[e.to] = dist_[now_node] + e.cost;
                        pque.push(P(dist_[e.to], e.to));
                    }
                }
            }
        }
        T getDist(int u) {
            return dist_[u];
        }
};
// Copy end

using ll = long long;

const ll INF = 1LL << 50;

int main() {
    // This sample is Atcoder Nikkei Contest 2019 Qual D
    int N, M;
    cin >> N >> M;
    Dijkstra<ll> dijkstra(N, INF);
    for (int i = 1; i < N; ++i) {
        dijkstra.addEdge(i, i - 1, 0);
    }
    int L, R;
    ll C;
    for (int i = 0; i < M; ++i) {
        cin >> L >> R >> C;
        --L, --R;
        dijkstra.addEdge(L, R, C);
    }
    dijkstra.calcShortestPath(0);
    ll ans = dijkstra.getDist(N - 1);
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 10104
#include <iostream>

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

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    double a, b, h;
    std::cin >> a >> b >> h;
    std::cout << (int) ((a + b) / 2 * h) << '\n';
    return 0;
}

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

int main()
{
    ll N,K;
    cin >> N >> K;
    N %= K;

    while(1)
    {
        ll diff;
        if((N - K) >= 0)diff = N - K;
        else diff = K - N;
        
        if(N > diff)
        {
            N = diff;
        }
        else
        {
            break;
        }
        
    }
    cout << N << endl;
    return 0;
}

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

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

    int heights[N];
    int dp[N];
    

    for(int i = 0; i < N; i++) {
        cin >> heights[i];
    }
    dp[0] = 0;
    dp[1] = abs(heights[1] - heights[0]);


    for(int i = 2; i < N; i++){
        dp[i] = dp[i - 1] + abs(heights[i] - heights[i - 1]);

        for(int j = 1; j <= K && (i - j) >= 0; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(heights[i] - heights[i - j]));
        }
    }


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

    return 0;
}


Measured memory_bytes: 1024
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z, k, n;
	string s;
	cin >> s;

	n = s.size();

	z = 0;


	for (auto x : s) {
		z += (x - '0');
		z %= 9;
	}

	if (z % 9 == 0)	puts("Yes");
	else puts("No");

	// ce(z);

}



Measured memory_bytes: 3776
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  cout << a-b+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<double,double>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////

void solve(){
  ini(N);
  vl v(N); in(v);
  vi ans(N);
  rep(i,N) ans[v[i] - 1] = i + 1;
  out(ans);

}

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		for(int i = 0; i < n;i++) {
			int a = sc.nextInt();
			for(int j = 0; a * j + 1 <= d;j++) x++;
		}
		System.out.println(x);
	}
}

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



int main()
{
    int a, b;
    cin >> a >> b;
    double low = b*10, high = (b+1)*10;
    if(a >= (int)floor(low*8.0/100.0) && a < (high*8.0)/100.0)
    {
        for(int i = (int) low; i < high; i++)
        {
            if(floor(i*0.08) == a)
            {
                cout << i;
                break;
            }
        }
    }
    else
        cout << "-1";
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int H, W;
    int i, j;
    while(1){
        scanf("%d %d", &H, &W);
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i==0||j==0||i==H-1||j==W-1){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c[3],d,e,z;
    cin>>a>>b;
    c[0]=a+b;
    c[1]=a-b;
    c[2]=a*b;
    z=c[0];
    for(d=1; d<3; d++)
    {
        if(z<=c[d])
    {
        z=c[d];
    }
    }



    cout<<z<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	while(s.size()>0){
		if(s.size()>=5&&s.substr(s.size()-5,5)=="dream"||s.substr(s.size()-5,5)=="erase"){
			s=s.substr(0,s.size()-5);
			continue;
		}
		if(s.size()>=6&&s.substr(s.size()-6,6)=="eraser"){
			s=s.substr(0,s.size()-6);
			continue;
		}
		if(s.size()>=7&&s.substr(s.size()-7,7)=="dreamer"){
			s=s.substr(0,s.size()-7);
			continue;
		}
		
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
}


Measured memory_bytes: 640
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define N 100100
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(x, a, b) for(int x=a; x<=b; x++)
#define drp(x, a, b) for(int x=a; x>=b; x--)
int deg[N], d[N], n, vis[N], a[N], tot, num[N], l[N], ans=1, fac[N], inv[N];
vector<pair<int, int> > fu;
queue<int> q;
int power(int a, int k){
	int ret=1;
	while(k)
	{
		if(k&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod; k>>=1;
	}
	return ret;
}
int C(int n, int m){
	return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int pr(int n){
	return 1ll*fac[2*n]*inv[n]%mod*power((mod+1)>>1, n)%mod;
}
void init(){
	fac[0]=1;
	rep(i, 1, n) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=power(fac[n], mod-2);
	drp(i, n, 1) inv[i-1]=1ll*inv[i]*i%mod;
}

int st[N<<1];
void renew(int &x, const int y){
	x += y;
	if(x < 0) x += mod;
	if(x >= mod) x -= mod;
}
int getdp(){
	int fr = 0;
	rep(i, 1, tot) st[i + tot] = st[i];
	rep(i, 1, tot) if(l[st[i]]){
		fr = i;
		break;
	}
	reverse(st + fr + 1, st + fr + tot);
	int a = fr + l[st[fr]] - 1, b = a + 1, c = 1;
	rep(i, fr + 1, fr + tot - 1)if(l[st[i]]){
		int na = i + l[st[i]] - 1, nb = na + 1, cc = 0;
		if(a < i) renew(cc, c);
		if(b < i) renew(cc, c);
		a = na;
		b = nb;
		c = cc;
	}
	int ans = 0;
	if(a < fr + tot) renew(ans, c);
	if(b < fr + tot) renew(ans, c);
	return ans;
}

int main(){
	scanf("%d", &n);
	init();
	rep(i, 1, n)
	{
		scanf("%d", a+i);
		deg[a[i]]++;
	}
	rep(i, 1, n) if(deg[i]>2) return puts("0"), 0;
	rep(i, 1, n) d[i]=deg[i];
	rep(i, 1, n) if(!d[i]) q.push(i);
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		vis[u]=1;
		if(--d[a[u]]==0) q.push(a[u]);
	}
	rep(i, 1, n) if(vis[i] && deg[i]>1) return puts("0"), 0;
	rep(i, 1, n) if(vis[i] && !deg[i])
	{
		int x=i, cnt=0;
		for(; vis[x]; x=a[x]) cnt++;
		l[x]=cnt;
	}
	rep(i, 1, n) if(!vis[i])
	{
		int x=i, fl=0, ass=1; tot=0;
		for(; !vis[x]; x=a[x]) st[++tot]=x, fl|=bool(l[x]), vis[x]=1;
		if(!fl) num[tot]++;
		else
		{
			fu.clear();
			//if(l[i]) fu.pb(mp(l[i], 0));
			//for(int p=1, x=a[i]; x!=i; x=a[x]) if(l[x]) fu.pb(mp(l[x], p));
			rep(p, 1, tot) if(l[st[p]]) fu.pb(mp(l[st[p]], p));
			fu.pb(mp(fu[0].fi, fu[0].se+tot));
			int sz=fu.size();
			rep(j, 1, sz-1)
			{
				if(fu[j].fi>fu[j].se-fu[j-1].se) ass=0;
				if(fu[j].fi<fu[j].se-fu[j-1].se) ass=2ll*ass%mod;
			}
//			ass=getdp();
		}
		ans=1ll*ans*ass%mod;
	}
	rep(i, 1, n) if(num[i])
	{
		int m=num[i], ass=0;
		rep(j, 0, m/2)
		{
			int tmp=1ll*C(m, 2*j)*pr(j)%mod*power(i, j)%mod;
			if(i>1 && (i&1)) tmp=1ll*tmp*power(2, m-2*j)%mod;
			ass=(ass+tmp)%mod;
		}
		ans=1ll*ans*ass%mod;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3616
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ){
    if ( L[i].value <= R[j].value ){
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right ){
  int mid;
  if ( left+1 < right ){
    mid = (left + right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if ( p < r ){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}

int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
 for ( j = p; j < r; j++ ){
    if ( A[j].value <= x.value ){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}

main(){
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;
  scanf("%d", &n);

 for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);
for ( i = 0; i < n; i++ ){
    if ( A[i].suit != B[i].suit ) stable = 0;
  }

  if ( stable == 1 ){
    printf("Stable\n");
  }
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }
}




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

int main() {
int64_t a,c,d;
  c=0;
  d=0;
char b;
cin>>a;
  vector<char> vec(3);
  for(int64_t i=0;i<4;i++){
  cin>>b;
    if(b!='.'){vec.at(d)=b;
              d++;}
  }
  c=(int64_t)((vec.at(0)-'0')*100+(vec.at(1)-'0')*10+vec.at(2)-'0');
  cout<<a*c/100<<endl;
} 

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n);
	input(a);
	sort(all(a),greater<ll>());
	int at = 0;
	for (int i = 0; i < n-1; i++) {
		ans += a[at];
		if (i % 2 == 0) {
			at++;
		}
	}
	cout << ans << endl;
}

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

int main(){
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int ans = 0;
  for(int i = 0; i < N; ++i){
    if(x >= A[i]){
      x -= A[i];
      ++ans;
    }else{
      x = 0;
      break;
    }
  }
  if(x > 0) --ans;
  ans = max(ans,0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;
	ll M;

	cin >> N;
	cin >> M;
	vpll D(N);

	for (int i = 0; i < N; i++)
	{
		cin >> D[i].first >> D[i].second;
	}
	sort(all(D));
	ll ans = 0;

	for (int i = 0; M > 0; i++)
	{
		ll buy = min(M, D[i].second);

		ans += D[i].first * buy;
		M -= buy;
	}
	cout << ans << endl;

}



Measured memory_bytes: 1792
n = input()
A = []
sum = 0
for i in n:
    A.append(i)
    sum += int(i)

if A[0] == '1':
    print(max(sum, (len(A) - 1) * 9))
else:
    print(max(sum, (len(A) - 1) * 9 + int(A[0]) - 1))

Measured memory_bytes: 38256
n = int(input())

print(0)
init_state = input().rstrip()
if init_state == "Vacant":
    exit()
if init_state == "Male":
    states = ["Male", "Female"]
else:
    states = ["Female", "Male"]

l = 0; r = n
while r - l > 1:
    mid = (r + l) // 2
    print(mid)
    new_state = input().rstrip()
    if new_state == "Vacant":
        exit()
    if new_state == states[mid % 2]:
        l = mid
    else:
        r = mid
print(r, l)

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

import math
# 時針Aの位置、真ん中を(0,0)とする
# 時針の角速度1時間で30°, 3時間でpie/2
# 時針角速度(分単位）
a_omega_m = math.pi/2/3/60
# 分針角速度（分単位）
# 2pie/1 hour
b_omega_m = 2*math.pi/60

# 何分過ぎたか
T = H*60 + M

# 時針の位置
A_y = A*math.sin(a_omega_m*T)
A_x = A*math.cos(a_omega_m*T)
B_y = B*math.sin(b_omega_m*T)
B_x = B*math.cos(b_omega_m*T)

print(math.sqrt((A_y - B_y)**2 + (A_x - B_x)**2))

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	vector<vector<int>> c(3,vector<int>(3));
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	bool pro=true;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(c[i%3][j%3]-c[i%3][(j+1)%3]!=c[(i+1)%3][j%3]-c[(i+1)%3][(j+1)%3])pro=false;
			if(c[j%3][i%3]-c[(j+1)%3][i%3]!=c[j%3][(i+1)%3]-c[(j+1)%3][(i+1)%3])pro=false;
		}
		

	}
	cout<<((pro)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define findnot find_first_not_of
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD funcions*/
lli power(lli x,lli y,lli p)
{
	lli res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%p;
		//y must be even now
		y=y>>1; //y=y/2
		x=(x*x)%p;
	}
	return res;
}
lli modi(lli a,lli m)
{
// fermat little thm where m is prime
return power(a,m-2,m);
}
lli sumXOR(lli arr[],lli n) 
{ 
    lli sum = 0; 
    for (int i = 0; i < 60; i++)  
    { 
        lli zc = 0, oc = 0;  
        lli idsum = 0;  
        for (int j = 0; j < n; j++) 
        { 
            if (arr[j] % 2 == 0) 
                zc=(zc+1)%mod;
            else
                oc=(oc+1)%mod;
            arr[j] /= 2; 
        } 
        idsum = (oc%mod);
        lli temp=(zc%mod* power(2,i,mod))%mod;   
        idsum=(idsum*temp)%mod;
        sum=(sum+ idsum)%mod;;  
    } 
    return sum; 
} 
int main()
{
    kira;
    lli s=0;
    lli n;
    cin>>n;
    lli a[n];
    forz(i,n)cin>>a[i];
    s=sumXOR(a,n);
    cout<<s;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
 
//dp解
//dp[i][j] -> i,jから始めた時一致している長さ
int dp[5005][5005];
 
int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  for (int i = N-1; i >= 0; i--) {
    for (int j = N-1; j >= 0; j--) {
      if(s[i] != s[j] )dp[i][j] = 0;
      else dp[i][j] = dp[i+1][j+1] + 1;
    }
  }
  int res = 0;
  rep(i,N)rep(j,N) {
    if (i >= j) continue; // i < j 
    int now = min(dp[i][j], j - i);//i文字目を終端とした時のlenの最大
    res = max(res,now);
  }
  
  cout << res << endl;
  return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(LL (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

const int MOD = 1000000007;

int main(){
    LL N;
    cin>>N;
    Vll x(N),y(N),h(N);
    REP(i,N){
        cin>>x[i]>>y[i]>>h[i];
    }
    
    REP(cx,101){
        REP(cy,101){
            bool ok = true;
            LL H = 0;
            REP(i,N){
                if(h[i] == 0) continue;
                H = h[i]+abs(x[i]-cx)+abs(y[i]-cy);
            }
            REP(i,N){
                LL hi = max(H - abs(x[i]-cx) - abs(y[i]-cy), 0LL);
                if(h[i] != hi) ok = false;
            }
            if(ok) cout<<cx<<" "<<cy<<" "<<H<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main() {
	
	int N, K, X, Y,ans = 0;

	cin >> N;
	cin >> K;
	cin >> X;
	cin >> Y;

	for (int i = 1; i <= N; i++) {
		if(i <= K) ans += X;
		else ans += Y;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            
            if((a+b+c) <= 21){
                System.out.println("win");
            }
            else if((a+b+c) >= 22){
                System.out.println("bust");
            }
    }
}

Measured memory_bytes: 35848
#include <stdio.h>
int main(void){
  int i;
  long long int a,b,c,k,w;
  w=0;
  scanf("%lld",&a);
  scanf("%lld",&b);
  scanf("%lld",&c);
  scanf("%lld",&k);

  for(i=0;i<k;i++){
    if(a>0){
      w++;
      a--;
    }else if(b>0){
      b--;
    }else if(c>0){
      w=w-1;
    }
  }
  printf("%lld",w);
  return 0;
  }

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

ll solve(const vector<vector<int>> &adj, int k, int S) {
  int N = adj.size();
  if(S == (1 << N) - 1) return 1LL;
  ll res = 0LL;
  for(int e: adj[k]) {
    if((S >> e) & 1) continue;
    res += solve(adj, e, S + (1 << e));
  }
  return res;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> adj(N);
  REP(i,M) {
    int a, b;
    cin >> a >> b; --a; --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  cout << solve(adj, 0, 1) << endl;
  return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll x; cin >> x;
  cout << x / 500 * 1000 +(x % 500) /5 * 5 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s;
    int q;
    bool flag = true;

    cin >> s >> q;

    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;

        if (t == 1)
        {
            flag = !flag;
        }
        else
        {
            int f;
            string c;
            cin >> f >> c;

            if (f == 1)
            {
                if (flag)
                {
                    s.insert(0, c);
                }
                else
                {
                    s += c;
                }
            }
            else
            {
                if (flag)
                {
                    s += c;
                }
                else
                {
                    s.insert(0, c);
                }
            }
        }
    }

    if (flag)
    {
        cout << s << endl;
    }
    else
    {
        for (int i = s.size() - 1; i >= 0; i--)
        {
            printf("%c", s[i]);
        }

        printf("\n");
    }
}

Measured memory_bytes: 900
#include <iostream>

using namespace std;

int main()
{
    unsigned long long W, H;
    int x, y;
    cin >> W >> H >> x >> y;

    cout << (double)(W * H) / 2 << " ";
    if (W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2){
            cout << 1;
    }
    else
        cout << 0;
    cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

long long int gcm(long long int x,long long int y){
	long long int r,tmp;
	if(x<y){
		tmp=x;
		x=y;
		y=tmp;
	}
	r=x%y;
	while(r!=0){
		x=y;
		y=r;
		r=x%y;
	}
	return(y);
}

int main(){
	int T;
	scanf("%d",&T);
	int q,i;
	long long int A[T],B[T],C[T],D[T];
	long long int a,b,c,d,gcm_bd;
	
	for(q=0;q<T;q++){
		scanf("%lld %lld %lld %lld",&A[q],&B[q],&C[q],&D[q]);
	}
	for(q=0;q<T;q++){
		a=A[q];
		b=B[q];
		c=C[q];
		d=D[q];
		if(a<b || d<b){
			printf("No\n");
		} else if(c>=b){
			printf("Yes\n");
		} else {
			gcm_bd=gcm(b,d);
			a=b-gcm_bd+(a%gcm_bd);
			if(a>c){
				printf("No\n");
			} else{
				printf("Yes\n");
			}
		}
	}
	return 0;
}

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

char in[120];
pair<pair<string,int>,int> p[110];
int main(){
int a;scanf("%d",&a);
for(int i=0;i<a;i++){
int t;scanf("%s%d",in,&t);
string tmp=in;
p[i]=make_pair(make_pair(in,-t),i);
}
std::sort(p,p+a);
for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);
}

Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();
    let n: u8 = iter.next().unwrap().parse().unwrap();
    let k: u8 = iter.next().unwrap().parse().unwrap();

    println!("{}", if 2 * k - 1 <= n { "YES" } else { "NO" });
}


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

// varibable settings
#define infile "../test/sample-3.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 ceil(a,b) ((a)+(b)-1)/(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 n;cin>>n;
  vi p(n);
  map<int, int> pos;
  rep(i, n){
    cin>>p[i];
    pos[p[i]] = i;
  }
  dump(p);

  multiset<int> st;
  st.insert(-1);
  st.insert(-1);
  st.insert(n);
  st.insert(n);

  int ans = 0;
  rrep(x, 1, n+1){
    dump(x, st);
    int i = pos[x];
    auto it = st.upper_bound(i);
    int r1 = *it;
    int r2 = *next(it);
    int l1 = *prev(it);
    int l2 = *prev(prev(it));
    dump(x, i, l2, l1, r1, r2);
    ans += x*abs((r2-r1)*(l1-i));
    ans += x*abs((l2-l1)*(r1-i));
    st.insert(i);
  }
  cout << ans << 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: 12032