akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll n,m,v,p;
vector<ll>a;
bool check(ll ii){
  if(a[ii]+m<a[n-p])return 0;
  if(v<=p&&a[ii]+m>=a[n-p]){
    return 1;
  }
  ll vv=v-p;
  ll S=0;
  rep(i,n-p+1){
    if(i==ii)continue;
    S+=min(m,m+a[ii]-a[i]);
  }
  return S>=m*vv;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>m>>v>>p;
  a.resize(n);
  rep(i,n)cin>>a[i];
  ll ng=-1,ok=n;
  sort(all(a));
  while(ok-ng>1){
    ll mi=(ok+ng)/2;
    if(check(mi))ok=mi;
    else ng=mi;
  }
  cout<<n-ok<<endl;



  return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

typedef long long ll;

const int M = 30;

int main() {
    ll p3[M];
    for (int i = 0; i < M; i++) {
        p3[i] = i == 0 ? 1 : 3 * p3[i-1];
    }

    int q;
    cin >> q;

    while (q--) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;

        ll ans = 0;
        for (int i = M - 1; i >= 0; i--) {
            ll a3 = a / p3[i], b3 = b / p3[i];
            ll c3 = c / p3[i], d3 = d / p3[i];

            if (a3 != c3 && b3 != d3) {
                ans += abs(a - c) + abs(b - d);
                break;
            }

            if (a3 == c3 && b3 == d3) {
                a = a % p3[i], b = b % p3[i];
                c = c % p3[i], d = d % p3[i];
                continue;
            }

            if (b3 == d3) {
                swap(a, b);
                swap(c, d);
                swap(a3, b3);
                swap(c3, d3);
            }

            if (b > d) {
                swap(a, c);
                swap(b, d);
                swap(a3, c3);
                swap(b3, d3);
            }

            if ((a3 == 1 || a3 == 4) && (b3 == 0 || d3 == 5)) {
                ans += d - b;

                ll dis1 = a % p3[i] + c % p3[i];
                ll dis2 = 2 * p3[i] - 2 - dis1;
                ans += min(dis1, dis2) + 2;

                break;
            }

            if (i == 0) {
                ans += abs(a - c) + abs(b - d);
                break;
            }

            a -= a3 * p3[i], c -= c3 * p3[i];
            a3 = c3 = 0;
            b -= b3 * p3[i], d -= b3 * p3[i];
            d3 -= b3, b3 = 0;

            if (d3 <= 1) {
                continue;
            }

            ll d9 = d / p3[i-1];
            ans += (d9 - 5) * p3[i-1];
            d -= (d9 - 5) * p3[i-1];
            d9 = 5;
            d3 = 1;
        }


        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        String s1 = sc.next().toUpperCase();
        String s2 = sc.next().toUpperCase();
        String s3 = sc.next().toUpperCase();
        String[] s = {s1,s2,s3};
      
        for(int i = 0; i < 3; i++){
          System.out.print(s[i].charAt(0));
        }
      
        System.out.println();
	}

}

Measured memory_bytes: 35588
#include<bits/stdc++.h>
#define ll long long
using namespace std;
stack<char>s;
void work(ll x)
{
    if(x<=26)
    {
        s.push(x+'a'-1);
        while(!s.empty())
        {
            putchar(s.top());
            s.pop();
        }
        return;
    }
    if(x%26!=0)
    {
        s.push(x%26 + 'a'-1);
        work(x/26);
    }
    else
    {
        s.push('z');
        work(x/26-1);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    work(n);
    return 0;
}



Measured memory_bytes: 3676
#include <iostream>
#include <map>
#include <cstdlib>
using namespace std;


int main()
{
    int a;
    int b;
    cin >> a >> b;
    
    // 大き方をa
    if(a < b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    // a×bの結果を保存しておく
    // a,bの値域が10の5乗なので最大で10の10乗となる
    // 格納できるよう64bit変数にすること
    
    // bが32bitのまま計算すると正しい結果が出ない。なぜ…
    // [long = int × int]と[long = int × long]で結果が異なる
    long long int longb = b;
    long long int x = a * longb;

    // ユークリッドの互除法で最小公約数(gcd)を計算
    // 1. aをbで割った余りをrとする
    // 2. aにbを、bにrを代入
    // 3. rが0になるまで繰り返す
    // 4. r=0の時、bが最小公約数
    int r = a%b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    //cout << x << "," << a << "," << b << "," << r << endl;
    
    // 最小公約数を使って最小公倍数(lcm)を求める
    // lcm(a.b ) = a * n / gcm(a,b) 
    long long int ans = x / b;
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()

print(180 * (n - 2))

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

struct rest
{
	char name[10];
	int score;
	int index;
}r[200];

bool operator < (rest a, rest b)
{
	int s = strcmp(a.name, b.name);
	if (s == 0)
		return a.score > b.score;
	else
	{
		return s < 0;
	}

}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> r[i].name >> r[i].score;
		r[i].index = i;
	}
	
	sort(r, r + n);

	for (int i = 0; i < n; i++)
	{
		cout << r[i].index + 1 <<endl;
	}
	

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, X) = readLine()!!.split(" ").map(String::toInt)
    val L = readLine()!!.split(" ").map(String::toInt)

    val D = IntArray(N + 1)
    D[0] = 0
    var sum = 1
    for (i in 1..N) {
        D[i] = D[i - 1] + L[i - 1]
        if (D[i] <= X) {
            sum++
        }
    }
    println(sum)
}

Measured memory_bytes: 37820
#include <iostream>                                                                              
using namespace std;                                                                             
                                                                                                 
int main() {                                                                                     
  int n, k;                                                                                      
                                                                                                 
  cin >> n >> k;                                                                                 
                                                                                                 
  if (n - k + 1 < 0) {                                                                           
    cout << 0 << endl;                                                                           
    return 0;                                                                                    
  }                                                                                              
                                                                                                 
  cout << n - k + 1 << endl;                                                                     
                                                                                                 
  return 0;                                                                                      
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
  string ans = "No";
  int d, t, s;
  cin >> d >> t >> s;
  if(d-t*s <= 0)ans="Yes";
  cout << ans << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

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

int main()
{
	priority_queue<int>q;
long long n,k,h,sum=0;
cin>>n>>k;
if(k>=n){cout<<0<<endl;}
else{
for(int i=0;i<n;i++){
	cin>>h;
	q.push(h);
	sum+=h;
}
while(k--){
sum-=q.top();
q.pop();
}
cout<<sum;}


	return 0;
}


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

int main () {
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H') cout << 'H' << endl;
    else cout << 'D' << endl;
  }
  else {
    if (b == 'H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
}
  

Measured memory_bytes: 256
N = gets.to_i
D = gets.chomp.split(" ").map(&:to_i)

countD = Array.new(D.max + 1, 0)

D.each{|d|
  countD[d] += 1
}

if D[0] != 0 then
  puts 0
elsif D[1...N].include?(0)
  puts 0
else
  ans = 1
  for i in 1...countD.length do
    ans *= countD[i-1] ** countD[i]
  end
  puts ans % 998244353
end


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

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

    //(K-1)*区間の数+1が全体の区間が覆える範囲
    //(K-1)*区間数+1>=N、区間数>=(N-1)/(K-1)を満たす区間数
    //求める

    int ans = ((N-2)/(K-1))+1; //切り上げ

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		Dice dice1 = new Dice();
		Dice dice2 = new Dice();

		dice1.createDice(in.readLine().split(" "));
		dice2.createDice(in.readLine().split(" "));

		dice1.check(dice2);
	}
}

class Dice {
	public int on, tw, th, fo, fi, si;

	public Dice() {

	}

	public Dice(int on, int tw, int th, int fo, int fi, int si) {
		this.on = on;
		this.tw = tw;
		this.th = th;
		this.fo = fo;
		this.fi = fi;
		this.si = si;
	}

	void createDice(String[] data) {
		int[] diceNums = new int[6];
		for (int i = 0; i < data.length; i++) {
			diceNums[i] = Integer.parseInt(data[i]);
		}
		on = diceNums[0];
		tw = diceNums[1];
		th = diceNums[2];
		fo = diceNums[3];
		fi = diceNums[4];
		si = diceNums[5];
	}

	void check(Dice otherDice) {
		boolean result = false;
		int checkTimes = 0;
		while (checkTimes <= 29) {
			result = this.match(otherDice);
			if (result)
				break;
			checkTimes++;
			if (checkTimes == 5 || checkTimes == 15 || checkTimes == 25) {
				otherDice.north();
			} else if (checkTimes == 10 || checkTimes == 20) {
				otherDice.west();
			} else {
				otherDice.rightSpin();
			}
		}

		if (result) {
			System.out.println("Yes"); // ?????´??????
		} else {
			System.out.println("No"); // ?????´?????????
		}
	}

	boolean match(Dice otherDice) {
		if (this.on == otherDice.on && this.tw == otherDice.tw
				&& this.th == otherDice.th && this.fo == otherDice.fo
				&& this.fi == otherDice.fi && this.si == otherDice.si) {
			return true;
		}
		return false;
	}

	void rightSpin() {
		int temp = tw;
		tw = fo;
		fo = fi;
		fi = th;
		th = temp;
	}

	public void north() {
		int temp = on;
		on = tw;
		tw = si;
		si = fi;
		fi = temp;
	}

	public void east() {
		int temp = on;
		on = fo;
		fo = si;
		si = th;
		th = temp;
	}

	public void west() {
		int temp = on;
		on = th;
		th = si;
		si = fo;
		fo = temp;
	}

	public void south() {
		int temp = on;
		on = fi;
		fi = si;
		si = tw;
		tw = temp;
	}
}

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

int main(){
  int n; cin>>n;
  long long s=0;
  long long sum[n+1];
  sum[0]=0;
  for(int i=0;i<n;i++){
    long long a; cin>>a;
    s+=a;
    sum[i+1]=sum[i]+a;
  }
  long long ans=abs(s-2*sum[1]);
  for(int i=2;i<n+1;i++){
    ans=min(ans,abs(s-2*sum[i]));
  }
  cout<<ans<<endl;
}


/* これは半分の地点を決めきっており、互いに値に近づくという動きが取れていない
int main(){
  int n; cin>>n;
  long long num[n];
  long long sum=0,ans=0;
  for(int i=0;i<n;i++){
    cin>>num[i];
    sum+=num[i];
  }if(sum%2==1){
    sum++; ans++;
  }
  long long sum2=0,half=sum/2,half2=(sum/2)-1;
  int log;
  for(int i=0;i<n;i++){
    sum2+=num[i];
    if(sum2==half){
      cout<<ans<<endl;
      return 0;
    }else if(sum2>half){
      log=i;
    }
  }long long sum3=0;
  int log2;
  for(int i=0;i<n;i++){
    sum3+=num[i];
    if(sum3==half2){
      cout<<ans<<endl;
      return 0;
    }else if(sum3>half2){
      log2=i;
    }
  }
  long long rest=sum-sum2,rest2=sum-sum3;
  long long pre=min(abs(sum2-half)+abs(rest-half),abs(sum2-num[log]-half)+abs(rest+num[log]-half))+ans;
  long long pre2=min(abs(sum3-half2)+abs(rest2-half2),abs(sum3-num[log2]-half2)+abs(rest2+num[log2]-half2))+ans;
  cout<<min(pre,pre2)<<endl;
}
*/

Measured memory_bytes: 1792
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int> > jobs(m);

  //二次元配列に詰め込む
  for(int i=0; i<n; i++){
    int a,b;
    cin >> a >> b;
    if(a>m) continue;
    jobs[m-a].push_back(b);
  }

  priority_queue<int> q;
  ll ans = 0;
  for(int i = m-1; i>= 0; i--){
    //pythonでいうfor i in hoge みたいなimage
    for(int j =0; j < jobs[i].size() ; j++){
      int b = jobs[i][j];
      q.push(b);
    }

    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,m,n,cnt=0;
    double x,y,sum=0;
    cin >> n >> m;
    double a[n];
    y=1.00/(4.00*(m*1.00));
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
    }
    y*=sum;
    for(i=0;i<n;i++)
    {
        if(a[i] >= y)++cnt;
    }
    if(cnt >= m)cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string str;
  cin >> str;
  int ans = 0;

  int n = str.size();

  for (int i = 0; i < n; ) {
    char c = str[i];
    int cnt = 0;
    while (i < n && str[i] == c) {
      i++;
      cnt++;
    }
    if (c == 'R')
      ans = max(ans, cnt);
  }  

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

int main(){

    int i;
    string s;
    int N;
    ll m, a, r, c, h;
    ll D[5];

    int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
    int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
    int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

    scanf("%d", &N);
    m = 0;
    a = 0;
    r = 0;
    c = 0;
    h = 0;
    for(i=0; i<N; i++){
        cin >> s;
        if(s[0] == 'M') m++;
        if(s[0] == 'A') a++;
        if(s[0] == 'R') r++;
        if(s[0] == 'C') c++;
        if(s[0] == 'H') h++;
    }
    D[0] = m;
    D[1] = a;
    D[2] = r;
    D[3] = c;
    D[4] = h;

    ll res = 0;
    for(i=0; i<10; i++){
        res += D[P[i]] * D[Q[i]] * D[R[i]];
    }

    printf("%lld\n", res);

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define fst first
#define snd second

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

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  
  int n;
  double t, a;
  cin >> n >> t >> a;
  double least = 10000.0;
  int at = 0;
  for(int i = 0; i < n; i++){
    double h;
    cin >> h;
    if(least > fabs(a - (t - h * 0.006))){
      least = fabs(a - (t - h * 0.006));
      at = i;
    }
  }
  cout << at + 1 << "\n";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


int main(void)
{
    IOS
    int n; cin >> n;
    constexpr ll INF = 1LL << 50;
    vector<map<int,ll>> v(n,map<int,ll>());
    REP(i,n-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        v[a][b] = c;
        v[b][a] = c;
    }
    int q, k;
    cin >> q >> k;
    k--;
    vector<pii> xy;
    REP(i,q){
        int x,y; cin >> x >> y;
        x--;y--;
        xy.push_back(make_pair(x,y));
    }

    // ver bfs
    vector<ll> d(n,INF);
    vector<bool> visit(n);
    d[k] = 0;
    visit[k] =true;
    vector<int> bfs;
    for(auto item:v[k]) {
        d[item.first] = item.second;
        bfs.push_back(item.first);
    }
    while(!bfs.empty()) {
        vector<int> tmp;
        swap(tmp,bfs);
        for(auto from:tmp) {
            for(auto to:v[from]) {
                if (d[to.first] > d[from] + to.second) {
                    d[to.first] = d[from] + to.second;
                    bfs.push_back(to.first);
                }
            }
        }
    }

    REP(i,q) {
        cout << d[xy[i].first] + d[xy[i].second] << endl;
    }

    return 0;
}

Measured memory_bytes: 20724
#include<algorithm>
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=400+10,M=1e5+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n,m,e[M][2];
bitset<N> a[N]; 

int main()
{
	n=rd(),m=rd();
	for(int i=1;i<=m;++i) e[i][0]=rd(),e[i][1]=rd();
	for(int i=1;i<=n;++i)
	{
		a[i][i]=1;
		for(int j=m;j;--j)
		{
			int x=e[j][0],y=e[j][1];
			if(a[i][x]&a[i][y]) {a[i][i]=0;break;}
			if(a[i][x]) a[i][y]=1;
			else if(a[i][y]) a[i][x]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		if(!a[i][i]) continue;
		for(int j=i+1;j<=n;++j)
		{
			if(!a[j][j]) continue;
			ans+=(bool)!(a[i]&a[j]).count();
		}
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//整数の入力
      	int a = sc.nextInt();
     	int b = sc.nextInt();
        if((a * b) % 2 == 0){
        	System.out.print("Even");
        }else{
        	System.out.print("Odd");
        }
	}
}

Measured memory_bytes: 21716
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]

INF = 10 ** 9

def dfs(n, a, b, c):
    if n == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return INF
    else:
        p = dfs(n+1, a, b, c)
        q = dfs(n+1, a+l[n], b, c) + 10
        r = dfs(n+1, a, b+l[n], c) + 10
        s = dfs(n+1, a, b, c+l[n]) + 10
        return min(p, q, r, s)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int solve(const ll &e) {
  ll m = 1e6;
  for (ll z = 0; z <= e; z++) {
    ll zzz = pow(z, 3);
    if (zzz > e) break;
    for (ll y = 0; y <= e - zzz; y++) {
      ll yy = pow(y, 2);
      if (yy > e - zzz) break;
      int x = e - zzz - yy;
      m = min(m, x + y + z);
    }
  }
  return m;
}

int main() {
  ll e;
  while (cin >> e && e > 0) {
    cout << solve(e) << endl;
  }
  return 0;
}



Measured memory_bytes: 3228
# A - Weather Prediction

# ある町の天気は晴れ→曇り→雨→晴れ…と周期的に変化する
# 入力された今日の天気から明日の天気を出力する


S = str(input())

if S == 'Sunny':
    print('Cloudy')

elif S == 'Cloudy':
    print('Rainy')

elif S == 'Rainy':
    print('Sunny')


Measured memory_bytes: 8896
#include<iostream>
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	if(a+b>c+d)cout<<"Left"<<endl;
	else if(a+b<c+d)cout<<"Right"<<endl;
	else cout<<"Balanced"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;

class Main{
    public static void main (String[ ] args) throws Exception{
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        String str = br.readLine();

        String[] strarr = str.split(" ");
        int[] intarr = new int[3];

        for(int i=0; i<3; i++)
        {
            intarr[i] = Integer.parseInt(strarr[i]);
        }
        
        Arrays.sort(intarr);
        
        System.out.println(intarr[0] + " " + intarr[1] + " " + intarr[2]);
    }
}

Measured memory_bytes: 24332
from collections import defaultdict, deque

d = defaultdict(list)
N = int(input())
l = []

for _ in range(N-1):
    a, b = map(int, input().split())
    a-=1
    b-=1
    d[a].append(b)
    d[b].append(a)
    l.append((a,b))

parent = [0]*(N)
used = [False]*(N)
used[0]=True

q = deque()
q.append(0)
res = {}

max_n = 0
while q:
    p = q.popleft()
    color_num = 0
    for i in d[p]:
        if used[i]:continue

        used[i] = True
        
        color_num += 1
        # 根の値とかぶらない限り、1から小さい順に埋めるとよい
        if color_num == parent[p]:
            color_num+=1 # 根の値とかぶらないようにする
        parent[i] = color_num
        res[(p,i)] = color_num
        q.append(i)
    max_n = max(max_n, color_num)

print(max_n)
for i in l:
    print(res[i])

Measured memory_bytes: 54600
a,b,k = map(int,input().split())
if a >= k:
    ans1 = a-k
    ans2 = b 
if a < k:
    if (a+b) <= k:
        ans1 = 0
        ans2 = 0
    else:
        ans1 = 0
        ans2 = b-(k-a)
print(ans1,ans2)

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

// int solve(vector<int>arr, int pos, int k, vector<int>&dp) {
// 	int n = arr.size();
// 	if (pos == n - 1) {
// 		return 0;
// 	}
// 	if (dp[pos] != -1) {
// 		return dp[pos];
// 	}

// 	int res = INT_MAX;

// 	for (int i = 1; i <= k; i++) {
// 		if (pos + i <= n - 1) {
// 			res = min(res, abs(arr[pos] - arr[i + pos]) + solve(arr, pos + i, k, dp));
// 		}
// 	}
// 	return dp[pos] = res;
// }

int solve(vector<int>arr, int k) {

	vector<int>dp;
	dp.resize(arr.size());
	int n = arr.size();
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++) {
		int res = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0) {
				res = min(res, abs(arr[i] - arr[i - j]) + dp[i - j]);
			}
		}

		dp[i] = res;

	}
	return dp[n - 1];
}
in main() {

	// cout << "hoho";
	int n, k;
	cin >> n >> k;

	vector<int>arr;
	arr.resize(n);
	vector<int>dp;
	dp.resize(n);
	for (int i = 0; i < n; i++)
		dp[i] = -1;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	cout << solve(arr, k);

}



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

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

const int MAXN = 105;
const int BASE1 = 3137;
const int BASE2 = 10007;
const int MOD = 998244353;

char in[MAXN];
map <pii, pii> dp;
vector <int> divs[MAXN];

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
	return x;
}

inline int mul(int x, int y) {
	return (ll)x * y % MOD;
}

pii hsh(string s) {
	pii res = {0, 0};
	for (auto it : s)
		res = {add(mul(BASE1, res.first), it + 1), add(mul(BASE2, res.second), it + 1)};
	return res;
}

int f(string);
int calc(string);

int calc(string s) {
	int N = s.size();
	if (N == 1)
		return s[0] - '0' + 1;
	int res = 0;
	for (auto it : divs[N]) {
		string tmp = "";
		for (int i = 0; i < it; i++) {
			char bit = '1';
			for (int j = 0; j < N / it; j++)
				if (s[j * it + i] == '0') {
					bit = '0';
					break;
				}
			tmp += bit;
		}
		res = add(res, f(tmp));
	}
	return res;		
}

int f(string s) {
	pii &ref = dp[hsh(s)];
	if (ref.first)
		return ref.second;
	ref.first = 1;
	if (s.empty())
		return ref.second = 1;
	int N = s.size();
	for (int i = 0; i < N; i++)
		ref.second = add(ref.second, mul(calc(s.substr(0, i + 1)), f(s.substr(i + 1, N - i - 1))));
	return ref.second;
}

void init() {
	for (int i = 1; i < MAXN; i++)
		for (int j = 2 * i; j < MAXN; j += i)
			divs[j].push_back(i);
}

int main() {
	init();
	scanf("%s", in);
	printf("%d\n", f(in));
	return 0;
}

Measured memory_bytes: 3072
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int flag[105];
int vis[105];

int main(){
	int n = 0,m = 0;
	int X = 0,Y = 0;
	int z;
	int ax = 0,ay = 0;
	int x[105],y[105];
	int cot1 = 0,cot2 = 0,cot3 = 0;
	scanf("%d %d %d %d",&n,&m,&X,&Y);
	for(int i = 1; i <= n; i++) scanf("%d",&x[i]);
	for(int i = 1; i <= m; i++) scanf("%d",&y[i]);
	if(X >= Y) printf("War\n");
	else{
		sort(x + 1, x + n + 1);
		sort(y + 1, y + m + 1);
	//	printf("%d %d\n",x[1],y[m]);
		for(int i = X + 1; i <= Y; i++){
			if(x[n] < i && y[1] >= i) cot1++;
			//printf("%d %d\n",i,cot1);
		}
		if(cot1) printf("No War\n");
		else printf("War\n");
	}
}



Measured memory_bytes: 128
import java.util.concurrent.LinkedBlockingQueue

fun main() {
    val n = readLine()?.toInt() ?: return

    data class Edge(val i: Int, val from: Int, val to: Int)

    val vertex = Array(n + 1) { false }
    val edge = Array(n - 1) { 0 }
    val edges = hashMapOf<Int, MutableList<Edge>>()
    repeat(n - 1) {
        val (a, b) = readLine()?.split(" ")?.map(String::toInt) ?: return
        edges.getOrPut(a) { mutableListOf() }.add(Edge(it, a, b))
        edges.getOrPut(b) { mutableListOf() }.add(Edge(it, b, a))
    }
    val root = edges.maxBy { it.value.size }!!
    val colorCount = root.value.size
    val queue = LinkedBlockingQueue<Pair<Int, Int>>()
    queue.add(Pair(root.key, 0))
    while (queue.isNotEmpty()) {
        val (i, connectedColor) = queue.poll()
        vertex[i] = true
        val v = edges[i]!!
        val r = 1.until(v.size + 1).toMutableList()
        r.remove(connectedColor)
        v.forEach {
            if (edge[it.i] == 0) {
                val c = r.first()
                edge[it.i] = c
                r.removeAt(0)
                if (!vertex[it.to]) {
                    queue.add(Pair(it.to, c))
                }
                if (!vertex[it.from]) {
                    queue.add(Pair(it.from, c))
                }
            }
        }
    }
    buildString {
        appendln(colorCount)
        append(edge.joinToString(separator = "\n"))
    }.let {
        println(it.trimIndent())
    }
}


Measured memory_bytes: 91776
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key)
{
    NodePointer cur = nil->next;
    while( cur != nil && cur->key != key ) cur = cur->next;
    return cur;
}

void init()
{
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    NodePointer cur = nil->next;
    int isf = 1;
    while(1)
    {
        if ( cur == nil ) break;
        if ( isf == 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}

void deleteNode(NodePointer t)
{
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast()
{
    NodePointer t = nil->prev;
    if ( t == nil ) return;
    deleteNode(t);
}

void delete(int key)
{
    NodePointer t = listSearch(key);
    if ( t == nil ) return;
    deleteNode(t);
}


void insert(int key){
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ )
    {
        scanf("%s%d", com, &key);
        if ( com[0] == 'i' ) 
        {
            insert(key); np++; 
            size++;
        }
        else if ( com[0] == 'd' ) 
        {
            if (strlen(com) > 6)
            {
                if ( com[6] == 'F' ) deleteFirst();
                else if ( com[6] == 'L' ) deleteLast();
            } 
            else 
            {
                delete(key); 
                nd++; 
            }
            size--;
        }
    }

    printList();
    
    return 0;
}


Measured memory_bytes: 32956
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l[100],count=0,i,j,k;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>l[i];
	for(i=0;i<n-2;i++)
	for(j=i+1;j<n-1;j++)
	for(k=j+1;k<n;k++)
	if(l[i]!=l[k]&&l[j]!=l[k]&&l[i]!=l[j])
	{
		if(l[i]+l[j]>l[k]&&l[i]+l[k]>l[j]&&l[k]+l[j]>l[i])
		count++;
	}
	cout<<count;
}

Measured memory_bytes: 3520
<?php
$str = trim(fgets(STDIN));
$moji = "";
$answer = "";
for($i = 0; $i < strlen($str); $i++) {
  if(preg_match('/[ ,\.]/',$str[$i])){
      if( strlen($moji) < 3 || strlen($moji) > 6 ){
        //pass
      }else{
        $answer .= $moji . " ";
      }
      $moji = "";
  }else{
      $moji .= $str[$i];
  }
}
print(trim($answer) . "\n");

Measured memory_bytes: 15260
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), k = scanner.nextInt();
			Set<Integer> set = new HashSet<>();
			IntStream.range(a, Math.min(a + k, b)).forEach(set::add);
			IntStream.rangeClosed(Math.max(b - k + 1, a), b).forEach(set::add);
			set.stream().sorted().forEach(System.out::println);
		}
	}
}


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

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> l(N);

    for (int i = 0; i < N; i++)
        cin >> l.at(i);
    
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());

    int sum = 0;
    for (int i = 0; i < K; i++)
        sum += l.at(i);

    cout << sum << endl;
}

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

using ll = long long;

const int MAXN = 2.1e5;

int N;
ll L;
ll X[MAXN];
ll pref[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> L >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	ll ans = 0;
	for (int z = 0; z < 2; z++) {
		pref[0] = 0;
		for (int i = 0; i < N; i++) {
			pref[i+1] = pref[i] + X[i];
		}
		for (int i = 0; i < N; i++) {
			// we walk forward to i, then start to alternate
			ll cnd = 0;
			if ((N - i) % 2 == 0) {
				// we take an even number of steps
				// last step is backwards
				int mid = (N+i) / 2;
				cnd += ((pref[mid] - pref[i]) + (L * (mid - i))) * 2 - (pref[N] - pref[mid]) * 2 + X[mid] - L;
			} else {
				// last step if forwards
				int mid = (N+i+1) / 2;
				// (mid - i) * 2 - (N - mid) * 2 - 2
				cnd += ((pref[mid] - pref[i]) + (L * (mid - i))) * 2 - (pref[N] - pref[mid]) * 2 - (X[mid-1]+L) - L;
			}

			ans = max(ans, cnd);
		}

		for (int i = 0; i < N; i++) {
			X[i] = L - X[i];
		}
		reverse(X, X + N);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3456
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            arr[i] = new int[]{i, sc.nextInt()};
        }

        Arrays.sort(arr, (a1, a2) -> a2[1] - a1[1]);
//        debug(arr);

        long[][] dp = new long[n + 1][n + 1];
        for (long[] x : dp) {
            Arrays.fill(x, -1);
        }
        dp[0][0] = 0;
        // dp[i][j] ... 左からi人、右からj人並べた場合のうれしさの最大値

        for (int k = 0; k < n; k++) {
            int x = arr[k][0];
            long a = (long) arr[k][1];
            for (int i = 0; i <= k; i++) {
                int j = k - i;
                if (dp[i][j] == -1) continue;
                dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + a * Math.abs(x - i));
                dp[i][j + 1] = Math.max(dp[i][j + 1], dp[i][j] + a * Math.abs((n - 1 - j) - x));
            }
//            debug(dp);
        }
//        debug(dp);
        long ans = -1;
        for (int i = 0; i <= n; i++) {
            ans = Math.max(ans, dp[i][n - i]);
        }
        System.out.println(ans);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 84264
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let n:i64 = read();
    println!("{}", n/3);
}


Measured memory_bytes: 4352
//---------- Begin IO utilities ----------
#[macro_use]
#[allow(dead_code, unused_macros)]
mod io {
    // Thanks to https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
    macro_rules! input {
        ($($r:tt)*) => {
            let s = {
                use std::io::Read;
                let mut s = String::new();
                std::io::stdin().read_to_string(&mut s).unwrap();
                s
            };
            let mut iter = s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
    }
    macro_rules! input_inner {
        ($iter:expr) => {};
        ($iter:expr, ) => {};
        ($iter:expr, $var:tt : $t:tt $($r:tt)*) => {
            let $var = read_value!($iter, $t);
            input_inner!{$iter $($r)*}
        };
    }
    macro_rules! read_value {
        ($iter:expr, ( $($t:tt),* )) => {
            ( $(read_value!($iter, $t)),* )
        };
        ($iter:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        };
        ($iter:expr, chars) => {
            read_value!($iter, String).chars().collect::<Vec<char>>()
        };
        ($iter:expr, usize1) => {
            read_value!($iter, usize) - 1
        };
        ($iter:expr, $t:ty) => {
            $iter.next().unwrap().parse::<$t>().expect("Parse error")
        };
    }

    macro_rules! p {
        ($v:expr) => {
            println!("{}", $v);
        };
        ($v:expr, $($t:expr),*) => {
            print!("{}", $v);
            ($(print!(" {}", $t)),*);
            println!();
        }
    }

    macro_rules! ps {
        ($v:expr) => {
            println!("{}", $v.iter().collect::<String>());
        };
        ($v:expr, $($t:expr),*) => {
            print!("{}", $v.iter().collect::<String>());
            ($(print!(" {}", $t.iter().collect::<String>())),*);
            println!();
        }
    }

    pub fn pv<T: std::string::ToString>(v: &[T], sep: &str) {
        let s = v.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep);
        println!("{}", s);
    }

    pub fn pvs(v: &[Vec<char>], sep:&str) {
        let s = v.iter().map(|e| e.iter().collect::<String>()).collect::<Vec<String>>().join(sep);
        println!("{}", s);
    }
}
//---------- End IO utilities ----------

//---------- Start solve ----------
#[allow(unused_imports)]
use io::*;
fn main() {
    input!{
        k: usize,
        a: usize,
        b: usize
    }
    for i in a..=b {
        if i % k == 0 {
            p!("OK");
            return;
        }
    }
    p!("NG");
}


Measured memory_bytes: 2084
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
char s[150];
int main()
{
    //freopen("in.txt","r",stdin);
	double a,b,h,m;
    cin>>a>>b>>h>>m;
    double pi=acos(-1);
    double anh=(h+m/60)/6*pi;
    double xh=a*cos(anh);
    double yh=a*sin(anh);
    double anm=m/60*2*pi;
    double xm=b*cos(anm);
    double ym=b*sin(anm);
    double dis=sqrt(pow(xm-xh,2)+pow(ym-yh,2));
    printf("%.17lf",dis);
    
 } 

Measured memory_bytes: 4132
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/


int prime[1000000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}


void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}


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

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair<long long,ll> &a , const pair<ll ,ll > &b){
    if(a.first == b.first)  return a.second < b.second;
    return a.first > b.first;

    return false;
}

void solve(){
    ll n;
    in(n);
    ll arr[n];
    ll sum = 0 ;
    f(i,n) in(arr[i]);

    sort(arr,arr+n);

    sum += arr[n-1];

    int temp = n-2;
    int i = 0,cur = n-2;
    while(temp--){
        sum += arr[cur];
        ++i;
        if(i >= 2){
            i = 0;
            --cur;
        }
    }

    out(sum);
}


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

    return 0;
}


Measured memory_bytes: 5256
import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val str = sc.next
  val cs = str.toCharArray.toList.zipWithIndex

  @tailrec
  def solve(cs: List[(Char, Int)]): (Int, Int) = cs match {
    case f :: _ :: t :: _ if f._1 == t._1 => (f._2 + 1, t._2 + 1)
    case f :: s :: _ if f._1 == s._1 => (f._2 + 1, s._2 + 1)
    case _ :: s :: rest => solve(s :: rest)
    case _ => (-1, -1)
  }
  val t = solve(cs)
  val ans = s"${t._1} ${t._2}"
  println(ans)
}


Measured memory_bytes: 42332
# input number
number = int(input())

# input coordinate
result = True
current_position = (0, 0, 0)
for i in range(number):
    t, x, y = map(int, input().split())
    
    if result:
        # calc move point
        move_point = (t - current_position[0])
        
        # calc distance
        distance = abs(x - current_position[1]) + abs(y - current_position[2])
        
        # check
        if (move_point < distance) or ((move_point - distance) % 2 != 0):
            result = False
        
        # update position
        current_position = (t, x, y)

if result:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
	string s;
	cin>>s;
	stack<char> q;
	for(int i=0;i<s.size();i++){
        if(s[i]=='1') q.push('1');
        else if(s[i]=='0') q.push('0');
        else{
            if(q.size()>0) q.pop();
        }
	}
	char a[25];
	int k=0;
	while(q.size()>0){
        a[k++]=q.top();
        q.pop();
	}
	for(int i=k-1;i>=0;i--)
        cout<<a[i];
    cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

cnt = 0

for i in range(0, n):
  for j in range(i+1, n):
    
    D = math.sqrt(sum((x[i][k] - x[j][k])**2 for k in range(d)))
    if D.is_integer() == True:
      cnt += 1

print(cnt)

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

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

using namespace std;

int main(){
	long long int n,m;
	cin >> n >> m;
	long long int x=0;
	x += (m*1900+100*(n-m))*pow(2,m);
	cout << x << endl;
}


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

int main(){
  int N;
  double A,T;
  cin>>N>>T>>A;
  double H[N];
  double dif[N];
  int ans=0;
  double difmax=1000;
  for (int i=0;i<N;i++){
    cin>>H[i];
    dif[i]=abs(A-T+H[i]*0.006);
    if(dif[i]<difmax){
      difmax=dif[i];
      ans=i;
    }
  }
  
  cout<<ans+1<<endl;
}

    
  

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

using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;

    vector<vector<int>> grid(h, vector<int>(w, 1));
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;

        for (int j = (a == 4 ? y : 0); j < (a == 3 ? y : h); j++) {
            for (int k = (a == 2 ? x : 0); k < (a == 1 ? x : w); k++) {
                grid[j][k] = 0;
            }
        }
    }

    int res = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            res += grid[i][j];
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <numeric>
#include <unordered_map>

using namespace std;
using ll = long long;

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

    string S;
    cin >> S;

    int K;
    cin >> K;

    char target = S[K-1];

    for (const auto& c : S) {
        if (c != target) {
            cout << "*";
        } else {
            cout << c;
        }
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256