akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let _ = scan!(sc; i64);
  let s = sc.get_line();
  let mut ans = std::usize::MAX;
  if s.chars().all(|c| c == '.') || s.chars().all(|c| c == '#') {
    println!("0");
    return;
  }
  let mut wr = s.chars().filter(|&c| c == '.').collect::<String>().len();
  let mut br = s.chars().filter(|&c| c == '#').collect::<String>().len();
  let wn = wr;
  let bn = br;
  let mut bl = 0;
  for c in s.chars() {
    match c {
      '.' => { wr -= 1; },
      '#' => { br -= 1; bl += 1; },
      _   => {}
    }
    ans = if ans < bl + wr { ans } else { bl + wr };
  }
  ans = if ans > wn { wn } else if ans > bn { bn } else { ans };
  println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int num = scanner.nextInt();
		final int point = scanner.nextInt();

		if (num >= point) {
			System.out.println(0);
			return;
		}

		final int[] points = new int[point];

		for (int i = 0; i < point; i++) {
			points[i] = scanner.nextInt();
		}

		int sum = 0;
		final int[] diffs = new int[point - 1];

		Arrays.sort(points);

		for (int i = 0; i < point - 1; i++) {
			final int diff = points[i + 1] - points[i];
			sum += diff;
			diffs[i] = diff;
		}

		Arrays.sort(diffs);

		int reducible = 0;

		for (int i = diffs.length - num + 1; i < diffs.length; i++) {
			reducible += diffs[i];
		}

		System.out.println(sum - reducible);
	}

}

Measured memory_bytes: 50108
# -*- coding: utf-8 -*-

N = int(input())

xyhn = []
for i in range(N):
    xyh = list(map(int, input().split()))
    xyhn.append(xyh)


ans_list = []
for xi in range(101):
    for yi in range(101):
        H_list = []
        for x,y,h in xyhn:
            if h > 0:
                H = h + abs(x - xi) + abs(y - yi)
                H_list.append(H)

        if min(H_list) == max(H_list):
            ans_list.append([xi,yi,H_list[0]])
            # print("%d %d %d"%(xi,yi,H_list[0]))
            # exit()

ans_list.sort(key=lambda x:x[2])
print("%d %d %d"%(ans_list[0][0],ans_list[0][1],ans_list[0][2]))


Measured memory_bytes: 4084
N = int(input())
S = [input() for i in range(N)]

ac, wa, tle, re = 0, 0, 0, 0
for i in range(len(S)):
    if S[i] == 'AC':
        ac = ac + 1
    elif S[i] == 'WA':
        wa = wa + 1
    elif S[i] == 'TLE':
        tle = tle + 1
    elif S[i] == 'RE':
        re = re + 1

print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))

Measured memory_bytes: 16204
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
	cin.sync_with_stdio(0);
	// cin.tie(0);

	ll n, m;
	cin >> n >> m;

	vector<list<ll>> jobs(m);
	FOR(i,0,n) {
		ll a, b;
		cin >> a >> b;
		if (a-1 < m) {
			jobs[a-1].pb(b);
		}
	}

	ll result = 0;
	list<ll> s_jobs;

	for(auto job : jobs) {
		if (!job.empty()) {
			job.sort();
			s_jobs.merge(job);
		}

		if (s_jobs.empty()) continue;

		result += s_jobs.back();
		s_jobs.pop_back();
	}

	cout << result << '\n';
}


Measured memory_bytes: 8064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; cin >> n;
    vector<ll> A(n);
    ll sum = 0;
    rep(i, n){
        cin >> A[i];
        sum += A[i];
    }
    ll res = 1e18, left = A[0];
    rep(i, n-1){
        chmin(res, abs(left - (sum-left)));
        left += A[i+1];
    }
    cout << res << ln;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N){
    return 0;
}

int main(){
    ll M1,D1; cin >> M1 >> D1;
    ll M2,D2; cin >> M2 >> D2;
    if(M2 == M1 + 1 && D2 == 1) pr(1);
    else pr(0);
}

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

using namespace std;
char bit_char[] = "01";

int main(){
    long long N;
    cin >> N;
    bool is_minus;
    if(is_minus = signbit(N)){
        N *= -1;
    }
    int max_bit = 0;
    for (int i = 0; i < sizeof(N)*8; ++i) {
        if(N>>i&1){
            if((i%2)^is_minus) {
                N += 0b10LL<<i;
            }
            max_bit = i;
        }
    }
    for (int i = max_bit; i >= 0; --i) {
        cout << bit_char[N>>i&1];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
//gcd(x, y) -> xとyの最大公約数
ll gcd(ll x, ll y){
    return y ? gcd(y, x % y) : x;
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int k; cin >> k;
   ll ans = 0;
   rep(a,k)rep(b,k)rep(c,k)ans+=gcd(gcd(a+1,b+1),c+1);
   cout << ans << endl;
}

Measured memory_bytes: 3612
# coding: utf-8
K, T = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = A[:]
tmp = 0
for i in range(T-1):
    minus = B[i]
    for j in range(i, T):
        A[j] -= minus
#     print(*A)
# print(*A)

ans = 0
for i in range(T):
    if A[i] > 0:
        ans += A[i] - 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;

void dfs (int i, vector<int> v[], long long int dp[], bool visited[]){
    visited[i] = true;

    for (int k = 0; k < v[i].size(); ++k)
    {
        if(!visited[v[i][k]]){
            dfs(v[i][k], v,dp,visited);
        }

        dp[i] = max(dp[i], 1+ dp[v[i][k]]);
    }

}



int main() {
int N,M, a, b;
cin >> N >> M;
vector<int> v[N+1];
bool visited[N+1];
long long int dp[N+1] = {0};
for (int i = 0; i < M; ++i)
{
    cin >> a >> b;
    v[a].push_back(b);
}
dp[0] = 0;

for (int i = 0; i < N+1; ++i)
{
    visited[i] = false;
}
for (int i = 1; i < N+1; ++i)
{
    if(!visited[i]){
        dfs(i, v, dp, visited);
    }
}

int mx = INT_MIN;

for (int i = 0; i < N+1; ++i)
{
    if(mx < dp[i]) mx = dp[i];
}

cout << mx << endl;
}

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

using namespace std;

int main() {
    int N, D;
    int x[100][100];
    
    cin >> N >> D;

    for (int i=0;i<N;i++) {
        for (int j=0;j<D;j++){
            cin >> x[i][j];
        }
    }

    double ans;
    int cnt = 0;

    for (int i=0;i<N;i++) {
        for (int k=i+1; k<N;k++) {
            int res = 0;
            for (int j=0;j<D;j++){
                res += pow(x[i][j] - x[k][j], 2);
            }
            ans = sqrt(res);
            if (ans == ceil(ans)) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char s[30];
  scanf("%s",&s);
  for(int i = 0;i < strlen(s) - 1;i++){
    for(int j = i + 1;j < strlen(s);j++){
      if(s[i] == s[j]){
        printf("no");
        return 0;
      }
    }
  }
  printf("yes");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
int main(){
    int K,A,B;
  cin>>K>>A>>B;

    if(A/K!=B/K || A%K==0 || B%K==0) cout<<"OK";
  	else cout<<"NG";
}


Measured memory_bytes: 3620
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const A = args[0].map(arg => parseInt(arg, 10)).sort((a, b) => a - b)
	let sum = 0
	sum += A[1] - A[0]
	sum += A[2] - A[1]
	console.log(sum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <cstdio>
#include <algorithm>
#define maxn 1000010
using namespace std;
char s[maxn];
struct node{
	int l,r;
}a[maxn];
int tot;
int cmp(node a,node b){
	return a.l-a.r>b.l-b.r;
}
int main(){
	int n,i,j,l,r,ln,rn;
	ln=rn=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		l=r=0;
		scanf("%s",s+1);
		for(j=1;s[j];j++){
			if(s[j]=='(')l++;
			else if(s[j]==')'){
				if(l)l--;
				else r++;
			}
		}
		if(l&&!r)ln+=l;
		else if(!l&&r)rn+=r;
		else if(l&&r) a[++tot]=(node){l,r};
	}
	sort(a+1,a+1+tot,cmp);
	for(i=1;i<=tot;i++)
		if(ln<a[i].r)return printf("No\n"),0;
		else ln-=a[i].r,ln+=a[i].l;
	if(ln!=rn)return printf("No\n"),0;
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  b, c, d, e, X, Y;
  //  double  c;
  long long  A[100003]={};
  int  B[100003]={};
  int  C[100003]={};

  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
  char s[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
//  int min=1000000;
  long long min=100000001;
  int len=0;
  int cnt=0;
  int num=0;
  double ans=1000;
  int max=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
//  scanf("%d%d", &a,&c);
//  cnt = strlen(t);
// printf("%d\n",a);
    scanf("%s", &s);
/*  
  for(i=0;i<a;i++){
//    printf("%lld ",A[i]);
    if(A[i]==1) {
      printf("1\n");
      return 0;
    }
  }    
*/
  
  a=(s[0]-'0')*10+s[1]-'0';
  b=(s[2]-'0')*10+s[3]-'0';
//  printf("%d %d\n", a,b);
  
  if (((0<a)&&(a<13)) && ((0<b)&&(b<13)))printf("AMBIGUOUS\n");
  else if((0<b)&&(b<13))printf("YYMM\n");
  else if((0<a)&&(a<13)) printf("MMYY\n");
  else printf("NA\n");
  //  //  if(flag==0)   printf("TLE\n");
//    if(max < cnt - max)  printf("Yes\n");
//    else  printf("No\n");
  
return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

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

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

int main(void) 
{
  string s;
  cin >> s;

  if (s.length() < 4 || s.substr(0, 4) != "YAKI")
    puts("No");
  else
    puts("Yes");

  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//lower_bound like o_set.find_by_order(val) strictly less then val
//upper_bound like o_set.order_of_key(MAX)– o_set.order_of_key(val)
//if u need multiset elements then use second parameter as time and think 
//typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MAX=2e5+5;
const ll MM=1e16;
const ll mod=998244353;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
//insert a element in vector at position i  vec.insert(vec.begin()+i,element)
//atmost 1e5 insertion allowed in 1 sec

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}

void solve()
{
    ll n,m,i,j,k,ans=0;
    cin>>n;
    vl v(n);
    fn(i,n)cin>>v[i];
    fn(i,n)
    {
        ll temp=v[i],cnt=0;
        W(i<n && temp>=v[i]){
            temp=v[i];
            i++;cnt++;
        }
        i--;
        
        ans=max(ans,cnt);
    }
    cout<<ans-1<<endl;
    
}

int main()
{
  boost;
  ll t=1;
//   cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3900
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	cin >> n;
	long long int a[n];
	long long sum=0;
	set <long long int> min;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	long long int  mae=0;
	if(n==2)
		cout << abs(a[1]-a[0]) << endl;
	else{
	for(int i=0;i<n-1;i++){
		mae+=a[i];
		min.insert(abs(mae-sum+mae));
	}
	cout << *min.begin() << endl;
	}
}

Measured memory_bytes: 11136
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=lambda x: x[0])

i = 0
count = 0
while count < K:
    if ab[i][1] >= K:
        ans = ab[i][0]
        break

    else:
        count += ab[i][1]
        ans = ab[i][0]
        i += 1

print(ans)


Measured memory_bytes: 29912
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(long long N, long long K, std::vector<long long> p) {
  long double max = 0;
  long double d = 0;
  vector<long double> exs(1001);

  rep(i, N) {
    if (exs[p[i]] == 0)
      exs[p[i]] = (long double)p[i] * (p[i] + 1) / 2 / p[i];
    d += exs[p[i]];
    if (i >= K)
      d -= exs[p[i - K]];
    if (max < d)
      max = d;
  }
  coutl << max << endl;
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> p(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&p[i]);
  }
  solve(N, K, std::move(p));
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
using namespace std;
#include<algorithm>
#include<set>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)

const int mod=1000000007;


int main(){
int n,k;
cin>>n>>k;
int ans=0;
while(n>0){
  n/=k;
  ans++;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3160
import java.util.Scanner;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.abs(x - a) < Math.abs(x - b) ? "A" : "B");
    }
}


Measured memory_bytes: 23764
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
static const int MAX_V = 100;
static const int INF = 1 << 17;

struct edge{int to, cap, cost, rev;};

int V, E, F;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, int cost){
  G[from].push_back((edge){to, cap, cost, G[to].size()});
  G[to].push_back((edge){from, 0, -cost, G[from].size() - 1});
}

int min_cost_flow(int s, int t, int f){
  int res = 0;
  while(f > 0){
    fill(dist, dist + V, INF);
    dist[s] = 0;
    bool update = true;
    while(update){
      update = false;
      for(int v = 0; v < V; v++){
	if(dist[v] == INF) continue;
	for(int i = 0; i < G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }

    if(dist[t] == INF){
      return -1;
    }

    int d = f;
    for(int v = t; v != s; v = prevv[v]){
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * dist[t];
    for(int v = t; v != s; v = prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int main(){
  scanf("%d %d %d", &V, &E, &F);
  for(int i = 0; i < E; i++){
    int u, v, c, d;
    scanf("%d %d %d %d", &u, &v, &c, &d);
    add_edge(u, v, c, d);
  }
  printf("%d\n", min_cost_flow(0, V - 1, F));
  return 0;
}

Measured memory_bytes: 2864
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),link[][]=new int[n][n];
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				link[i][j]=Integer.parseInt(in.next());
			}
		}
		
		int visit[]=new int[n],parent[]=new int[n],d[]=new int[n];
		List<Integer> G=new ArrayList<>();
		for(int i=0;i<n;i++) {
			parent[i]=-1; d[i]=Integer.MAX_VALUE;
		}
		d[0]=0;
		
		while(true) {
			int u=-1,min=Integer.MAX_VALUE;
			
			for(int i=0;i<n;i++) {
				if(visit[i]<2 && d[i]<min) {
					min=d[i];
					u=i;
				}
			}
			
			if(u==-1)break;
			visit[u]=2;
			
			for(int i=0;i<n;i++) {
				if(visit[i]<2 && link[u][i]>=0 && link[u][i]<d[i]) {
					d[i]=link[u][i];
					parent[i]=u;
					visit[i]=1;
				}
			}
		}
		
		int sum=0;
		for(int i=0;i<n;i++) {
//			System.out.print(d[i]+" ");
			if(d[i]!=Integer.MAX_VALUE)sum+=d[i];
		}
		System.out.println(sum);
	}

}



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

using namespace std;

int pos;
string str;

int number() {

  // sentou digit
  int ret = 0;
  
  while(isdigit(str[pos])) {
    ret *= 10;
    ret += str[pos]-'0';
    pos ++;
  }
  // saigo not digit
  return ret;
}

vector<int> rec() {
  
  pos ++;
  
  if(isdigit(str[pos])) {
    return vector<int>(1, number()/2+1);
  }
  
  if(str[pos] == '[') {
    vector<int> ret;
    while(str[pos] == '[') {
      vector<int> r = rec();
      pos ++;
      ret.push_back(r[0]);
    }
    
    sort(ret.begin(), ret.end());
    
    int sum = 0;
    for(int i=0; i<(int)ret.size()/2 + 1; i++) {
      sum += ret[i];
    }
    
    return vector<int>(1, sum);
  }
  pos ++;
  assert(false);
}

int main() {
  
  int Tc; cin >> Tc;
  
  for(int Tcnt=1; Tcnt<=Tc; Tcnt++) {
    cin >> str;
    pos = -1;
    vector<int> ret = rec();
    assert(ret.size() == 1);
    cout << ret[0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1276
#include<string>
#include<iostream>
#include<algorithm>

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

using namespace std;

bool match(char a,char b){
	if(a=='i' && b=='i') return true;
	if(a=='w' && b=='w') return true;
	if(a=='(' && b==')') return true;
	if(a==')' && b=='(') return true;
	if(a=='{' && b=='}') return true;
	if(a=='}' && b=='{') return true;
	if(a=='[' && b==']') return true;
	if(a==']' && b=='[') return true;
	return false;
}

bool isSymmetry(const string &s){
	int len=s.length();
	if(len%2==0) return false;
	rep(i,(len+1)/2) if(!match(s[i],s[len-i-1])) return false;
	return s.find("iwi")!=string::npos;
}

int main(){
	string s; cin>>s;
	int n=s.length();

	int ans=0;
	rep(S,1<<n){
		string t;
		rep(i,n) if(S&(1<<i)) t+=s[i];
		if(isSymmetry(t)) ans=max(ans,(int)t.length());
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 0
N=int(input())

l=0
r=N

print(l,flush=True)
bstate=input()

if bstate!="Vacant":
    while True:
        #c=int((l+r)/2)
        L=int((r-l)/2)
        if (L%2)==0:
            L-=1
        c=l+L
        c=max(l+1,c)
        c=min(r-1,c)
        #print(c,l,r)
        print(c,flush=True)
        state=input()
        if state=="Vacant":
            break

        if state!=bstate:
            l=c
        else:
            r=c

        bstate=state


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n;
struct Node
{
    int w,id;
}a[N];
int ot[N];
inline bool cp(Node x,Node y) { return x.w<y.w; }
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++) a[i].w=read(), a[i].id=i;
    sort(a+1,a+1+n,cp);
    for(ri int i=1;i<=n/2;i++) ot[a[i].id]=a[n/2+1].w;
    for(ri int i=n/2+1;i<=n;i++) ot[a[i].id]=a[n/2].w;
    for(ri int i=1;i<=n;i++) printf("%lld\n",ot[i]);
    return 0;
}

Measured memory_bytes: 8284
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char buf[20];char *p=buf;if(n<0)pcu('-'),n*=-1;
	if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

using V = vector<int>;

int main() {
	for (int n; (n = in())++;) {
		vector<V> d(n, V(n));
		auto loop = [n](auto f){for(int k = 1; k < n; k++) f(k);};
		int r = 0;
		loop([&](int y){
			 loop([&](int x) {
				  if (gcu() == '.')
					r = max(r, d[y][x] = min(min(d[y - 1][x - 1], d[y - 1][x]), d[y][x - 1]) + 1);});
			 gcu();});
		outl(r);
	}
}


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

int main() {
  int n,m,l;
  cin >> n >> m >>l;
  vector<vector<int> > A(n,vector<int>(m));
  vector<vector<int> > B(m,vector<int>(l));
  
  for(int i=0;i <n; i++){
    for(int j=0;j < m;j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for(int i=0;i <m; i++){
    for(int j=0;j < l;j++){
      cin >> B.at(i).at(j);
    }
  }
  
  for(int i=0;i <n;i++){
    for(int j=0; j < l;j++){
      long long sum=0;
      for(int k=0; k < m; k++){
        sum+=(A.at(i).at(k))*(B.at(k).at(j));
      }
      if(j!=l-1) cout << sum << " ";
      else cout << sum << endl;
    }
  }

}


Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B; cin >> A >> B;
    if(A * B %2 == 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

}


Measured memory_bytes: 256
#encoding: utf-8

n = int(input())
c = []
for i in range(n):
    c.append(int(input()))

dp = 1
prev = [0] * (max(c) + 1)
x = 0
for i in c:
    if x != i:
        dp += prev[i]
        prev[i] = dp
    x = i

print(dp % (10 ** 9 + 7))




Measured memory_bytes: 27560
def caesar(s, n):
    ns = []
    for ch in s:
        # A - Z
        if ('A' <= ch and ch <= 'Z'):
            ns.append(chr((ord(ch) - ord('A') + n) % 26 + ord('A')))
            # nの符号で向き変更
        # no change for other characters
        else:
            ns.append(ch)
    return "".join(ns)

N = int(input())
S = input()

print(caesar(S, N))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
vector<char> v;
int main ()
{
	char a;
	long long n; cin >> n;
	while(n > 0)
	{
		if (n % 26 == 0)
		{
			a = 122;
			n = (n / 26) - 1;
		}
		else
		{	
			a = (n % 26) + 96;
			n /= 26;
		}
		v.push_back(a);
	}
	reverse(v.begin(), v.end());
	for(int i = 0; i < v.size(); i++)
		cout << v[i];
	cout << '\n';
}

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

bool isprime[1000001];
std::vector<int> primes;

void sieve()
{
	std::fill( isprime + 2, isprime + 1000001, true );

	for( int i = 2; i <= 1000000; ++i )
	{
		if( isprime[i] )
		{
			primes.push_back( i );

			for( int j = i * 2; j <= 1000000; j += i )
				isprime[j] = false;
		}
	}
}

int main()
{
	sieve();

	int n;
	while( std::cin >> n, n )
	{
		int ans = 0;

		for( int i = 0; i != primes.size() && primes[i] <= n / 2; ++i )
			if( isprime[n - primes[i]] )
				++ans;

		std::cout << ans << std::endl;
	}

	return 0;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

typedef pair<int, int> Pair;
typedef vector<Pair> Path;

int K, X, Y;

Path revert(Path path, bool xRev, bool yRev, bool xySwap) {
  Path ret;
  for (Pair p : path) {
    if (xySwap) swap(p.first, p.second);
    if (yRev) p.second = -p.second;
    if (xRev) p.first = -p.first;
    ret.push_back(p);
  }
  return ret;
}

bool normal(int& Z) {
  if (Z < 0) {
    Z = -Z;
    return true;
  }
  return false;
}

void getPQ(int& p, int& q) {
  int s = (X+Y) % K;
  int r = s == 0 ? 0 : K - s;
  if (X + Y < K) {
    if (K % 2 != 0 && (X + Y) % 2 != 0) {
      p = K - (X + Y);
      q = (K + (X + Y)) / 2;
    }else {
      p = (r + K) / 2;
      q = 0;
    }
  }else {
    q = 0;
    if (r % 2 == 0)  p = r     / 2;
    else             p = (r+K) / 2;
  }
}

Path solve() {
  Path ret;
  int p, q; getPQ(p, q);
  int x = X + p;
  int y = Y + q;
  while (x >= K) {
    ret.emplace_back(K, 0);
    x -= K;
  }
  if (x > 0) {
    ret.emplace_back(x, K - x);
    y -= K - x;
  }
  while (y >= K) {
    ret.emplace_back(0, K);
    y -= K;
  }
  x = p;
  if (y > 0) {
    ret.emplace_back(-(K - y), y);
    x -= K - y;
  }
  if (x > 0 || q > 0) {
    ret.emplace_back(-x, -q);
  }
  return ret;
}

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  cin >> K >> X >> Y;
  
  if (K % 2 == 0 && (X+Y) % 2 != 0) {
    cout << "-1\n";
    return 0;
  }
  bool xRev = normal(X);
  bool yRev = normal(Y);
  bool xySwap = false;
  if (X > Y) {
    swap(X, Y);
    xySwap = true;
  }
  Path path = solve();
  Path answer = revert(path, xRev, yRev, xySwap);
  cout << answer.size() << endl;
  int x = 0;
  int y = 0;
  for (Pair p : answer) {
    x += p.first;
    y += p.second;
    cout << x << " " << y << "\n";
  }

  return 0;
}



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

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    ll l1=0,l2=0;
    int c1=0,c2=0;
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    rep(i,n){
        if(a[i]==a[i+1] && l1==0){
            l1=a[i];
            i++;
        }
        else if(a[i]==a[i+1] && l1!=0){
            l2=a[i];
            break;
        }
    }
    cout << l1*l2 << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  set<string> w;
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    w.insert(W[i]);
  }

  bool ans = (w.size() == N);

  for (int i = 0; i < N - 1; i++) {
    if (W[i].back() != W[i + 1].front()) {
      ans = false;
      break;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, sum;
int a[200005];
int main()
{
	while(~scanf("%d %d", &n, &m)){
		sum = 0;
		memset(a, 0, sizeof(a));
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", &a[i]);
			if(a[i] - a[i - 1] > m || a[i] - a[i - 1] == m)
				sum += m;
			else
				sum += a[i]-a[i-1];
		}
		sum += m;
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 1152
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
int dp[100006][13];
signed main() {
	string s; cin >> s;
	dp[0][0] = 1;
	rep(i, s.size()) {
		rep(j, 13) {
			if (s[i] == '?') {
				rep(k, 10) {
					dp[i + 1][(10 * j + k) % 13] += dp[i][j];
					dp[i + 1][(10 * j + k) % 13] %= mod;
				}
			}
			else {
				dp[i + 1][(10 * j + (s[i] - '0')) % 13] += dp[i][j];
				dp[i + 1][(10 * j + (s[i] - '0')) % 13] %= mod;
			}
		}
	}
	cout << dp[s.size()][5] << endl;
}

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

using namespace std;

typedef long long ll;

const int N = 105;

ll w[N], v[N];
vector <ll> g[4];
ll W;
ll ans = 0;

void go(ll nw, ll nsum, int d) {
  if(d == 4) {
    ans = max(ans, nsum);
    return;
  }
  ll cur = nw;
  ll sum = nsum;
  go(nw, nsum, d + 1);
  for(auto x : g[d]) {
    sum += x;
    cur += w[0] + d;
    if(cur > W) break;
    go(cur, sum, d + 1);
  }
  return;
}

int main() {
  int n; cin >> n;
  cin >> W;
  for(int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
    g[w[i] - w[0]].push_back(v[i]);
  }
  for(int i = 0; i < 4; i++) sort(g[i].rbegin(), g[i].rend());
  go(0, 0, 0);
  cout << ans << '\n';
}

Measured memory_bytes: 256
#ABC061C
N,K=map(int,input().split())
A={}
for n in range(N):
	a,b=map(int,input().split())
	A[a]=A.get(a,0)+b
for key in sorted(list(A.keys())):
	K-=A[key]
	if K<=0:
		print(key)
		break

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

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

    sort(a, a + n);
    int ans = 0;
    int maximum = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (maximum <= min(a[n - 1] - a[i], a[i]))
        {
            maximum = min(a[n - 1] - a[i], a[i]);
            ans = i;
        }
    }

    cout << a[n - 1] << " " << a[ans] << endl;
}


Measured memory_bytes: 640
class EmployeesManager
    @employees = Array.new
    def self.add_sales_employee(id, price, amount)
        employee = @employees.find{|employee| employee.id == id}
        if employee.nil? then
            employee = Employee.new(id)
            @employees.push(employee)
        end
        employee.add_sales(price, amount)
    end
    def self.achieved_employees(quota)
        achieved_employees = Array.new
        @employees.each do |employee|
            achieved_employees.push(employee) if employee.get_sales >= quota
        end
        achieved_employees
    end
    def self.reset
        @employees.clear
    end
end

class Employee
    attr_accessor :id
    @sales
    def initialize(id)
        self.id = id
        @sales = 0
    end
    def add_sales(price, amount)
        @sales += amount * price
    end
    def get_sales
        @sales
    end
end

def settlement
    quota = 1000000
    achieved_employees = EmployeesManager.achieved_employees(quota)
    unless achieved_employees.empty?
        achieved_employees.each do |employee|
            puts employee.id
        end
    else
        puts "NA"
    end
    EmployeesManager.reset
end

while true
    n = gets.chop
    if n == '0' then
        break
    end
    n.to_i.times do
        id, price, amount = gets.split(" ").map(&:to_i)
        EmployeesManager.add_sales_employee(id, price, amount)
    end
    settlement
end



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

using namespace std;

int main(void)
{
    int n,l;
    vector<string> s;

    cin>>n>>l;
    for(int i = 0;i < n;i++)
    {
	string temp;
	cin>>temp;

	s.push_back(temp);
    }

    sort(s.begin(),s.end());

    for(int i = 0;i < n;i++)
	cout<<s[i];

    cout<<endl;

    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

sushi_array = []

sushi_count = [-1] * N
sushi_kind = 0
for i in range(N):
    t, d = map(int, input().split())
    sushi_array.append([t - 1, d])
    if sushi_count[t - 1] == -1:
        sushi_count[t - 1] = 0
        sushi_kind += 1

sushi_array = sorted(sushi_array, key=lambda x: -x[1])
# print(sushi_array, sushi_kind)

now_kind = 0
kiso = 0
can_remove = []
for sushi in sushi_array[:K]:
    kiso += sushi[1]
    if sushi_count[sushi[0]] == 0:
        now_kind += 1
        sushi_count[sushi[0]] = 1
    else:
        can_remove.append(sushi[1])

    # print(sushi_count)
ans = kiso + now_kind * now_kind

add_index = K
remove_index = K - 1

# print(ans, kiso, now_kind)
now_kind += 1

for sushi in sushi_array[add_index:]:
    if len(can_remove) == 0 or now_kind > sushi_kind:
        break
    if sushi_count[sushi[0]] == 0:
        kiso += sushi[1] - can_remove.pop()
        sushi_count[sushi[0]] = 1
        # print(ans, kiso, now_kind)
        ans = max(ans, kiso + now_kind * now_kind)
        now_kind += 1
    else:
        continue

print(ans)

Measured memory_bytes: 61404
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

N=int(input())
A=list(map(int, input().split()))

A.sort(reverse=True)

if N == 2:
    print(A[0])
    sys.exit()

if N == 3:
    print(A[0]+A[1])
    sys.exit()

B = []
B.append(A[1])
B.append(A[2])
B.append(A[2])
ans = A[0]+A[1]

tmp = 0

for i in range(3,N):
    ans += B[tmp]
    tmp += 1
    B.append(A[i])
    B.append(A[i])

print(ans)





Measured memory_bytes: 124468
#include<iostream>
using namespace std;
long long int maximum(long long int a,long long int b)
{
   long long int c=a>b?a:b;
    return c;
}
main ()
{
     long long int a,b,c,d,sum1,sum2,sum3,sum4;
     long long int temp;
    cin>>a>>b>>c>>d;
    sum1=a*c;
    sum2=a*d;
    sum3=b*c;
    sum4=b*d;
    temp=maximum(sum1,sum2);
    temp=maximum(temp,sum3);
    temp=maximum(temp,sum4);
    cout<<temp<<endl;



}


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

int main() {
  int n, m; cin >> n >> m;
  priority_queue<ll> q;
  rep(i, n) {
    int a; cin >> a;
    q.push(a);
  }
  rep(i, m) {
    ll t = q.top(); q.pop();
    q.push(t / 2);
  }
  ll ans = 0;
  while (!q.empty()) {
    int t = q.top(); q.pop();
    ans += t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1528
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define en '\n'
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;

int main()
{
    godspeed
   // ll  t,n,m,x,i,j,k,l;
    string s;
    cin>>s;
    if(s[s.length()-1]=='s')
        cout<<s.substr(0,s.length()-1)<<"ses"<<en;
    else
    cout<<s<<"s"<<en;



    /*
    ll a[n],sum=0;
    for(i=0; i<n; i++)
        cin>>a[i];

    for(i=0; i<n-1; i++)
    for(j=i+1; j<n; j++)
   {
       sum+=mulmod(a[i],a[j],mod);
   }
   */


    return 0;
}






Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int a, b;
    cin >> a >> b;
    int flg = 0;
    if (a < b) { swap(a, b); flg = 1; }
    
    vector<pii> eu;
    eu.eb(a, b);
    while (1) {
        if (b == 0) break;
        int r = a % b;
        eu.eb(b, r);
        a = b; b = r;
    }
    // cerr << eu << endl;
    int g = eu.back().F;
    
    using t = tuple<int, int, int, int>;
    vector<t> ex;
    ex.eb(a, -1, 1, 0);
    ex.eb(b, -1, 0, 1);
    int c = 0;
    while(1) {
        int q, r, x, y;
        q = eu[c].F / eu[c].S; r = eu[c].F % eu[c].S;
        ++c;
        if (r == 0) break;
        
        int q1, r1, x1, y1;
        tie(q1, r1, x1, y1) = ex.back();
        ex.pop_back();
        
        int q2, r2, x2, y2;
        tie(q2, r2, x2, y2) = ex.back();
        ex.pop_back();
        
        x = x2 - q * x1;
        y = y2 - q * y1;
        ex.eb(q1, r1, x1, y1);
        ex.eb(q, r, x, y);
        // cerr << q << " " << r << " " << x << " " << y << endl;
    }
    
    int q, r, x, y;
    tie(q, r, x, y) = ex.back();
    if (flg) swap(x, y);
    cout << x << " " << y << endl;
}



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

#define chmax(x, y) (x = max(x, y))

int n, t, s;
int a[3000], b[3000];
int dp[3010];

int main()
{
	cin >> n >> t >> s;
	for (int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}

	for (int i = 0; i < n; i++){
		for (int j = t - b[i]; j >= 0; j--){
			if (j < s && s < j + b[i]) continue;
			chmax(dp[j + b[i]], dp[j] + a[i]);
		}
		for (int j = 0; j < t; j++){
			chmax(dp[j + 1], dp[j]);
		}
	}

	cout << dp[t] << endl;
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int r,c,tmp;
    scanf("%d %d",&r,&c);
    int sheet[r+1][c+1];
    for(int i=0;i<r;i++){
        tmp=0;
        for(int j=0;j<c;j++){
            scanf("%d",&sheet[i][j]);
            tmp+=sheet[i][j];
        }
        sheet[i][c]=tmp;
    }
    /**
    for(int i=0;i<r;i++){
        sheet[i][c]=0;
        for(int j=0;j<c;j++){
            sheet[i][c]+=sheet[i][j];
        }
    }**/
    for(int i=0;i<c+1;i++){
        sheet[r][i]=0;
        for(int j=0;j<r;j++){
            sheet[r][i]+=sheet[j][i];
        }
    }
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            if(j<c){
                printf("%d ",sheet[i][j]);
            }else{
                printf("%d\n",sheet[i][j]);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>

int main(){

    
    long a[10000],i,n,min,max,sum;
 	 
 	  scanf("%ld",&n);

 	 for(i=0;i < n;++i){
 	  scanf("%ld",&a[i]);
      }
  
      
      min=a[0];
      max=a[0];
      sum=a[0];
      
      for(i=1;i < n;++i){
 	   if(min>a[i]){
		   min=a[i];
	     }else if(max<a[i]){
		   max=a[i];
		 }
	    sum+=a[i];
 	   }  
 	  
 	  printf("%ld %ld %ld\n",min,max,sum);
    
	return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(){
	vector<int> graph[100];
	queue<int> que;
	int d[100];
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
		d[i] = -1;
	}
	d[0] = 0;
	que.push(0);
	while(!que.empty()){
		int num = que.front();
		que.pop();
		for(int i = 0;i < graph[num].size();i++){
			if(d[graph[num][i]] == -1) {
				d[graph[num][i]] = d[num] + 1;
				que.push(graph[num][i]);
			}
		}
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3144