akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


int main(void){
	int A, B, C, X ;
	fscanf(stdin, "%d\n%d\n%d\n%d", &A, &B, &C, &X ) ;

	int ways = 0 ;
	int a, b, c ;
	int max_a, max_b ;

	max_a = X / 500 ;
	if( max_a > A) {
		max_a = A ;
	}
	for( a = max_a ; a >= 0 ; a-- ) {
		max_b = ( X - 500 * a ) / 100 ;
		if( max_b > B ) {
			max_b = B ;
		}
		for( b = max_b ; b >= 0 ; b-- ) {
			c = ( X - 500 * a - 100 * b ) / 50 ;
			if( c > C ) {
				break ;
			}
			ways++ ;
		}
	}
	printf("%d", ways ) ;
	return 0 ;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n;
    cin >> n;
    vector<P> v(n);
    rep(i, n) {
        int x, l;
        cin >> x >> l;
        v[i].first = x + l;
        v[i].second = x - l;
    }
    sort(all(v));
    int ans = n;
    int r = v[0].first;
    repl(i, 1, n) {
        if(r > v[i].second) {
            --ans;
        }
        else r = v[i].first;
    }
    cout << ans << endl;
    return 0;
}


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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] b = new int[N];
        for (int i = 0; i < N; i++) {
            b[i] = sc.nextInt();
        }

        int[] ans = new int[N];
        for (int i = N-1; i >= 0; i--) {
            boolean delete = false;
            for (int j = i; j >= 0; j--) {
                if (b[j] == j+1) {
                    ans[i] = b[j];
                    delete = true;
                    while (j < i) {
                        b[j] = b[j+1];
                        j++;
                    }
                    break;
                }
            }
            if (!delete) {
                System.out.println(-1);
                return;
            }
        }

        for (int i = 0; i < N; i++) {
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;
import java.util.regex.Pattern;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    if(!scan.hasNextInt()){
    	System.out.print("1番目には数字を入力してください");
      	return;
    }
    int a = scan.nextInt();
    if(!scan.hasNext()){
    	System.out.print("2番目には文字列を入力してください");
      	return;
    }
    String s = scan.next();
    if(s.length()<1 || s.length()>10){
    	System.out.print("2番目に長さ1以上10以下の文字列です");
      	return;
    }
    if(!Pattern.matches("^[a-z]+$", s)){
    	System.out.print("2番目には英子文字です");
      	return;    	
    }
    if(a>=3200){
      System.out.println(s);
    }
    else{
      System.out.println("red");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace  std;
typedef long long int ll;
#define INF 1000000007
ll dp[100001];
ll  h[100001];
ll n;
ll fun(ll i)
{
	ll m1=INF,m2=INF;
	if(i>=n)
	return 0;
	if(dp[i]!=-1)
	return dp[i];
	
	if(i+1<=n)
	m1=abs(h[i]-h[i+1])+fun(i+1);
	if(i+2<=n)
	m2=abs(h[i]-h[i+2])+fun(i+2);
	return dp[i]=min(m1,m2);
}
int main()
{
	ll i;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(i=1;i<=n;i++)
	cin>>h[i];
	cout<<fun(1)<<endl;
	
}

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

typedef long long ll;

int n,mi;
vector<int> w;

int solve(){

    int ret = 0;
    vector<int> sub(w);
    sort(sub.begin(),sub.end());
    vector<int> cir(10001);
    vector<bool> bol(n);

    for(int i=0;i<n;i++){
        cir[sub[i]] = i;
        bol[i]=false;
    }
    for(int i=0;i<n;i++){
        int sum=0,sn=0;
        int loc=i;
        int mmi=1e9;

        for(;;){
            bol[loc]=true;
            sn++;
            mmi=min(w[loc],mmi);
            sum+=w[loc];
            loc=cir[w[loc]];
            if(bol[loc])break;
        }
        ret+=min(sum+(sn-2)*mmi,sum+mmi+mi*(sn+1));
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    mi = 1e9;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        mi = min(mi,a);
        w.push_back(a);
    }
    int ans = solve();
    cout << ans << endl;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  for (int i = 100; i <= n; ++i) {
    for (int j = 100; j <= 105; ++j) {
      if (i - j >= 0) dp[i] |= dp[i - j];
    }
  }
  kek(dp[n]);
  
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  char s[200001], t[200001];
  scanf("%s%s", &s, &t);

  int i, count=0;
  for(i=0; s[i]!='\0' ; i++){
      if(s[i]!=t[i])
        count++;
  }

  printf("%d\n", count);
  return 0;
}


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

using namespace std;

int isPrimeNumbers(int x){
  if(x==1){
    return 0;
  }else if(x==2){
    return 1;
  }else if((x%2)==0){
    return 0;
  }else{
    int y=pow(x,(1.0/2.0));
    for(int p=3;p<=y;p++){
      if(x%p==0)return 0;
    }
  }
  return 1;
}

int main(){
  int n;
  cin>>n;
  int x[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  int count=0;
  for(int i=0;i<n;i++){
    if(isPrimeNumbers(x[i])==1){
      count++;
      //cout<<isPrimeNumbers(x[i])<<endl<<x[i]<<endl;
    }else{
      continue;
    }
  }
  cout<<count<<endl;
  return 0;
  //std::cout << pow(9,(1.0/2.0))<< '\n';
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    ll n,m;
    cin>>n>>m;
    map<ll, ll> s;
    COMinit();
    ll ans = 1;
    for(ll i = 2;m>1&&i<=m;i++){
        //ll vv = s[i];
        ll cou = 0;
        while(m%i==0){
            //s[i]++;
            cou++;
            m/=i;
        }
        if(cou!=0){
            ans = (ans*COM(n-1+cou, cou))%MOD;
        }
    }

    /*for(auto i = s.begin();i!=s.end();i++){
        if(i->second==0)continue;
        debug("%d %d\n", i->first, i->second);
        ans = (ans*COM(n-1+i->second, i->second))%MOD;
    }*/
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

	int lparen = 0, rparen = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '(') {
			lparen++;
		} else {
			if (lparen > 0) {
				lparen--;
			} else {
				rparen++;
			}
		}
	}

	for (int i = 0; i < rparen; i++) {
		cout << "(";
	}

	cout << S;

	for (int i = 0; i < lparen; i++) {
		cout << ")";
	}

	cout << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int n; cin >> n;
  if(n%2==0) cout << n << endl;
  else cout << 2*n << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
	int flag=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(flag==0&&s[i]=='C'){
			flag++;
			continue;
		}
		if(flag==1&&s[i]=='F'){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	lli n;
	vector<pair<lli,lli>> v;
	map<pair<lli,lli>,lli> ans;

	cin>>n;
	REP(i,0,n){
		lli x,y;
		cin>>x>>y;
		v.push_back(make_pair(x,y));
	}
	sort(v.begin(),v.end());

	/*pqを決定する、50C2なので充分間に合う*/
	REP(i,0,n){
		lli nowX = v[i].first;
		lli nowY = v[i].second;
		REP(j,i+1,n){
			lli nextX = v[j].first;
			lli nextY = v[j].second;
			lli p = nextX - nowX;
			lli q = nextY - nowY;
			ans[make_pair(p,q)]++;
		}
	}
	/*pqに従ってコストを計算する*/

	lli maxCnt=0;
	for(auto e:ans){
		maxCnt = max(maxCnt,e.second);
	}

	cout<<n-maxCnt<<endl;


	return 0;
}

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

int main(){
    int N, M;  cin >> N >> M;
    vector<int> A(N+1,0);
    for(int i=1; i<=N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end()); 

    vector<pair<int,int>> P(M);
    for(int i=0; i<M; i++){
        cin >> P[i].first >> P[i].second;
    }
    sort(P.begin(), P.end(), [](const pair<int,int> &a, const pair<int,int> &b){
        return a.second > b.second;
    });

    int n = 0;
    for(int i=0; i<M; i++){
        int B = P[i].first;
        int C = P[i].second;
        while(B>0 && n+1<=N && A[n+1]<C){
            A[n+1] = C;
            n++;
            B--;
        }
    }

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

#define int ll

const int maxn = 2e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}




main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s; cin>>s;
    int na=0, nbc=0; 
    int n = s.length();
    ll re = 0;
    REP(i,n){
    	nbc=0;
    	while (i<n && s[i]=='A') {
    		i++; na++;
    	}
    	while (i<n-1&&s[i]=='B'&&s[i+1]=='C'){
    		i+=2; nbc++;
    	}
    	
    	re+=na*nbc;
    	if (s[i]!='A') na=0;
    	else na++;
    }
    cout<<re<<endl;

}

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

int main(){
  string S;
  cin >> S;
  
  int N = (int)S.size();
  
  int ans = 0;
  //aとbのminを２倍する
  int a = 0;
  int b = 0;
  
  
  for(int i = 0; i < N; i++){
    if(S.at(i) == '0')a++;
    else b++;
  }
  
  cout << 2 * min(a,b) << endl;
  
  
  
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll a,b,c;cin>>a>>b>>c;
  if(a+b+c<=21) cout<<"win"<<endl;
  else cout<<"bust"<<endl;
}

Measured memory_bytes: 256
import math
import itertools

N = int(input())
position = [list(map(int, input().split())) for _ in range(N)]
town = list(range(N))
distance =list2 = [[0 for i in range(N)] for j in range(N)]
average = 0

for i in range(N):
  for j in range(N):
    distance[i][j] = math.sqrt((position[i][0] - position[j][0])**2 
                               + (position[i][1] - position[j][1])**2)

for order in itertools.permutations(town, N):
  for i in range(N-1):
    average += distance[order[i]][order[i+1]]
average /= math.factorial(N)

print(average)

Measured memory_bytes: 9148
#include <iostream>
#include <algorithm>
int main() {
    long long n;
    std::cin >> n;
    long long a[5];
    for (auto &x: a) std::cin >> x;
    long long b = *std::min_element(&a[0], &a[5]);
    long long ans = (n + b - 1) / b + 4;
    std::cout << ans;
}


Measured memory_bytes: 256
using System;
class main
{
    static void Main(string[] args)
    {
        while (true)
        {
            string s = Console.ReadLine();

            if (s != null)
            {
                string[] t = s.Split(' ');
                double[] u = new double[6];

                for (int i = 0; i < t.Length; ++i)
                {
                    u[i] = double.Parse(t[i]);
                }

                double y = ((u[2] * u[3]) - (u[5] * u[0])) / ((u[1] * u[3]) - (u[4] * u[0]));
                double x = (u[2] - (y * u[1])) / u[0];

                Console.WriteLine(string.Format("{0:F3} {1:F3}", x, y));
            }
            if (s == null)
            {
                break;
            }
            //Console.ReadKey();
        }
    }
}

Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> H;

int main()
{
    cin >> N >> M;
    H = vector<int>(N + 1);
    H.at(0) = 0;
    for (int i = 1; i < N + 1; i++)
    {
        cin >> H.at(i);
    }

    vector<int> A(M);
    vector<int> B(M);
    for (int i = 0; i < M; i++)
    {
        cin >> A.at(i) >> B.at(i);
    }

    vector<vector<int>> dict(N + 1);
    for (int i = 0; i < M; i++)
    {
        int a = A.at(i);
        int b = B.at(i);
        dict.at(a).push_back(b);
        dict.at(b).push_back(a);
    }

    int cnt = 0;
    for (int i = 1; i < N + 1; i++)
    {
        int h = H.at(i);
        vector<int> routes = dict.at(i);

        bool good = true;
        for (int r : routes)
        {
            if (h <= H.at(r))
            {
                good = false;
                break;
            }
        }

        if (good)
        {
            cnt++;
        }
    }

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

Measured memory_bytes: 9616
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;

typedef long long ll;

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

int main(){

   string S, T;

   cin >> S >> T;

   cout << T << S;

    return 0;

}

Measured memory_bytes: 256
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

k = int(input())
a,b  = readInts()

for i in range(a,b+1):
	if i%k==0:
		print("OK")
		exit()

print("NG")

Measured memory_bytes: 9376
import java.util.Scanner;
  
class Main{
  public static void main(String[] arg){
    String input;
    StringBuffer output = new StringBuffer();
 
    Scanner in = new Scanner(System.in);

    input = in.nextLine();

    for(int i=0; i<input.length(); i++){
        char ch = input.charAt(i);
        if(Character.isLowerCase(ch))
            output.append(Character.toUpperCase(ch));
        else if(Character.isUpperCase(ch))
            output.append(Character.toLowerCase(ch));
        else
            output.append(ch);
    }

    System.out.println(output.toString());
 
  }
}

Measured memory_bytes: 26244
# include <bits/stdc++.h>
using namespace std;
const int N = 1100 * 1000;
vector < int > edges[N] , redges[N] , v;
int deg[N] , rdeg[N] , fix[N] , res[N];
void dfs(int x){
	fix[x] = 1;
	for(int i = 0; i < edges[x].size(); i ++){
		int u = edges[x][i];
		if(fix[u] == 2) continue; 
		if(fix[u] == 1){
			cout << "-1";
			exit(0);
		}
		dfs(u);
	}
	fix[x] = 2;
}
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++){
		int pvert = 0;
		for(int j = 1; j < n; j ++){
			int x;
			scanf("%d" , &x);
			int vert = min(i , x) * (n + 1) + max(i , x); 
			if(j > 1){
				edges[vert].push_back(pvert);
				redges[pvert].push_back(vert);
				deg[vert] ++;
				rdeg[pvert] ++;
			}
			pvert = vert;
			v.push_back(vert);
		}
	}
	for(int i = 0; i < v.size(); i ++)
		if(!fix[v[i]])
			dfs(v[i]);
	set < pair < int , int > > s;
	for(int i = 0; i < v.size(); i ++)
		s.insert({rdeg[v[i]] , v[i]});
	int days = 0; 
	while(s.size()){
		set < pair < int , int > > :: iterator it = s.begin();
		int x = it->second;
		s.erase(it);
		for(int i = 0; i < edges[x].size(); i ++){
			int u = edges[x][i];
			s.erase({rdeg[u] , u});
			rdeg[u] --;
			s.insert({rdeg[u] , u});
			res[x] = max(res[x] , 1);
			res[u] = max(res[u] , res[x] + 1);
			days = max(days , res[u]);
		}
	}
	cout << days << "\n";
}

Measured memory_bytes: 127596
/**
*    created: 05.07.2020 21:24:50
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(rall(a));
    int ans = 0;
    int turn = 0;
    ans += a[turn];
    turn++;
    n -= 2;
    while (true) {
        if (n - 2 < 0) {
            ans += a[turn] * n;
            break;
        }
        ans += a[turn] * 2;
        n -= 2;
        turn++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4848
#include <iostream>
using namespace std;
int main() {
	long long a, b, x;
	cin >> a >> b >> x;
	long long st = a - (a % x);
	if (st != a) st += x;
	long long r = b - st;
	if (r < 0) cout << 0 << endl;
	else cout << r / x + 1 << endl;	
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

static const double pi = 3.141592653589793;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<setprecision(10)<<fixed;
	double a, b, x;
  cin>>a>>b>>x;
  if(a*a*b==x){
    cout<<0<<'\n';
    return 0;
  }
  if(a*a*b/2<x){
    double lb=0, ub=90;
    while(ub-lb>1e-9){
       double mid=(lb+ub)/2;
      if(a*a*b-0.5*a*a/tan(pi/180*mid)*a>x){
        ub=mid;
      }
      else{
        lb=mid;
      }
    }
    cout<<90-ub<<'\n';
  }
  else{
    double lb=0, ub=90;
    while(ub-lb>1e-9){
      double mid=(lb+ub)/2;
      if(0.5*b*b*tan(pi/180*mid)*a>x){
        ub=mid;
      }
      else{
        lb=mid;
      }
    }
    cout<<90-ub<<'\n';
  }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main() {
    string A , B;
    cin >> A >> B;
    int a = A.size();
    int b = B.size();
    if(a > b){
        cout << "GREATER" << endl;
    }
    else if(b > a){
        cout << "LESS" << endl;
    }
    else{
        if(A == B){
            cout << "EQUAL" << endl;
        }
        else{
            string m = min(A , B);
            if(m == A){
                cout << "LESS" << endl;
            }
            else{
                cout << "GREATER" << endl;
            }
        }
    }
}


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

int main() {
	int N, C, K, T[100005], min = 0, count = 0;
	cin >> N >> C >> K;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	sort(T, T + N);
	for (int i = 0; i < N; i++) {
		if (i - min > C - 1 || T[i] - T[min] > K) {
			count++;
			min = i;
		}
	}
	if (min != N) count++;
	cout << count << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += l + i;
	}
	
	int ans = BIG_NUM;
	for (int i = 0; i < n; i++) {

		int a = sum - (l + i);
		if (abs(sum - ans) > abs(sum - a)) {
			ans = a;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vi v(n);
	rep(i,0,n)cin >> v[i];
	sort(all(v));
	double ans = double(v[0] + v[1])/2.0;
	rep(i,2,n){
		ans = (ans + v[i])/2.0;
	}
	cout << setprecision(15) << fixed;
	cout << ans << '\n';
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int offset=100000;
const int mod=1e9+7;
const int M=200005;
const int N=100000;
int par[M];
map<int,int>cntx;
map<int,int>cnty;
int fnd(int x)
{
    if(par[x]==x)return x;
    return par[x]=fnd(par[x]);
}
void tie(int x,int y)
{
     x=fnd(x);
     y=fnd(y);
    if(x==y)return ;
    par[y]=x;
}
 main()

{
    fast
    f(i,1,M-1)par[i]=i;
    int n;
    cin>>n;
    f(i,1,n)
    {
        int x,y;
        cin>>x>>y;
        tie(x,y+offset);
    }
    int ses=0;
    f(i,1,N)
    {
        int x=fnd(i);
        cntx[x]++;
        int y=fnd(i+offset);
        cnty[y]++;
    }
    f(i,1,M-1)
    {
        int x=cntx[i];
        int y=cnty[i];
        ses+=(x*y);
    }
    ses=max(0LL,ses-n);
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 30180
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	if(d>e)swap(d,e);
	cout<<a+d-50<<endl;
	return 0;
	}



Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

int h,w;
int store[1000][1000];
int memo[1000][1000][32];

int getCost(int y,int x){
	if(y<0 || h<=y) return 0;
	if(x<0 || w<=x) return 0;
	return store[y][x];
}

int solve(int y,int x,int bought){
	if(h<=y || w<=x) return INT_MAX;
	if(memo[y][x][bought]!=-1) return memo[y][x][bought];
	
	int ans=INT_MAX;
	int cost;
	int nexte,nexts;

	for(int i=0;i<4;i++){
			cost=0;nexte=0;nexts=0;
			if(bought & 1){
				nexte|=4;nexts|=2;
			}else{
				cost+=getCost(y,x);
			}
			if(i!=0 && !(bought & 2)){
				cost+=getCost(y-1,x);
			}
			if(i!=1 && !(bought & 4)){
				cost+=getCost(y,x-1);
			}
			if(i!=2){
				cost+=getCost(y+1,x);
				nexte|=16;nexts|=1;
			}
			if(i!=3){
				cost+=getCost(y,x+1);
				nexte|=1;nexts|=8;
			}
			if(bought & 8){nexte|=2;}
			if(bought & 16){nexts|=4;}

			if(y!=h-1 || x!=w-1){
				cost+=min(solve(y,x+1,nexte),solve(y+1,x,nexts));
			}
			ans=min(ans,cost);
	}

	memo[y][x][bought]=ans;
	return ans;
}

int main(){
	char c;

	cin>>h>>w;
	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			cin>>c;
			if(c=='.'){
				store[y][x]=0;
			}else{
				store[y][x]=c-'0';
			}
			for(int i=0;i<32;i++){
				memo[y][x][i]=-1;
			}
		}
	}

	cout<<solve(0,0,0)<<endl;
	return 0;
}

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

void dfs(const vector<vector<int>> &G, vector<int> &C,
         int v, int prev){
  for(auto v_ : G[v]){
    if(v_ == prev) continue;
    C[v_] += C[v];
    dfs(G,C,v_,v);
  }
}

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> G(N);
  for(int i = 1; i < N; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> C(N,0);
  for(int i = 0; i < Q; ++i){
    int p, x;
    cin >> p >> x;
    --p;
    C[p] += x;
  }
  dfs(G,C,0,-1);
  cout << C[0];
  for(int i = 1; i < N; ++i)
    cout << " " << C[i];
  cout << endl;
}


Measured memory_bytes: 29696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static bool Solve(int N, int M, Dictionary<int, int>[] children)
        {
            var distances = new Dictionary<int, int>();
            for (int i = 0; i < N; ++i)
            {
                if (!distances.ContainsKey(i))
                {
                    var q = new Queue<int>();
                    q.Enqueue(i);
                    distances[i] = 0;
                    while (q.Count > 0)
                    {
                        int a = q.Dequeue();
                        foreach (var pair in children[a])
                        {
                            int b = pair.Key;
                            if (distances.ContainsKey(b))
                            {
                                if (distances[b] != distances[a] + pair.Value) { return false; }
                            }
                            else
                            {
                                q.Enqueue(b);
                                distances[b] = distances[a] + pair.Value;
                            }
                        }
                    }
                }
            }
            return true;
        }

        static void Main(string[] args)
        {
            int[] values1 = ReadInts();
            int N = values1[0];
            int M = values1[1];
            var children = new Dictionary<int, int>[N];
            for (int i = 0; i < N; ++i) { children[i] = new Dictionary<int, int>(); }
            for (int i = 0; i < M; ++i)
            {
                int[] values2 = ReadInts();
                int L = values2[0] - 1;
                int R = values2[1] - 1;
                int D = values2[2];
                children[L][R] = D;
                children[R][L] = -D;
            }
            Console.WriteLine(Solve(N, M, children) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 59988
N, K = map(int, input().split())
A = input().split()

root = [1]
pastTown = {1:0}
t = 0
nextTown = 1

while 1:
  t += 1
  nextTown = int(A[nextTown - 1])
  if nextTown in pastTown.keys():
    break
  else:
    root.append(nextTown)
    pastTown[nextTown] = t

if nextTown == root[0]:
  town = root[K % len(root)]
else:
  if K <= pastTown[nextTown]:
    town = root[K]
  else:
    tmp = (K - pastTown[nextTown]) % (len(root) - pastTown[nextTown])
    town = root[pastTown[nextTown] + tmp]

print(town)


Measured memory_bytes: 50892
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int s;
    if (a*b > c*d){
        s = a*b;
    }else{
        s = c*d;
    }
    cout << s << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>

#define MAX 100000

using namespace std;

vector<int> a;
vector<int> ans;

int find(int s, int t){
  int min = a[s];
  for(int i = s; i <= t; ++i){
    if(min > a[i]){
      min = a[i];
    }
  }
  return min;
}

void update(int i, int x){
  a[i] = x;
}

int main(){
  int n = 0, q = 0;

  cin >> n >> q;
  for(int i = 0; i < n; ++i) a.push_back(INT_MAX);
  for(int i = 0; i < q; ++i){
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0){
      update(x, y);
    } else if(com == 1){
      ans.push_back(find(x, y));
    }
  }

  for(int i = 0; i < ans.size(); ++i){
    cout << ans[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3664
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
string s;
int w;
int main() {
	cin>>s>>w;
	for(int i=0;i<s.size();i+=w)cout<<s[i];
	cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>                                             
#include <cstdio>                                               
using namespace std;                                            
                                                                
int main() {                                                    
  int N;                                                        
  cin >> N;                                                     
  int A[N];                                                     
  for (int i=0; i<N; i++) {                                     
    cin >> A[i];                                                
  }                                                             
  int j;                                                        
  for (int i=0; i<N; i++) {                                     
    int v = A[i];                                               
    j = i-1;                                                    
    while (j>=0 && A[j]>v) {                                    
      A[j+1] = A[j];                                            
      j--;                                                      
      A[j+1] = v;                                               
    }                                                           
    for (int k=0; k<N; k++) {                                   
      cout << (k==0?"":" ") << A[k] << flush;                   
    }                                                           
    printf("\n");                                               
  }                                                             
  return 0;                                                     
}                           

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    int p[n];
    for(int i=0;i<n;i++)scanf("%d",&p[i]);
    int ans=0;
    for(int i=0;i<n-1;i++){
        if(p[i]==i+1){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    if(p[n-1]==n)ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
        int n,k;
        cin >> n;
        vector<int> d(n);
        for (int i = 0; i < n; i++)
                cin >> d[i];
        sort(d.begin(),d.end());
        k = d[n/2] - d[n/2 - 1]; 
        cout << k << endl;
        return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	double l;
	cin >> l;

	printf("%.7f\n", pow(l / 3.0, 3.0));
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
/*ex6_2
  TKC001*/

#include<stdio.h>
#include<string.h>

int main(void){
    int len;
    char str[101];

    //入力
    scanf("%s", str);

  	//文字列の長さ
    len = strlen(str);

    //真ん中の数字は文字列の長さ-2で、左の文字は先頭の文字、右の文字は最後の文字なので
    //出力はstr[0]len-2str[len-1]になる。
    printf("%c%d%c", str[0], len-2, str[len-1]);

    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    Arrays.sort(a);
    long ans = 0;
    if(n % 2 == 0) {
      for(int i = (n - 1); i >= 0; i--) {
        if(i >= (n / 2)) {
          if(i == (n / 2)) {
            ans += a[i];
          } else {
            ans += (2 * a[i]);
          }          
        } else {
          if(i == ((n / 2) - 1)) {
            ans -= a[i];
          } else {
            ans -= (2 * a[i]);
          }
        }
      }
    } else {
      long t = 0;
      for(int i = (n - 1); i >= 0; i--) {
        if(i >= (n - (n / 2))) {
          t += (2 * a[i]);          
        } else {
          if((i == (n - (n / 2) - 1)) || (i == (n - (n / 2) - 2))) {
            t -= a[i];
          } else {
            t -= (2 * a[i]);
          }
        }
      }
      ans = t;
      t = 0;
      for(int i = (n - 1); i >= 0; i--) {
        if(i >= (n - (n / 2) - 1)) {
          if((i == (n - (n / 2) - 1)) || (i == (n - (n / 2)))) {
            t += a[i];
          } else {
            t += (2 * a[i]);
          }          
        } else {
          t -= (2 * a[i]);
        }
      }
      ans = Math.max(ans, t);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 61940
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list> 
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<fstream>
#include<set>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define ll long long
#define ld long double
#define pb push_back
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define pi pair<int,int>
#define pll pair<long long,long long>
#define mp make_pair
#define B begin()
#define E end()
#define S size()
#define m9 1000000007
using namespace std;


 
/*
string fs(string str1, string str2)
{    if (str1.length() > str2.length())
        swap(str1, str2);
      string str = "";
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;
      int carry = 0;
      for (int i=n1-1; i>=0; i--)
    {
 
        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }
      for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }
      if (carry)
        str.push_back(carry+'0');
      reverse(str.begin(), str.end());
 
    return str;
}*/
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
/*
ll gcdextended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    int gcd = gcdextended(b%a, a, &x1, &y1); 
   
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}
 
 
///RELATIVE COPRIME
ll modinverse(ll a, ll m) 
{ 
    ll x, y; 
   ll g = gcdextended(a, m, &x, &y); 
    if (g != 1) 
return -1;
    else
    { 
        ll res = (x%m + m) % m; 
        return res;  
    } 
} 
  */
ll powmod(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = powmod(x, y/2, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
} 
///M IS PRIME
ll modif(ll x,ll m){
return(powmod(x,m-2,m));
 
}
 
bool fa(vll &x,vll &y){return x[0]<y[0];}
bool fa1(vll &x,vll &y){return x[1]<y[1];}
bool f1(pll &x,pll &y){return x.second<y.second;}
bool f2(pll &x,pll &y){return x.first>y.first;}
bool f3(ll &x,ll &y){
    return x>y; 
    }

#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define pin(a) for(auto x:a)cout<<x<<" ";cout<<endl
#define fck(a) cout<<a;exit(0)
#define vvll vector<vector<ll> >
#define A(b) b.begin(),b.end()


//include<bits/stdc++.h>


int main()
{ fastio;
//freopen("input.txt", "r", stdin); 
//freopen("output.txt", "w", stdout);
ll n;cin>>n;
ll ans=0;
forl(i,1,361){
    ans=i;
if((i*n)%360==0)break;
}
cout<<ans;

return 0;
}




Measured memory_bytes: 3624
/*input
6
11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=500+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    ll res=0LL;
    while(b){
        if(b&1) res=(res+a)%MOD;
        a=(a+a)%MOD;
        b>>=1;
    }
    return res%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int ans[maxn][maxn];
bool done[maxn][maxn];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n;
bool isin(int x,int y){
    if(x<0 or x>=n or y<0 or y>=n) return false;
    return true;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n;
    REP(i,n){
        REP(j,n){
            ans[i][j]=min(min(i,j),min(n-i-1,n-j-1));
            done[i][j]=1;
        }
    }
    ll tot=0;
    REP(asd,n*n){
        int x;
        cin>>x;
        --x;
        int r=x/n,c=x%n;
        tot+=ans[r][c];
        done[r][c]=0;
       // cout<<r<<' '<<c<<'\n';
        queue<int> q;
        q.push(r*n+c);
        while(!q.empty()){
            int z=q.front();
            q.pop();
            int x=z/n,y=z%n;
            REP(k,4){
                if(isin(x+dx[k],y+dy[k])){
                    int a=x+dx[k],b=y+dy[k];
                    if(ans[a][b]>ans[x][y]+done[x][y]){
                        ans[a][b]=ans[x][y]+done[x][y];
                        q.push({a*n+b});
                    }
                }
            }
        }
        //cout<<ans[r][c]<<' ';
    }
    cout<<tot;
}

Measured memory_bytes: 4852
my $n = <>;
my %d = ();

for (;0 < $n; $n--) {
    $d{<>}++;
}

my $m = -1;
foreach my $k (reverse sort {$d{$a} <=> $d{$b} || $b cmp $a} keys %d) {
    if ($d{$k} < $m) {
        last;
    }
    print $k;
    $m = $d{$k};
}

Measured memory_bytes: 38884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
#define fr freopen("in.txt","r",stdin);
const ll INF=0x3f3f3f3f;
const ll N=1e6+7;
const ll mod=1e9+7;
ll maxn,minn;
ll T,n,m,k;
ll arr[N];
ll vis[N];
vector<ll>que;

int main(){
//	fr;
	ll flag1,flag2;
	ll a;
	cin>>n>>k;
	k++;
	for(ll i=1;i<=n;i++){
		scanf("%lld",arr+i);
	}
	vis[1]=1;
	a=1;
	que.push_back(a);
	while(1){
		if(vis[arr[a]]==0){
			vis[arr[a]]=vis[a]+1;
			que.push_back(arr[a]);
			a=arr[a];
		}
		else{
			flag1=vis[arr[a]];
			flag2=vis[a];
			break;	
		}
	}
//	for(ll i=0;i<que.size();i++){
//		cout<<que[i]<<" ";
//	}
//	cout<<endl;
//	cout<<flag1<<" "<<flag2<<endl;
	if(k<=flag2){
		cout<<que[k-1]<<endl;
	}
	else{
		k=k-flag2;
//		cout<<k<<endl; 
		k=k%(flag2-flag1+1);
//		cout<<k<<endl;
		if(k==0){
			cout<<que[flag2-1]<<endl;
		}
		else{
			cout<<que[flag1+k-2]<<endl;
		}
	}
	
	
	return 0;
}





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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

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

    std::vector<bool> flg(N);
    int ans = N;
    rep(i, K) {
        int d;
        std::cin >> d;
        rep(j, d) {
            int A;
            std::cin >> A;
            --A;
            if(flg[A]) continue;
            --ans;
            flg[A] = true;
        }
    }

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


Measured memory_bytes: 3644
def Bubble_Sort(l,n):
    count = 0
    dec = 0
    
    is_reverse = True
    while is_reverse:
        is_reverse = False
        
        for i in range(n-1-dec):
            if l[i][1] > l[i+1][1]:
                l[i] , l[i+1] = l[i+1], l[i]
                is_reverse = True
                count += 1
        
        dec += 1

def selectionSort(A,n):
    count = 0
    for i in range(n):
        minj = i
        
        for j in range(i,n):
            if A[j][1] < A[minj][1]:
                minj=j
        A[i],A[minj]=A[minj],A[i]
        count = count + int( i != minj)
    return count

n = int(input())
A = input().split()
B = A.copy()
Bubble_Sort(B,n)
print(' '.join(B))
print('Stable')

selectionSort(A,n)
print(' '.join(A))
if A == B:
    print('Stable')
else:
    print('Not stable')


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

int main(){
  int N;
  cin >> N;
  int T[N];
  for(int i=0 ; i<N ; i++)
    cin >> T[i];
  
  int M, P, X;
  cin >> M;
  for(int i=0 ; i<M ; i++){
    int ans=0;
    cin >> P >> X;
    P--;
    for(int j=0 ; j<N ; j++)
      if(j==P)
        ans+=X;
      else
        ans+=T[j];
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
h,w=map(int,input().split())
l=[['#' for i in range(w+2)] for j in range(2)]
l[1:1]=[list('#'+input()+'#') for i in range(h)]
p=[]
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]=='#':
      p.append((i,j))
d=[(-1,0),(1,0),(0,-1),(0,1)]
r=-1
while len(p)!=0:
  r+=1
  s=[]
  for i, j in p:
    for di, dj in d:
      di+=i
      dj+=j
      if l[di][dj]=='.':
        l[di][dj]='#'
        s.append((di,dj))
  p=s
print(r)

Measured memory_bytes: 128044