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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N, M;
    cin >> N >> M;
    
    ll sum = 0;
    vector<ll> A(N);
    REP(i, N) { 
        cin >> A[i];
        sum += A[i];
    }
    ll cnt = 0;
    REP(i, N) {
        if (A[i] * 4 * M >= sum) {
            cnt++;
        }
    }
    if (cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

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

int main() {
  string s,t,ss = "",tt = "";
  cin >> s >> t;
  vector<int>sd(26,0);
  vector<int>td(26,0);
  for(int i = 0;i < s.size();i++){
    sd[s[i]-'a']++;
  }
  for(int i = 0;i < t.size();i++){
    td[t[i]-'a']++;
  }
  for(int i = 0;i < 26;i++){
    for(int j = 0;j < sd[i];j++) ss.push_back('a'+i);
  }
  for(int i = 25;i >= 0;i--){
    for(int j = 0;j < td[i];j++) tt.push_back('a'+i);
  }
  if(ss < tt) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <utility>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<typename T>
void chmin(T &a, T b) {
    a = min(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<ll> L(N);
    REP(i, 0, N) {
        cin >> L[i];
    }

    vector<int> group(N, 0);
    auto calc = [&](int n, int goal) -> ll {
        vector<int> g;
        REP(i, 0, N) {
            if (group[i] == n) {
                g.push_back(L[i]);
            }
        }
        ll ans = 1LL << 60;
        REP (i, 1, 1 << g.size()) {
            ll tmp = 0;
            ll cnt = 0;
            REP (j, 0, g.size()) {
                if ((i >> j) & 1) {
                    tmp += g[j];
                    cnt += 10;
                }
            }
            if (cnt >= 10) {
                cnt -= 10;
            }
            if (tmp < goal) {
                chmin(ans, goal - tmp + cnt);
            } else{
                chmin(ans, tmp - goal + cnt);
            }
        }
        return ans;
    };
    ll ans = 1LL << 60;
    function<void(int)> rec = [&](int pos) {
        if (pos == N) {
            chmin(ans, calc(0, A) + calc(1, B) + calc(2, C));
            return;
        }
        REP(i, 0, 3) {
            group[pos] = i;
            rec(pos + 1);
            group[pos] = -1;
        }
    };

    rec(0);
    cout << ans << endl;

    return 0;
}


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

int charge(int n){
    int res = 1150;
    int per[3] = {125, 140, 160};
    int lim[4] = {10, 20, 30, 100};
    for(int i=0; i<3; i++){
        res += per[i] *max(0, (min(lim[i+1], n) -lim[i]));
    }
    return res;
}

int main(){
    int n;
    while(cin >> n, n!=-1){
        cout << 4280 -charge(n) << endl;
    }
    return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B,X;
	cin >> A >> B >> X;
	if (X >= A && A + B >= X){
		cout << "YES" <<endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()

def main():
    ans = float('inf')
    length = len(S)
    for i in range(length - 2):
        s = S[i:i + 3]
        n = int(s)
        ans = min(ans, abs(753 - n))
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
	int n, tmp;
	cin >> n;
	list<int> ls;
	for(int i = 0; i < n - 1; i++){
		cin >> tmp;
		ls.push_front(tmp);
	}
	cin >> tmp;
	cout << tmp;
	for(int i : ls){
		cout << " " << i;
	}
	cout << endl;
	return 0;
}

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

ll cost[300][300];
int main(){
    int n,m,R; cin >> n >> m >> R;
    vector<ll> v(R);
    rep(i,R){
        cin >> v[i];
        v[i]--;
    }
    sort(v.begin(),v.end());
    rep(i,n+1){
        rep(j,n+1){
            if(i==j) cost[i][j]=0;
            else cost[i][j] = INF;
        }
    }
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c;
        a--;b--;
        cost[a][b] = c;
        cost[b][a] = c;
    }

    rep(k,n+1){
        rep(i,n+1){
            rep(j,n+1){
                cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
            }
        }      
    }
    ll ans = INF;
    do{
        ll sum=0;
        for(int i=0;i+1<R;i++){
            sum += cost[v[i]][v[i+1]];
        }
        ans = min(ans,sum);
    }while(next_permutation(v.begin(),v.end()));
    cout << ans << endl;
}

Measured memory_bytes: 4112
def third_root(q):
    x=q/2
    while abs(x**3-q)>=q*10**(-5):
        x=x-(x**3-q)/(3*x**2)
    return x
while 1:
    q=eval(input())
    if q==-1:break
    ans=third_root(q)
    print(ans)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b; cin>>a>>b;
    reverse(all(b));
    if (a==b){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    long long int ans = 0;
    long long int now;
    long long int cnt = 0;
    
    cin >> n;

    vector<long long int> v(n);

    for (int i = 0; i < n; i++) cin >> v[i];

    sort(v.begin(), v.end());
    now = v[0];

    v.push_back(-1);

    for (int i = 0; i < (int)v.size(); i++) {
        if (now == v[i]) {
            cnt++;
        }
        else {
            if (cnt < now) {
                ans += cnt;
            }
            else if (cnt > now) {
                ans += (cnt - now);
            }
            now = v[i];
            cnt = 1;
        }
    }

    cout << ans << endl;
}


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

int n,k,a[10];
string s,t;

int main() {
  cin >> s;
  t="CODEFESTIVAL2016";
  int cnt=0;
  rep(i,s.size()){
    if(s[i]!=t[i]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf 1000000000
#define gcd __gcd //最大公約数,gcd(x,y)
int lcm(int a, int b){return a/gcd(a, b)*b;} //(int)最小公倍数,lcm(x,y)
ll llcm(ll a, ll b){return a/gcd(a, b)*b;}//(ll)最小公倍数,lcm(x,y)


int main(){
  int N,i,j,maxi=0,tmp=0;
  cin >> N;
  int L[N];
  for(i=0 ; i<N ; i++){
    cin >> L[i];
    maxi = max(maxi,L[i]);
    if(maxi == L[i]){
      j = i;
    }
  }

  for(i=0 ; i<N ; i++){
    if(i != j){
      tmp += L[i];
    }
  }

  if(tmp > maxi){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
import * as readline from 'readline';
const rl = readline.createInterface(process.stdin, process.stdout);

let line = 0;
let n: number;
let a: number[];
let b: number[];
let c: number[];

rl.on("line", input => {
  line++;
  if (line === 1) {
    n = parseInt(input);
  } else if (line === 2) {
    a = input.split(/\s+/).map(val=>parseInt(val));
  } else if (line === 3) {
    b = input.split(/\s+/).map(val=>parseInt(val));
  } else {
    c = input.split(/\s+/).map(val=>parseInt(val));

    let x = 0;
    for (let i = 0; i < n; i++) {
      x += b[a[i]-1];
      if (i > 0 && a[i] === (a[i-1] + 1)) {
        x += c[a[i-1]-1];
      }
    }
    console.log(x);
  }
});


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

using namespace std;

bool check[200];

int main(){
	int x, y;
	int aux, menor = 110, resp = -1;
	cin>>x>>y;
	for(int i = 1; i <= y; i++){
		cin>>aux;
		check[aux] = true;
	}
	
	for(int i = -10; i<=150; i++){
		if(i<1 || check[i]==false){
			if(abs(x-i)<menor){
				menor = abs(x-i);
				resp = i;
			}
			
		}
	}
	
	cout<<resp<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
n=int(input())
c=list(input())
if len(set(c))==1:
    print('0')
else:
    r=c.count('R')
    w=c.count('W')
    rc=c[:r].count('R')
    wc=c[:r].count('W')
    if rc==0:
        if r<w:
            print(r)
        else:
            print(w)
    else:
        if r-rc<wc:
            print(r-rc)
        else:
            print(wc)


Measured memory_bytes: 11744
from collections import deque
d = deque(list(input()))
rev = False
for _ in range(int(input())):
    q = list(input().split(" "))
    t = int(q[0])
    if t == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(q[1]) == 1:
            if rev:
                d.append(q[2])
            else:
                d.appendleft(q[2])
        elif int(q[1]) == 2:
            if rev:
                d.appendleft(q[2])
            else:
                d.append(q[2])
if rev:
    d.reverse()
for res in d:
    print(res, end="")


Measured memory_bytes: 7520
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <cinttypes>
using std::int64_t;
using std::max;

int N, M;
int64_t XYZs[1000][3];
int64_t DP[1001][1001];

int64_t ScoreForSign(int xsign, int ysign, int zsign) {
  int64_t scores[1000];
  for (int n = 0; n < N; ++n) {
    scores[n] = XYZs[n][0] * xsign;
    scores[n] += XYZs[n][1] * ysign;
    scores[n] += XYZs[n][2] * zsign;
  }

  for (int n = 1; n < N+1; ++n) {
    for (int m = 1; m < M+1; ++m) {
      DP[n][m] = max(DP[n-1][m-1] + scores[n-1], DP[n-1][m]);
    }
  }
  return DP[N][M];
}

int main() {
  scanf("%d %d", &N, &M);
  for (int n=0; n < N; ++n) {
    scanf("%" PRId64 " %" PRId64 " %" PRId64, &XYZs[n][0], &XYZs[n][1], &XYZs[n][2]);
  }

  for (int m = 0; m < M+1; ++m) {
    DP[0][m] = INT64_MIN / 2;
  }
  for (int n = 0; n < N+1; ++n) {
    DP[n][0] = 0;
  }

  int64_t best = 0;
  best = max(best, ScoreForSign(+1, +1, +1));
  best = max(best, ScoreForSign(-1, +1, +1));
  best = max(best, ScoreForSign(+1, -1, +1));
  best = max(best, ScoreForSign(+1, +1, -1));
  best = max(best, ScoreForSign(+1, -1, -1));
  best = max(best, ScoreForSign(-1, +1, -1));
  best = max(best, ScoreForSign(-1, -1, +1));
  best = max(best, ScoreForSign(-1, -1, -1));

  printf("%" PRId64 "\n", best);
  return 0;
}

Measured memory_bytes: 8064
(defun solve (a b c x y)
  (min (+ (* a x) (* b y))
       (+ (* c 2 y) (* a (if (> (- x y) 0) (- x y) 0)))
       (+ (* c 2 x) (* b (if (> (- y x) 0) (- y x ) 0)))))

(princ (solve (read) (read) (read) (read) (read)))

Measured memory_bytes: 12388
import java.util.*;
import java.io.*;

public class Main{
	public static boolean isInteger( String input ) { //Pass in string
    	try { //Try to make the input into an integer
        	Integer.parseInt( input );
        	return true; //Return true if it works
    	}
    	catch( Exception e ) { 
        	return false; //If it doesn't work return false
    	}
	} 

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		
		if(s.length() == (a + b + 1)){ 
			if(s.charAt(a) == '-'){
				String s1 = s.substring(0, a);
				String s2 = s.substring(a+1);
				if(isInteger(s1) && isInteger(s2))
					System.out.println("Yes");
				else
					System.out.println("No");
			}else{
				System.out.println("No");
			}
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) for(ll i=1;i<=(n);i++)
#define MOD 1000000007
#define int long long
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1e9;

void bin(int lb, int ub)
{
    char ans;
    while (ub - lb > 1) {
        int mid = (lb + ub) / 2;
        cout << "? " << mid * 10 << endl;
        cin >> ans;
        if (ans == 'Y') {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    
    cout << "? " << lb * 10 << endl;
    cin >> ans;
    if (ans == 'Y') {
        cout << "! " << lb << endl;
    } else {
        cout << "! " << ub << endl; 
    }
    
    return;
}

signed main()
{
    char ans;
    
    cout << "? 1000000000" << endl;
    cin >> ans;
    
    if (ans == 'Y') {
        for (int i=1; i<=1000000000; i*=10) {
            cout << "? " << i * 2 << endl;
            cin >> ans;
            if (ans == 'Y') {
                cout << "! " << i << endl;
                return 0;
            }
        }
    } else {
        for (int i=100000000; i>=1; i/=10) {
            cout << "? " << i << endl;
            cin >> ans;
            if (ans == 'Y') {
                bin(i + 1, i * 10 - 1);
                return 0;
            }
        }
        cout << "! 1" << endl;
        return 0;
    }
}


Measured memory_bytes: 596
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    vector<int> b;

    vector<int> ev;
    vector<int> od;

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

        if (i % 2 == 0) {
            ev.push_back(a);
        } else {
            od.push_back(a);
        }
    }


    if (n % 2 != 0) {
        for (int i = ev.size() - 1; i >= 0; i--) {
            cout << ev[i] << " ";
        }
        for (int i = 0; i < od.size(); i++) {
            cout << od[i] << " ";
        }
    } else {
        for (int i = od.size() - 1; i >= 0; i--) {
            cout << od[i] << " ";
        }
        for (int i = 0; i < ev.size(); i++) {
            cout << ev[i] << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<string> v;
	for (int i = 0; i < n; i++) {
		string a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

	size_t size = v.size();
	cout << size << endl;
	return 0;
}


Measured memory_bytes: 11664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;


bool kaibun(string x){
    bool is_kaibun = true;
    for(int i=0; i<x.size(); i++){
        if(x[i] != x[x.size()-1-i]){
            is_kaibun = false;
        }
    }
    return is_kaibun;
}

int main(){
    string s;
    cin >> s;
    if(kaibun(s) and kaibun(s.substr(0,(s.size()-1)/2))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def normalized(s):
  indexes = {}
  def translated(ch):
    if ch not in indexes:
      indexes[ch] = len(indexes)
    return indexes[ch]

  return list(map(translated, s))


def main():
  s = input()
  t = input()

  print('Yes' if normalized(s) == normalized(t) else 'No')


if __name__ == '__main__':
  main()


Measured memory_bytes: 6832
//ITP1_7_C
#include<iostream>
using namespace std;

int main()
{
	int r,c,i,j,k=0;
	
	cin>>r>>c;
	
	int irc[101][101];
	
	for(i=0;i<r+1;i++){
		for(j=0;j<c+1;j++){
			irc[i][j]=0;
		}
	}
	
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			cin>>irc[i][j];
			irc[i][c]+=irc[i][j];
			irc[r][j]+=irc[i][j];
			irc[r][c]+=irc[i][j];
		}
	}
	
	for(i=0;i<r+1;i++){
		for(j=0,k=0;j<c+1;j++,k++){
			if(k!=0){
			cout<<" ";
			}
			cout<<irc[i][j];
		}
		cout<<endl;
	}
			
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define pi 3.14159265358979323846264338327950
typedef pair<int,int> pr;
#define N 1000002
int power(int x,int p)
{
   int temp=1;
   while(p>0)
   {
       if(p%2)
       {
           temp*=x;
           temp%=MOD;
           --p;
       }
       else
       {
           x*=x;
           x%=MOD;
           p/=2;
       }
   }
   return temp%MOD;
}
signed main()
{
    SPEED;
    int n,ans=0,p1=0,p2=0,p=0;
    cin>>n;
    set<pr> s;
    map<pr,int> m;
    int a[n],b[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i]>>b[i];
        if(a[i]==0 && b[i]==0)
            p++;
        else if(a[i]==0)
            p1++;
        else if(b[i]==0)
            p2++;
        else
        {
            int g=__gcd(a[i],b[i]);
            a[i]/=g;
            b[i]/=g;
            if(b[i]<0)
            {
                a[i]*=-1;
                b[i]*=-1;
            }
            m[{a[i],b[i]}]++;
        }
    }
    ans+=(power(2,p1)-1+power(2,p2));
    for(int i=0;i<n;++i)
    {
        if(a[i]==0 || b[i]==0 || m[{a[i],b[i]}]==0)
            continue;
        int chk=power(2,m[{a[i],b[i]}]);
        m[pr(a[i],b[i])]=0;
        if(a[i]<0)
        {
            a[i]*=-1;
            b[i]*=-1;
        }
        chk+=power(2,m[{-b[i],a[i]}])-1;
        chk%=MOD;
        m[pr(-b[i],a[i])]=0;
        ans*=chk;
        ans%=MOD;
    }
    cout<<(MOD+ans-1+p)%MOD;
}

Measured memory_bytes: 31728
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main(){
    string s; cin >> s;
    
    
    rep(i,3){
        if(s[i]==s[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout <<"Good" << endl;

        

}
 

 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e13;
 
int n;
long long dp[401][401];
int arr[405];
 
long long sum (int l, int r) {
	long long ans = 0;
	for (int i = l; i <= r; i++)
		ans += arr[i];
	return ans;
}
 
int main () {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R)
				dp[L][R] = 0;
			else {
				dp[L][R] = INF;
				for (int i = L; i <= R - 1; i++)
					dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum(L, R));
			}
		
		}
	}
	cout << dp[0][n - 1] ;
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int len = s.size();
  bool jud = true;
  for (int i=0; i<len; i++){
    if (i%2==0){ //奇数番め
      if (s[i]!='R' && s[i]!='U' && s[i]!='D') jud = false;
    }
    else{
      if (s[i]!='L' && s[i]!='U' && s[i]!='D') jud = false;
    }
  }
  if (jud == true) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3604
use std::f64::consts::PI;
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let a: f64 = sc.next();
    let b: f64 = sc.next();
    let x: f64 = sc.next();

    let mut ok: f64 = 0.;
    let mut ng: f64 = PI / 2.;

    for _ in 0..100 {
        let theta = (ok + ng) / 2.;

        let mass = if theta.tan() >= a / b {
            a * a * (b - a / theta.tan() / 2.)
        } else {
            a * b * b * theta.tan() / 2.
        };

        if mass <= x {
            ok = theta;
        } else {
            ng = theta;
        }
    }

    println!("{:.10}", 90. - ok / PI * 180.);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4604
<?php
$tmp = [];
while ($line = fgets(STDIN)) {
    $tmp[] = trim($line);
}

$n = $tmp[0];
$list = explode(' ', $tmp[1]);

$count = 0;
while (existsInt($list)) {
    $new_list = $list;
    foreach ($list as $key => $num) {
        $new_list[$key] = $num / 2;
    }
    $list = $new_list;
    $count++;
}

echo $count;

function existsInt(array $list)
{
    foreach ($list as $num) {
        if ($num % 2 !== 0)
            return false;
    }

    return true;
}

Measured memory_bytes: 4984
lst k = [(x, y, z) | x <- [1..k], y <- [1..k], z <- [1..k]]

solve :: [(Int, Int, Int)] -> [Int]
solve [] = []
solve ((x, y, z) : xs) = [gcd x (gcd y z)] ++ solve xs

main = do
    k <- readLn :: IO Int
    print $ sum (solve (lst k))


Measured memory_bytes: 6888
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k, ct;
	string s;

	cin >> n >> s;
	ct = 0;
	for (i = 0; i < n; i++) {
		for (j = i; (j < n) && (s[i] == s[j]); j++);
		ct++;
		i = j - 1;
	}
	cout << ct << "\n";

	return 0;
}


Measured memory_bytes: 1144
#include <cstdio>
#include <string>
struct Istream {
	Istream() {
#ifdef DEBUG
		freopen("input","r",stdin);
#endif
	}
	template <class T> 
	Istream &operator >>(T &x) {
		static char ch;static bool neg;
		for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
		for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
		x=neg?-x:x;
		return *this;
	}
}is;
struct Ostream {
	template <class T>
	Ostream &operator <<(T x) {
		x<0 && (putchar('-'),x=-x);
		static char stack[233];static int top;
		for(top=0;x;stack[++top]=x%10+'0',x/=10);
		for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
		return *this;
	}
	Ostream &operator <<(char ch) {
		putchar(ch);
		return *this;
	}
}os;
#include <string>
#include <iostream>
#include <algorithm>
template <class T> inline
bool chkmn(T &a,T const &b) {
	return a>b?a=b,1:0;
}
bool Valid(std::string s) {
	for(size_t i=1;i<s.length();++i) {
		if(s[i-1]!=s[i]) {
			return 0;
		}
	}
	return 1;
}
int Calc(std::string s,char c) {
	int res=0;
	while(!Valid(s)) {
		++res;
		std::string news;
		for(size_t i=0;i<s.length()-1;++i) {
			if(s[i]==c || s[i+1]==c) {
				news+=c;
			} else {
				news+=s[i];
			}
		}
		s=news;
	}
	return res;
}
int main() {
	std::string s;
	std::cin>>s;
	int Ans=s.length();
	for(int i=0;i<26;++i) {
		chkmn(Ans,Calc(s,i+'a'));
	}
	os<<Ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using namespace std;
using pii = pair<int,int>;

int n,L;
pii dp[100001];
vector<int> adj[100001];

void dfs(int cur,int p) {
    dp[cur] = pii(0,0);
    multiset<int> tr;
    for(auto &it:adj[cur]) if(it!=p) {
        dfs(it,cur);
        dp[cur].fi += dp[it].fi;
        if(dp[it].se+1==L) dp[cur].fi++;
        else tr.insert(dp[it].se+1);
    }

    int mx=0;
    while(sz(tr)>1) {
        auto it=prev(tr.end());
        auto jt=tr.upper_bound(L-*it);
        if(jt==tr.begin()) {
            if(mx) dp[cur].fi++;
            mx = *it;
        } else {
            jt--;
            if(jt==it) jt--;
            dp[cur].fi++;
            tr.erase(jt);
        }
        tr.erase(it);
    }
    if(!tr.empty()) {
        if(mx) dp[cur].fi++;
        mx = *tr.begin();
    }
    dp[cur].se = mx;
}

int main() {
    scanf("%d",&n);
    for(int i=1,u,v;i<n;i++) {
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(n==2) {
        puts("1 1");
        return 0;
    }

    L=n;

    int root=0;
    for(int i=1;i<=n;i++) if(sz(adj[i])>1) {
        root=i;
        break;
    }
    dfs(root,0);
    
    int dt=dp[root].first+(dp[root].se>0);
    int lo=0,up=n;
    while(up-lo>1) {
        L=(lo+up)>>1;
        dfs(root,0);
        if(dp[root].fi+(dp[root].se>0) > dt) lo=L;
        else up=L;
    }
    printf("%d %d\n",dt,up);

    return 0;
}


Measured memory_bytes: 17152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		String ansa = "";
		String ansb = "";
		
		for(int i=0;i<a;i++) {
			ansa += "1";
			ansb += "0";
		}
		for(int i=a;i<w;i++) {
			ansa += "0";
			ansb += "1";
		}
		
		for(int i=0; i<b;i++) {
			System.out.println(ansa);
		}
		for(int i=b;i<h;i++) {
			System.out.println(ansb);
		}
		
	}

}


Measured memory_bytes: 32980
l = list(input())
n = len(l)

for bit in range(1<<(n-1)):
    f = l[0]
    sum = int(l[0])

    for i in range(n-1):
        if bit & (1<<i):
            f = f + "+" + l[i+1]
            sum = sum + int(l[i+1])
        else:
            f = f + "-" + l[i+1]
            sum = sum - int(l[i+1])
    
    if sum == 7:
        print(f+"=7")
        exit()
        


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n,i,j;
    cin>>n;
    vector<ll> a(n);
    map<ll,ll> mp;
    for(i=0;i<n;i++) cin>>a[i], mp[a[i]]++;
    vector<ll> v;
    for(auto p: mp)
    {
        ll tmp;
        if(p.second%2) tmp=1;
        else tmp=2;
        v.pb(tmp);
    }
    sort(all(v));
    reverse(all(v));
    if(v[0]==1) 
    {
       cout<<accumulate(all(v),0); 
    }
    else
    {
        ll sum = accumulate(all(v),0);
        ll c = 0;
        i = 0;
        while(i<sz(v) && v[i]==2) {c++;i++;}
        ll pairs = c/2;
        ll rem =  c%2;
        sum-=(2*pairs);
        if(rem) sum-=2;
        cout<<sum;
    }
}


Measured memory_bytes: 8444
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
sat=0
for i,name in enumerate(A):
  sat+=B[name-1]
  if i>=1:
      if name==A[i-1]+1:
          sat+=C[name-2]
print(sat)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector< pair< pair<string, int>, int> > vp;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    vp.resize(n);
    for(int i=0; i<n; i++){
        cin >> vp[i].first.first;
        cin >> vp[i].first.second;
        vp[i].first.second *= - 1;
        vp[i].second = i;
    }
    sort(vp.begin(), vp.end());
    for(int i=0; i<vp.size(); i++)
        cout << vp[i].second + 1 <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>

int main(void)
{
  int n;

  while (true) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    std::vector<int> cards_A, cards_B;
    for (int i = 0; i < n; i++) {
      int card_A, card_B;
      std::cin >> card_A >> card_B;
      cards_A.push_back(card_A);
      cards_B.push_back(card_B);
    }
    int score_A = 0;
    int score_B = 0;
    for (int i = 0; i < n; i++) {
      if (cards_A.at(i) == cards_B.at(i)) {
        score_A += cards_A.at(i);
        score_B += cards_B.at(i);
      }
      else {
        int score_sum = cards_A.at(i) + cards_B.at(i);
        if (cards_A.at(i) > cards_B.at(i)) score_A += score_sum;
        if (cards_A.at(i) < cards_B.at(i)) score_B += score_sum;
      }
    }
    std::cout << score_A << " " << score_B << std::endl;
  }

  return 0;
}

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

using namespace std;

               
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef LOCAL
	assert(freopen("input.txt", "r", stdin));
	#endif

	string s = "ACGT";

	auto ok = [&](char c) {
		for (auto x : s) {
			if (x == c) {
				return true;
			}
		}
		return false;	
	};
	string x;
	cin >> x;
	int ans = 0;
	for (int i = 0; i < (int)x.size(); i++) {
		for (int j = i; j < (int)x.size(); j++) {
			bool can = true;
			for (int k = i; k <= j; k++) {
				if (!ok(x[k])) can = false;
			}
			if (can) {
				ans = max(ans, j - i + 1);
			}
		}
	}
	cout << ans;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

int n;
int x,y,z;
ll a[111111],b[111111],c[111111];
ll l[111111],r[111111];
ll perm[111111];
ll suma;

bool sorter(const ll& i,const ll& j){
  return b[i]+c[j]>b[j]+c[i];
}

int main(){
	cin.sync_with_stdio(false);
  cin>>x>>y>>z;
  n=x+y+z;
  rep(i,n){
    cin>>a[i]>>b[i]>>c[i];
    suma+=a[i];
    b[i]-=a[i];
    c[i]-=a[i];
    perm[i]=i;
  }
  sort(perm,perm+n,sorter);
  
  rep(i,n+1)l[i]=-INF;
  rep(i,n+1)r[i]=-INF;

  ll s=0;
  multiset<ll> st;
  rep(i,n){
    ll j=perm[i];
    s+=b[j];
    st.insert(b[j]);
    if(st.size()>y){
      auto it=st.begin();
      s-=*it;
      st.erase(it);
    }
    if(st.size()==y){
      l[i+1]=s;
    }
  }

  s=0;
  st.clear();
  for(ll i=n-1;i>=0;i--){
    ll j=perm[i];
    s+=c[j];
    st.insert(c[j]);
    if(st.size()>z){
      auto it=st.begin();
      s-=*it;
      st.erase(it);
    }
    if(st.size()==z){
      r[n-i]=s;
    }
  }

  ll res=-INF;
  rep(i,n+1)maxch(res,suma+l[i]+r[n-i]);

  cout<<res<<endl;

	return 0;
}


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

Int n, m, q;
Int a[51], b[51], c[51], d[51];
Int res = 0;

void dfs(vector<Int> v) {
    if ((Int)v.size() == n + 1) {
        Int sum = 0;
        for (Int i = 0; i < (Int)q; i++) {
            if (v[b[i]] - v[a[i]] == c[i]) {
                sum += d[i];
            }
        }
        res = max(res, sum);
        return;
    }
    for (Int i = v.back(); i <= (Int)m; i++) {
        v.push_back(i);
        dfs(v);
        v.pop_back();
    }
}

int main() {
    cin >> n >> m >> q;
    for (Int i = 0; i < (Int)q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<Int> v;
    v.push_back(1);
    dfs(v);
    print(res);
    return 0;
}

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

int main() {
  long long h, n;
  cin >> h >> n;
  long long sum = 0;
  rep(i, n) {
    long long a;
    cin >> a;
    sum += a;
  }
  if (h <= sum)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(12)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int X=abs(sx-tx);
    int Y=abs(sy-ty);
    REP(i,X) putchar('R');
    REP(i,Y) putchar('U');
    REP(i,X) putchar('L');
    REP(i,Y) putchar('D');
    putchar('D');
    REP(i,X+1) putchar('R');
    REP(i,Y+1) putchar('U');
    putchar('L');
    putchar('U');
    REP(i,X+1) putchar('L');
    REP(i,Y+1) putchar('D');
    putchar('R');
    putchar('\n');
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6 + 5;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int ans=0,x=0;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&x);
        if(x>=k)ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!
typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<"#x:"<<x<<endl
#define ERR2(x,y) cout<<"#x:"<<x<<" "<<"#y:"<<y<<endl;
#define ERR3(x,y,z) cout<<"#x:"<<x<<" "<<"#y:"<<y<<" "<<"#z:"<<z<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()

ll solve(ll n, vector<ll>&A){
	vector<ll>pref(n+1,0);
	for(int i=n-1;i>=0;i--){
		pref[i] = (pref[i+1] + A[i])%MOD;
	}
	ll s = 0;
	for(int i=0;i<n-1;i++){
		s = (s+(A[i]*pref[i+1])%MOD)%MOD;
	}
	return s;
}

int main()
{
	ll n;
	cin>>n;
	vector<ll>A(n);
	FOR(i,0,n){
		cin>>A[i];
	}
	cout<<solve(n,A)<<endl;
	return 0;
}


Measured memory_bytes: 6416
from collections import Counter
def foods():
    n,m=map(int,input().split())
    ka=[[int(i) for i in input().split()] for i in range(n)]
    food=[i for i in range(1,m+1)]
    ans=[]
    for i in ka:
        hito=i[1:]
        ans+=[x for x,y in Counter(hito+food).items() if y>1]
    ansa=[x for x,y in Counter(ans).items() if y==n]
    return ansa

print(len(foods()))

Measured memory_bytes: 3444
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    r = N%10
    if r in [2,4,5,7,9]:
        print('hon')
    elif r in [0,1,6,8]:
        print('pon')
    else:
        print('bon')

main()


Measured memory_bytes: 26844
while 1:
    n=int(input())
    if not n:break
    l=[]
    m=0
    for _ in range(n):
        s=input()
        a=s[0]
        for i,t in enumerate(s[:-1]):
            if any(t==c for c in'aiueo'):
                a+=s[i+1]
        m=max(m,len(a))
        l.append(a)
    for k in range(m+1):
        if len(set(t[:k]for t in l))==n:
            print(k)
            break
    else:
        print(-1)


Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n, l; cin >> n >> l;
  int mini, minz = 300;
  for(int i = 0; i < n; i++){
    int z;
    if(l + i >= 0) z = l + i;
    else z = -(l + i);
    if(z < minz){
      mini = i;
      minz = z;
    }
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
    if(i == mini) continue;
    sum += l + i;
  }
  cout << sum << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  var i = 0
  val sb = StringBuilder.newBuilder
  for(x <- io.Source.stdin.getLines() if x != "0") {
    i += 1
    // sb.append("Case ").append(i).append(": ")
    //   .append(x).append('\n')
    // sb.append(s"Case $i : $x\n")
    sb.append("Case " + i + ": " + x + "\n")
  }
  print(sb.toString())
}


Measured memory_bytes: 52292
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
string s;
cin>>s;
if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
{
cout<<"Bad";
}
else
{
cout<<"Good";
}
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
set < ll> primes;
 
int n,m;

bool isvalid(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}
int dx[]={0,0,1,-1,-1,1,1,-1};
int dy[]={1,-1,0,0,-1,1,-1,1};
void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i)
		prime[i]=true;
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(ll p=2; p<=n; p++) 
       if (prime[p]) 
		primes.insert(p);  
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
        return gcd(b % a, a); 
} 
ll powermod(ll x, ll y){
    if(y==0)
    return 1;
        
    if(y%2==0)
    return (powermod(x,y/2)*powermod(x,y/2))%mod;
    else
    return (((powermod(x,y/2)*powermod(x,y/2))%mod)*x)%mod;
}

void solve()
{
   int n;
   cin>>n;
   
   if(n%1000==0)cout<<"0\n";
   else cout<<1000-n%1000;
    
}

 

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}

Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>

const int moo=1000000007;
int n,m,i,j,x[200005],y[200005],l[200005],r[200005];
int p[200005],tp[200005];
int ch;

inline int getint()
{
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int i1=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())i1=((i1<<3)+(i1<<1)+ch-'0');
	return i1;
}

inline void sortx(int l0,int r0)
{
	if(l0>=r0)return;
	int i1,i2,i3=((l0+r0)>>1),i4=l0-1;
	sortx(l0,i3);
	sortx(i2=(i3+1),r0);
	for(i1=l0;i1<=i3;++i1)
	{
		while((i2<=r0)&&(x[i2]<x[i1]))
		{
			++i4;
			p[i4]=x[i2];tp[i4]=y[i2];
			++i2;
		}
		++i4;
		p[i4]=x[i1];tp[i4]=y[i1];
	}
	for(i1=l0;i1<=i4;++i1)
	{
		x[i1]=p[i1];
		y[i1]=tp[i1];
	}
	return;
}
inline void sortp(int l0,int r0)
{
	if(l0>=r0)return;
	int i1,i2,i3=((l0+r0)>>1),i4=l0-1;
	sortp(l0,i3);
	sortp(i2=(i3+1),r0);
	for(i1=l0;i1<=i3;++i1)
	{
		while((i2<=r0)&&(y[p[i2]]<y[p[i1]]))
		{
			tp[++i4]=p[i2];
			++i2;
		}
		tp[++i4]=p[i1];
	}
	for(i1=l0;i1<=i4;++i1)p[i1]=tp[i1];
	return;
}
int maxl[200005];
int dp[200005],sdp[200005];

int main()
{
	n=getint();
	for(i=1;i<=n;++i)
	{
		x[i]=getint();y[i]=getint();
	}
	sortx(1,n);
	for(i=1;i<=n;++i)p[i]=i;
	sortp(1,n);
	j=-12345678;
	for(i=1;i<=n;++i)
	{
		if(p[i]>j)j=p[i];
		r[p[i]]=j;
	}
	j=12345678;
	for(i=n;i>=1;--i)
	{
		if(p[i]<j)j=p[i];
		l[p[i]]=j;
	}
	memset(maxl,0,sizeof(maxl));
	for(i=1;i<=n;++i)if(l[i]>maxl[r[i]])maxl[r[i]]=l[i];
	for(i=1;i<=n;++i)if(maxl[i]<maxl[i-1])maxl[i]=maxl[i-1];
	memset(sdp,0,sizeof(sdp));
	dp[0]=sdp[0]=1;
	for(i=1;i<=n;++i)
	{
		if(maxl[i-1]>0)
		{
			dp[i]=sdp[i-1]-sdp[maxl[i-1]-1];
			if(dp[i]<0)dp[i]+=moo;
		}else dp[i]=sdp[i-1];
		sdp[i]=sdp[i-1]+dp[i];
		if(sdp[i]>=moo)sdp[i]-=moo;
	}
	if(maxl[n]<=0)puts("???");
	i=sdp[n]-sdp[maxl[n]-1];
	if(i<0)i+=moo;
	printf("%d\n",i);
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,p;
    cin>>a>>p;
    p+=a*3;
    cout<<p/2<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
e = [a[i] for i in range(n) if i % 2 == 1]
o = [a[i] for i in range(n) if i % 2 == 0]
if (n % 2 == 1):
    ans = o[::-1] + e
else:
    ans = e[::-1] + o
ans = [str(i) for i in ans]
ans = " ".join(ans)
print(ans)

Measured memory_bytes: 31428
n, m = map(int, input().split())
a = input().split()

max = 0
for ai in a:
  max += int(ai)

ss = max / (4 * m)

rs = 0
for ai in a:
  if float(ai) >= ss:
  	rs += 1

if rs >= m:
  print('Yes')
else:
  print('No')

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int a, b; cin >> a >> b;
	if (a > 9 || b > 9) {
		cout << -1 << endl;
		return 0;
	}
	else cout << a * b << endl;
}


Measured memory_bytes: 256