akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CADDi_C solver = new CADDi_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class CADDi_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long p = in.nextLong();
            long copy = p;
            long ans = 1;
            long cnt = 0;

            for (long i = 2; i < Math.sqrt((double) copy) + 2; i++) {
                if (p == 1) break;
                while (p % i == 0) {
                    cnt++;
                    p /= i;
                }
                if (cnt >= n) {
                    ans *= (long) Math.pow(i, (cnt / n));
                }
                cnt = 0;
            }

            if (p != 1) {
                if (1 >= n) {
                    ans *= p * (1 / n);
                }
            }

            out.print(ans);

        }

    }
}



Measured memory_bytes: 24020
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;

long long a,b;

int main()
{
	cin>>a>>b;
	b/=2;
	if(a>b)cout<<b<<endl;
	else if((a+b)%2==0)
	{
		cout<<a+(b-a)/2<<endl;
	}
	else
	{
		cout<<(a+b-1)/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int N = 3005, mod = 1e9 + 7;
int n, m;
unsigned int f[2][N][N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("AT2370 [AGC013D] Piling Up.in", "r", stdin);
  freopen("AT2370 [AGC013D] Piling Up.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    f[0][0][i] = 1;
  }
  f[1][0][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (j - 1 >= 0) {
        if (j == 1)
          (f[1][i + 1][j - 1] += f[0][i][j]) %= mod, (f[1][i + 1][j] += f[0][i][j]) %= mod;
        else
          (f[0][i + 1][j - 1] += f[0][i][j]) %= mod, (f[0][i + 1][j] += f[0][i][j]) %= mod;
        (f[1][i + 1][j - 1] += f[1][i][j]) %= mod;
        (f[1][i + 1][j] += f[1][i][j]) %= mod;
      }
      if (j + 1 <= n) {
        (f[0][i + 1][j + 1] += f[0][i][j]) %= mod;
        (f[1][i + 1][j + 1] += f[1][i][j]) %= mod;
        (f[0][i + 1][j] += f[0][i][j]) %= mod;
        (f[1][i + 1][j] += f[1][i][j]) %= mod;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    (ans += f[1][m][i]) %= mod;
  }
  printf("%d", ans);
  return 0;
}

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	int res = 0;
	for (int i = 0; i < N-1; ++i) {
		for (int j = i+1; j < N; ++j) {
			res += d[i]*d[j];
		}
	}
	cout << res << endl;
	return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,k;cin >>n>>k;
    ll cnt0=0;
    ll cnt2=0;
    cnt0=n/k;
    if(k%2==0){
        cnt2=n/k;
        if(n%k>=k/2)cnt2++;
    }
    ll a=1,b=1;
    for (int i = 0; i < 3; ++i) {
        a*=cnt0;
        b*=cnt2;
    }
    cout <<a+b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int x, n500, n5;
  
  scanf("%d", &x);
  
  n500 = x/500;
  x %= 500;
  
  n5 = x/5;
  
  printf("%d\n", n500*1000+n5*5);
  
  return 0;
}

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

int main()  {
    int n,l;
    cin>>n>>l;
    vector<string> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
        cout<<v[i];
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int t[100000];
int table[100000];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>t[i];

	for(int i=0;i<n;i++){
		while(t[i]!=0&&t[i]%2==0){
		table[i]++;
		t[i]=t[i]/2;
		}
	}
	//for(int i=0;i<n;i++)cout<<table[i]<<endl;
	int ma=100000000;
	for(int i=0;i<n;i++)ma=min(ma,table[i]);
	cout<<ma<<endl;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	int N;
	while (cin >> N, N) {
		bool na = true;
		int k, res = 1;
		++N;
		while (--N) {
			cin >> k;
			if (0 < k) ++res;
			if (2 <= k) na = false;
		}
		if (na) {
			cout << "NA\n";
		} else {
			cout << res << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1196
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = scanner.nextInt() - 1;
        }

        UnionFind unionFind = new UnionFind(n);
        for (int i = 0; i < m; i++) {
            unionFind.unite(scanner.nextInt() - 1, scanner.nextInt() - 1);
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (unionFind.same(i, p[i])) {
                ans++;
            }
        }
        System.out.println(ans);
    }

    static class UnionFind {
        private int[] parent;

        UnionFind(int n) {
            parent = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
            }
        }

        int root(int n) {
            while (parent[n] != n) {
                n = parent[n] = parent[parent[n]];
            }
            return n;
        }

        void unite(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                parent[x] = y;
            }
        }

        boolean same(int x, int y) {
            return root(x) == root(y);
        }
    }
}

Measured memory_bytes: 90524
#include <iostream>

using namespace std;

typedef long long ll;

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

ll a, b;

int main(void) {
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}

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

const int maxn = 1000;
int n;
int A[maxn];

int cal(int tar)
{
    int res = 0;
    for(int i = 1;i <= n;++i)
        res += (tar-A[i])*(tar-A[i]);
    return res;
}

int main()
{
    //freopen("./test.txt","r",stdin);
    scanf("%d",&n);

    for(int i = 1;i <= n;++i)
        scanf("%d",&A[i]);

    int res = 0x3f3f3f3f;
    for(int i = -100;i <= 100;++i)
        res = min(res,cal(i));

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

    return 0;
}


Measured memory_bytes: 256
def main():
    a, b, k = map(int, input().split())
    ans_a = a - k
    ans_b = b
    if ans_a < 0:
        ans_b += ans_a
        ans_a = 0
    ans_b = max(ans_b, 0)
    print(ans_a, ans_b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
program main

    character T*200000
    integer S,I
    read *,T
    S = len_trim(T)
    I = S
    do
        if ( I == S ) then
            if ( T(I:I) == "?" ) then
                T(I:I) = "D"
            end if
        else
            if ( T(I:I) == "?" ) then
                if( I == 1 ) then
                    if( T(I+1:I+1) == "D") then
                        T(I:I) = "P"
                    else
                        T(I:I) = "D"
                    end if
                elseif( T(I-1:I-1) == "P" ) then
                    T(I:I) = "D"
                elseif( T(I+1:I+1) == "D") then
                    T(I:I) = "P"
                else
                    T(I:I) = "D"
                end if
            end if
        end if
        I = I - 1
        
        if ( I == 0 ) then
            exit
        end if

    end do
    
    print "(A)",trim(T)
    end program main

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int k;
    cin>>k;
    vector<ll>  v;
    for(int i=1;i<=9;i++){
        v.push_back(i);
    }
    if(k<10){ 
        cout<<v[k-1]<<endl;
        return 0;
    }
    int i=0;
    while(1){
        ll check=v[i];
        if(i+1==k){
            cout<<v[i]<<endl;
            return 0;
        }
        for(int j=0;j<=9;j++){
            if(abs(check%10-j)<=1){
                //cout<<"NEW"<<endl;
                v.push_back(check*10+j);
            }
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 6512
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
ok=False
for i in range(n):
  if a[i][2]==0:
    ok=True
for cx in range(101):
  for cy in range(101):
    s=float('inf')
    d={}
    for k in range(n):
      if a[k][2]==0:
        s=min(s,abs(a[k][0]-cx)+abs(a[k][1]-cy))
      else:
        if a[k][2]+abs(a[k][0]-cx)+abs(a[k][1]-cy) not in d:
          d[a[k][2]+abs(a[k][0]-cx)+abs(a[k][1]-cy)]=1
    if len(list(d))==1:
      c=list(d)
      if ok:
        if 1<=c[0]<=s:
          print(cx,cy,c[0])
          exit()
      else:
        if 1<=c[0]:
          print(cx,cy,c[0])
          exit()

Measured memory_bytes: 3064
/**************************************************
  Solution to: ABC 175 A - Rainy Season
  Writer: InvisibleCyclist
  By/Based on:
**************************************************/
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	if(s=="SSS") cout<<0<<endl;
	if(s=="SSR") cout<<1<<endl;
	if(s=="SRS") cout<<1<<endl;
	if(s=="SRR") cout<<2<<endl;
	if(s=="RRR") cout<<3<<endl;
	if(s=="RRS") cout<<2<<endl;
	if(s=="RSS") cout<<1<<endl;
	if(s=="RSR") cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr inline ll mod = 2019;
// constexpr int max_n = 200'000 + 5;

string s;
ll res;
vector<int> dp(mod), dp2(mod);

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin>>s;
    rep(i, s.size()) {
        int a = s[i] - '0';
        dp2 = dp; // コピー
        rep(j, mod) {
            dp[(10 * j + a) % mod] = dp2[j];
        }
        dp[a]++;
        res += dp[0];
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 3764
// https://atcoder.jp/contests/abc170/tasks/abc170_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int ans = 0;
    REP(i, 5) {
        int t;
        cin >> t;
        if (t == 0) {
            ans = i + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3584
a = $<.read.split.map(&:to_i)
N = a[0]
a[0] = 0
ma = a.max
mi = a.min

if ma.abs > mi.abs
	idx = a.index(ma)
	a = a.each_with_index.select { |x| x[0] < 0 }
	p N - 1 + a.size
	puts "#{idx} %d\n"*(a.size)%(a.map(&:pop)) if a.size > 0
	[*1..N].each_cons(2){ |x,y| print x," ",y,"\n" }

else

	idx = a.index(mi)
	a = a.each_with_index.select { |x| x[0] > 0 }
	p N - 1 + a.size
	puts "#{idx} %d\n"*(a.size)%(a.map(&:pop)) if a.size > 0
	[*1..N].reverse.each_cons(2){ |x,y| print x," ",y,"\n" }
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int N;
    cin>>N;
    int ans = 10000-N;
    cout<<ans%1000<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;float p=1.08,x,s,q,f;
    cin>>n;
    x=n/p;
    s=ceil(x);
    q=ceil(x)*p;
    f=floor(q);
    if(n==f)
    {
        cout<<s;
    }
    else{
        cout<<":(";
    }


}


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

int main(){
	int n; cin>>n;
	vector<int> va(n+1);
	vector<int> vb(n);
	rep(i,n+1) cin>>va[i];
	rep(i,n) cin>>vb[i];
	ll cnt=0;
	rep(i,n){
		if(va[i]-vb[i]>=0) cnt+=vb[i];
		else{
			if(va[i+1]+va[i]-vb[i]<0){
				cnt+=va[i]+va[i+1];
				va[i+1]=0;
			} else {
				va[i+1]-=vb[i]-va[i];
				cnt+=vb[i];
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 4004
#include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 int *list;
 int n,i,j,cnt;
 
 while(scanf("%d",&n) != EOF)
 {
  cnt = 0;
  list = (int*)calloc(n+1,sizeof(int));
  for(i = 2; i <= n; i++)
  {
   if(list[i] != 1) /*prime number:0 no prime numbers:1*/
   { 
    cnt++;
    for(j = i+i; j <= n; j+=i) list[j] = 1;
   }
  }
  printf("%d\n",cnt);
  free(list);
 } 
 return 0;
}

Measured memory_bytes: 4396
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
long long solve()
{
	long long n;cin>>n;
	std::vector<long long> inp(n);
	REP(i,0,n-1){cin>>inp[i];}
	std::vector<std::vector<long long>> fin(n,std::vector<long long>(n,10000000000000000));
	std::vector<long long> pre;
	long long sum=0;
	REP(i,0,n-1){sum+=inp[i];pre.pb(sum);}
	REP(i,0,n-1)
	{
		fin[i][i]=0;
	}
	REP(i,0,n-2)
	{
		fin[i][i+1]=(inp[i]+inp[i+1]);
	}
	for(int i=n-3;i>=0;--i)
	{
		REP(j,i+2,n-1)
		{
			long long pref=(pre[j]-((i==0)?0:pre[i-1]));
			REP(k,i,j-1)
			{
				fin[i][j]=MIN(fin[i][j],(fin[i][k]+fin[k+1][j]+pref));
			}
		}
	}
	/*REP(i,0,n-1)
	{
		REP(j,i,n-1){cout<<i<<" "<<j<<" "<<fin[i][j]<< "\n";}
	}*/
	cout<<fin[0][n-1];
}
signed main(){
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define F first
#define S second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
using namespace std;
int main()
{
   	fast
    ll n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2)
    	cout<<"No\n";
    else
    {
    	ll i;
    	for(i=0;i<n/2;i++) if(s[i]!=s[i+n/2])  break;
    	if(i == n/2) cout <<"Yes\n";
    	else cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val n = f.readLine().toInt()

	var ac = 0
	var wa = 0
	var tle = 0
	var re = 0

	for(k in 0 until n){
		val s = f.readLine()
		if(s.equals("AC")) ac++
		if(s.equals("WA")) wa++
		if(s.equals("TLE")) tle++
		if(s.equals("RE")) re++
	}

	println("AC x $ac")
	println("WA x $wa")
	println("TLE x $tle")
	println("RE x $re")
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (int i = 0; i < (int)S.size(); i++) {
        if ((char)(S[i] + N) <= 'Z') {
            S[i] += N;
        } else {
            int tmp = N - (int)('Z' - S[i]) - 1;
            S[i] = char('A' + tmp);
        }
    }
    cout << S << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int x = 1;
  for (int i = 0;i<N; i++){
    if (x < K){
      x += x;
    }
    else {
      x += K;
    }
    
  }
  cout << x << endl;
  
    
  
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    Q, H, S, D = [int(x) for x in input().split()]
    N = int(input())

    ans = 0
    if Q * 8 > D and H * 4 > D and S * 2 > D:
        X, N = divmod(N, 2)
        ans += X * D

    if Q * 4 > S and H * 2 > S:
        print(ans + S * N)
    elif Q * 2 > H:
        print(ans + H * 2 * N)
    else:
        print(ans + Q * 4 * N)


    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
h,w = gets.chomp.split.map(&:to_i)
as = h.times.map{gets.chomp.chars}
as.each do |a|
    if a.all?{|i| i == "." }
        as.delete(a)
    end 
end
as = as.transpose
as.each do |a|
    if a.all?{|i| i == "." }
        as.delete(a)
    end 
end
as.transpose.each do |a|
    puts a.join 
end

Measured memory_bytes: 2684
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>

using namespace std;

double color[20][3];
double dist[20][20];

int bitcount(int arg){
    int ret = 0;
    while(arg > 0){
        if(arg & 1) ret++;
        arg >>= 1;
    }
    return ret;
}

int main(){
    int n,m;
    
    while(cin >> n >> m){
        if((n|m) == 0) break;
        
        memset(color, 0, sizeof(color));
        memset(dist, 0, sizeof(dist));

        for(int i=0;i<n;i++){
            cin >> color[i][0] >> color[i][1] >> color[i][2];
        }

        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                dist[i][j] = 
                    pow(abs(color[i][0] - color[j][0]), 2) +
                    pow(abs(color[i][1] - color[j][1]), 2) +
                    pow(abs(color[i][2] - color[j][2]), 2);
                dist[j][i] = dist[i][j];
            }
        }

        double tmp, ret=-1;

        for(int i=0;i<(1 << n);i++){
            if(bitcount(i) == m){ //choosed m colors
                tmp = 0;
                for(int j=0;j<n;j++){
                    if((i & (1 << j))){
                        for(int k=j+1;k<n;k++){
                            if((i & (1 << k))){
                                tmp += dist[j][k];
                            }
                        }
                    }
                }
                ret = max(ret, tmp);
            }
        }
        printf("%.17f\n", ret);
    }
}

Measured memory_bytes: 984
// 2020 04 11 p95 Bellman-Ford for shortest path, GRL_1_B
// DAG : 有向非巡回グラフ, Directed acyclic graph
// 主に負のコストを持つ辺があるときに用いられる
// O(V*E)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B&lang=jp
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 100000000;

struct Edge{   
    // B-F は辺を1つ選んでcostを計算していく
    int from;
    int to;
    int weight;
    Edge(int f, int t, int w) : from(f), to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;


int main() {
    int V, E, r;
    cin >> V >> E >> r;
    if (E == 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<Edge> e;
    vector<int> d(V, INF); // Shortest distance
    d[r] = 0;
    rep(i, E){
        int from, to, weight;
        cin >> from >> to >> weight;
        e.push_back(Edge(from, to, weight));
    }

    // Bellman-Ford
    bool neg_loop = false; // trueなら負の閉路が存在する
    int cnt = 0;    // while-loopは高々V-1回しか繰り返されない
    while(true) {
        // cout << cnt << endl;
        bool update = false;
        if(cnt >= V-1) {
            neg_loop = true;
            break;
        }
        rep(i, E) {
            if (d[e[i].from] != INF && d[e[i].to] > d[e[i].from] + e[i].weight) {
                d[e[i].to] = d[e[i].from] + e[i].weight;
                update = true;
            }
        }
        cnt++;
        if (!update) break;
    }


    if (neg_loop) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; i++){
            if (d[i] == INF) {
                cout << "INF" << endl;
            }else{
                cout << d[i] << endl;
            }
        }
        
    }


    return 0;
}


Measured memory_bytes: 3156
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, H, W, a[500][500], x1[250000], y1[250000], x2[250000], y2[250000];
	cin >> H >> W;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}

	for (i=0; i < H; i++) {
		for (j=0; j < W-1; j++) {
			if (a[i][j] % 2) {
				x1[k] = i; y1[k] = j; x2[k] = i; y2[k++] = j + 1;
				a[i][j]--; a[i][j + 1]++;
			}
		}
		if ((a[i][j] % 2)&&(i<H-1)) {
			x1[k] = i; y1[k] = j; x2[k] = i+1; y2[k++] = j;
			a[i][j]--; a[i + 1][j]++;
		}
	}

	cout << k << endl;
	for (i = 0; i < k; i++) {
		cout << x1[i]+1 << " " << y1[i]+1  << " " << x2[i]+1 << " " << y2[i]+1 << endl;
	}
	return 0;
}


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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	string ans = "";
	while (n) {
		if (n % 2) {
			n--;
			ans += "1";
		}else {
			ans += "0";
		}
		n /= -2;
	}	
	reverse(ans.begin(),ans.end());
	if (ans == "")  ans = "0";
	cout << ans;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int mod = 1e+9 + 7;
/* global variables */
/* funciton */
/* main */
int main() {
    string S;
    int D;
    cin >> S >> D;
    vector<int> a(S.size());
    for (int i = 0; i < S.size(); i++) a[i] = S[i] - '0';

    // dp[i][j][0] i桁目まで使って, mod D = j, 現時点でSよりも数字が小さいことが確定している
    // dp[i][j][1] i桁目まで使って, mod D = j, 現時点でSと同じ数字 -> これから同じ or 小さい
    // transition)
    // dp[i+1][j+(num = a[i]) mod D][1] += dp[i][j][1]
    // dp[i+1][j+(num < a[i]) mod D][0] += dp[i][j][1]
    // dp[i+1][j+(0<= num <= 9) mod D][0] += dp[i][j][0]
    // init
    vector<vector<vector<ll>>> dp(a.size() + 1, vector<vector<ll>>(D, vector<ll>(2)));
    dp[0][0][1] = 1;
    // calc
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < D; j++) {
            for (int num = 0; num <= 9; num++) {
                int neJ = (j + num) % D;
                if (num == a[i]) {
                    dp[i+1][neJ][1] += dp[i][j][1];
                    dp[i+1][neJ][1] %= mod;
                }
                if (num < a[i]) {
                    dp[i+1][neJ][0] += dp[i][j][1];
                    dp[i+1][neJ][1] %= mod;
                }
                dp[i+1][neJ][0] += dp[i][j][0];
                dp[i+1][neJ][0] %= mod;
            }
        }
    }
    // ans = (mod D == j)の個数
    // 答えに0が含まれるので-1する
    ll ans = (dp[a.size()][0][1] + dp[a.size()][0][0] - 1 + mod) % mod;
    cout << ans << '\n';
}

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

using namespace std;

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

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

    sort(h.begin(), h.end());
    long long ans = 0;
    for (int i=0; i<n-k; i++) ans += h[i];

    cout << ans << endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <unordered_set>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> p(n*n);
  for (auto &x: p) {
    cin >> x;
  }

  vector<vector<bool> > exist(n, vector<bool>(n, true));
  vector<vector<int> > dist(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = min(min(i, n-i-1), min(j, n-j-1));
    }
  }
  int ans = 0;
  for (auto &x: p) {
    ans += dist[(x-1)/n][(x-1)%n];
    exist[(x-1)/n][(x-1)%n] = false;
    queue<Pii> que;
    que.emplace((x-1)/n, (x-1)%n);
    while (!que.empty()) {
      auto now = que.front();
      que.pop();
      if (now.first > 0) {
        if (!exist[now.first][now.second] && dist[now.first-1][now.second] > dist[now.first][now.second]) {
          dist[now.first-1][now.second] = dist[now.first][now.second];
          que.emplace(now.first-1, now.second);
        }
        else if (exist[now.first][now.second] && dist[now.first-1][now.second] > dist[now.first][now.second]+1) {
          dist[now.first-1][now.second] = dist[now.first][now.second]+1;
          que.emplace(now.first-1, now.second);
        }
      }
      if (now.first < n-1) {
        if (!exist[now.first][now.second] && dist[now.first+1][now.second] > dist[now.first][now.second]) {
          dist[now.first+1][now.second] = dist[now.first][now.second];
          que.emplace(now.first+1, now.second);
        }
        else if (exist[now.first][now.second] && dist[now.first+1][now.second] > dist[now.first][now.second]+1) {
          dist[now.first+1][now.second] = dist[now.first][now.second]+1;
          que.emplace(now.first+1, now.second);
        }
      }
      if (now.second > 0) {
        if (!exist[now.first][now.second] && dist[now.first][now.second-1] > dist[now.first][now.second]) {
          dist[now.first][now.second-1] = dist[now.first][now.second];
          que.emplace(now.first, now.second-1);
        }
        else if (exist[now.first][now.second] && dist[now.first][now.second-1] > dist[now.first][now.second]+1) {
          dist[now.first][now.second-1] = dist[now.first][now.second]+1;
          que.emplace(now.first, now.second-1);
        }
      }
      if (now.second < n-1) {
        if (!exist[now.first][now.second] && dist[now.first][now.second+1] > dist[now.first][now.second]) {
          dist[now.first][now.second+1] = dist[now.first][now.second];
          que.emplace(now.first, now.second+1);
        }
        else if (exist[now.first][now.second] && dist[now.first][now.second+1] > dist[now.first][now.second]+1) {
          dist[now.first][now.second+1] = dist[now.first][now.second]+1;
          que.emplace(now.first, now.second+1);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int w,h,n;
  cin>>w>>h>>n;
  int x,y,a;
  
  int minX=0;
  int minY=0;
  int maxX=w;
  int maxY=h;
  
  for(int i=0;i<n;i++){
    cin>>x>>y>>a;
    if(a==1){
      minX=max(minX,x);
    }else if(a==2){
      maxX=min(maxX,x);
    }else if(a==3){
      minY=max(minY,y);
    }else if(a==4){
      maxY=min(maxY,y);
    }
  }

  int area=max(0,maxX-minX)*max(0,maxY-minY);
  
  cout<<area<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    ll L1 = 1, L2 = 2;
    ll ans = 1;
    if(N==0){
        cout << 1 <<endl;
    }
    else{
        for(int i = 1; i < N; i++){
            ans += L2;
            L2 = L1;
            L1 = ans;
        }
        cout << ans <<endl;
    }
}


Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int a,b;
int dis(int x,int y){return y>=x?y-x:mod;}
int main()
{
	cin>>a>>b;
	cout<<min(dis(a,b),min(dis(-a,b)+1,min(dis(a,-b)+1,dis(-a,-b)+2)))<<endl;
	return 0;
}


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

const int N = 100000 + 10;

std::string strings[N];
int n;

bool cmp(char* a, char* b) {
  return strcmp(a, b) < 0;
}

int main() {
  char buffer[12];
  scanf("%d", &n);
  for (int i = 1; i <= n; ++ i) {
    scanf("%s", buffer);
    int length = strlen(buffer);
    std::sort(buffer, buffer + length);
    strings[i] = buffer;
  }
  std::sort(strings + 1, strings + n + 1);

  long long answer = 0;
  for (int i = 1; i <= n; ) {
    int j = i + 1;
    while (j <= n && strings[i] == strings[j]) {
      j ++;
    }
    long long x = j - i;
    answer += x * (x - 1) / 2;
    i = j;
  }
  printf("%lld\n", answer);
  return 0;
}


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

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

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

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


int main(){
  ll x,a,b; cin >> x >> a >> b;
  if(abs(a-x) < abs(b-x)) cout << 'A' << endl;
  else cout << 'B' << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
ablist = [[] for _ in range(N)]
anslist = [0 for i in range(N)]

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

pxlist = [list(map(int,input().split())) for _ in range(Q)]

for q,x in pxlist:
    anslist[q-1] += x

def dfs(nownode,oya=-1):
    for nextnode in ablist[nownode]:
        if oya == nextnode:
            continue
        anslist[nextnode] += anslist[nownode]
        dfs(nextnode,nownode)
dfs(0,-1)
print(*anslist)

Measured memory_bytes: 310916
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
int rint();char rch();long long rlong();
// mt19937 rng; rng.seed(std::chrono::high_resolution_clock::now().time_since_epoch().count());
// template<typename T> int bins(vector<T> &v, T key) {int imin=0,imax=v.size();while(imin<imax) {int imid=(imin+imax)>>1;if (v[imid]<key) imin=imid+1;else imax=imid;}return imin;}
int c[4];
int main() 
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin>>n;
  //printf("n:%d\n",n);
  int fir=0;
  for (int j=0;j<n;j++) {
  	string s; cin>>s;
  	int k=s.length(); for (int i=1;i<k;i++) if (s[i-1]=='A'&&s[i]=='B') fir++;
		int t=0;
		if (s[k-1]=='A') t|=1;
		if (s[0]=='B') t|=2;
		//printf("t:%d\n",t);
		++c[t];
  }
  int A=c[1],B=c[2],BA=c[3];
  int ans=0;
  if (BA>0) {
  	if (A>0) {A--; ans++;}
  	if (B>0) {B--; ans++;}
  	ans+=BA-1;
  }
  ans+=min(A,B);
  //printf("oans:%d fir:%d\n",ans,fir);
  ans+=fir;
  printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int A,B,C,K;cin>>A>>B>>C>>K;
    cout<<(K%2==1?B-A:A-B)<<endl;
}


Measured memory_bytes: 256
# ABC 144 C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = gets.chomp.to_i
divisors = []

(1..(Math.sqrt(n))).each do |i|
  div, mod = n.divmod(i)
  if mod == 0
    divisors.push(div)
  end
end

result = Float::INFINITY

divisors.each do |divisor|
  another_divisor = n / divisor
  i = divisor + another_divisor
  if result > i
    result = i
  end
end

puts result - 2


Measured memory_bytes: 1916
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int X;
    R(X);
    LL an=X/500*1000;
    X%=500;
    an+=X/5*5;
    W(an);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

/*int isEmpty(){
  if(head == tail) return 0;
  else return 1;
}*/

/*int isFull(){
  if(head == (tail + 1) % n)  return 1;
  else return 0;
}*/
void enqueue(P x){
  //if(isFull()){}
  Q[tail].t = x.t;
  strcpy(Q[tail].name,x.name);
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x;
  //if(isEmpty()){};
  x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

void initialize(){
  head = 1;
  tail = n + 1;
}


int main(){
  int elaps = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  initialize();
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(n != 0){
      u = dequeue();
      if(u.t > q){
        u.t -= q;
        elaps += q;
        enqueue(u);
      }else{
        elaps += u.t;
        printf("%s %d\n",u.name,elaps);
        n--;
      }
  }

  return 0;
}



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

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

long long MOD = 10000000000 + 7;

vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(i != n / i) res.push_back(n / i);
    }
  }
  return res;
}
int main(){
  cout << setprecision(10);
  ll N; cin >> N;
  auto div = divisor(N);

  ll ans = N - 1;
  for(auto x: div){
    ll y = N / x;
    ll tmp = x-1 + y-1;

    ans = min(tmp, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3688
#include<stdio.h>
#define MAX 500000
#define NIL -1
int r, l, N, largest;
int A[MAX];

void maxHeapify(int *A, int i, int H){
  l = 2 * i;
  r = 2 * i + 1;

    if(l <= H && A[l] > A[i]){
    largest = l;
    }else{  largest = i;}
    if( r <= H && A[r] > A[largest])
    largest = r;

    if(largest != i){
      N = A[i];
    A[i] = A[largest];
    A[largest] = N;
    maxHeapify(A, largest, H);
    }
}

int main(){
  int i;
  int H;
  int id;

  scanf("%d", &H);
  for(i=1; i<=H; i++) scanf("%d", &A[i]);

  for(i=H/2; i>=1 ;i--)
    maxHeapify(A, i, H);

  for(i=1; i<=H; i++) printf(" %d", A[i]);
  printf("\n");
  return 0;
}




Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define PI 3.141592653589793
typedef long long ll;

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

    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << a << endl;
    }else if(a < b){
        cout << a << endl;
    }else{
        cout << a - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

k=INT()
a,b=MAP()

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





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

typedef long long Long;

/* オイラーのφ関数 
 * 正の整数 n について、1 から n までの自然数のうち n と互いに素なものの個数を求める */
map<Long, int> PrimeFactorize(Long n) {
    map<Long, int> Ret;
    for (Long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            Ret[i]++;
            n /= i;
        }
    }
    if (n != 1) Ret[n]++;
    return Ret;
}
Long Pow(Long x, Long n) {
    Long Ret = 1;
    for (int i = 0; i < n; i++) Ret *= x;
    return Ret;
}
Long EulersTotientFunction(Long n) {
    typedef map<Long, int> M;
    M Factor = PrimeFactorize(n);
    Long Ret = 1;
    for (M::iterator it = Factor.begin(); it != Factor.end(); it++) {
        Ret *= Pow(it->first, it->second) - Pow(it->first, it->second - 1);
    }
    return Ret;
}

int main() {
    int N; cin >> N;
    cout << EulersTotientFunction(N) << endl;
    return 0;
}

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

int main(){
    int n;
    long long max = -1000000;
    long long min = 1000000;
    long long a;
    long long sum = 0;
    cin >> n;
    for(int i = 0; i < n ; ++i){
       cin >> a;
       if(a > max) max = a;
       if(a < min) min = a;
       sum += a;
      }
    cout << min << " " << max << " " << sum << endl;
    return 0;
  }
     

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	double a,b,x; cin >> a >> b >> x;
	x /= a;
	if(x >= a*b/2){
		double s = a*b-x;
		double d = s*2 / a;
		cout << atan2(d,a)/acos(-1)*180 << endl;
	}else{
		double d = x*2/b;
		cout << atan2(b,d)/acos(-1)*180 << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
	int N,K,x[100],Result=0;
	
	scanf("%d %d",&N,&K);
	
	for(int i=0; i<N; i++)
	{
		scanf("%d",&x[i]);
	}
	
	for(int i=0; i<N; i++)
	{
		if((x[i]) > abs((x[i]-K))) Result += abs((x[i]-K)*2);
		else Result += x[i]*2;
	}
	
	printf("%d\n",Result);
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

main(){
  int S[10000],T[500],n,q,i,j,count=0;
  
  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(j=0 ; j<q ; j++){ 
    scanf("%d",&T[j]); 
    for(i=0 ; i<n ; i++){    
      if(T[j] == S[i]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll a[N + 1];
  for(int i = 0; i < N + 1; i++) cin >> a[i];
  ll b[N];
  for(int i = 0; i < N; i++) cin >> b[i];

  ll ans = 0;
  for(int i = 0; i < N; i++){
    if(a[i] >= b[i]){
      ans += b[i];
    } else {
      ans += a[i];
      b[i] -= a[i];
      ans += min(a[i + 1], b[i]);
      a[i + 1] = max(a[i + 1] - b[i], 0LL);
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
from itertools import groupby
from functools import reduce

N = int(input())
Ss = [''.join(sorted(list(input()))) for _ in range(N)]

def calc(x):
    return int(x*(x-1)/2)

g = list(map(lambda x: len(list(x[1])), groupby(sorted(Ss))))
h = list(map(calc, g))
res = sum(h)

print(res)

Measured memory_bytes: 12968
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(){
	/*input*/
	int n;	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	/*calculation*/
	sort(a.begin(), a.end());
	int dicnum = 0, tmp, ans = 0;
	vector<pair<int, int> >dic;
	dic.push_back(pair<int, int>(a[0], 0));
	rep(i, n){
		if(dic[dicnum].first == a[i]){
			dic[dicnum].second++;
		}else{
			dic.push_back(pair<int, int>(a[i], 1));
			dicnum++;
		}
	}
	rep(i, dic.size()){
		(dic[i].first > dic[i].second)?ans += dic[i].second:ans += dic[i].second - dic[i].first;
	}
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 3500;
 
int main() {
  long long n;
  cin >> n;
  for (long long a = 1; a <= MAX; a++) {
    for (long long b = 1; b <= MAX; b++) {
      long long x = n * a * b;
      long long y = 4 * a * b - n * b - n * a;
      if (y > 0 && x % y == 0) {
        long long c = x / y;
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256