akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
long long tree[200005],dp[200005],a[200005];
int h[200005];
inline int lowbit(int x)
{
	return x&(-x);
}
inline void add(int x,long long y)
{
	if(x>200000) return ;
	tree[x]=max(tree[x],y),add(x+lowbit(x),y);
}
inline long long ask(int x)
{
	if(x==0) return 0;
	return max(tree[x],ask(x-lowbit(x)));
}
int main(int argc, char** argv) {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> h[i];
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=n;i++)
	{
		dp[i]=a[i]+ask(h[i]-1);
		add(h[i],dp[i]);
	}
	cout << ask(n);
	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<queue>
#include<map>

using namespace std;


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

    vector<int> a(n);

    for(int i=0;i<n;i++) cin >> a[i];
    
    for(int j=0;j<n-1;j++)
        for(int i=n-1;i>j;i--) {
            if(a[i] < a[i-1]) {
                swap(a[i], a[i-1]);
                cnt++;
            }
        }

    for(int i=0;i<n;i++){
        if(i > 0) {cout  << " ";}
        cout << a[i];
    }

    cout << endl;
    cout << cnt << endl;
}


Measured memory_bytes: 3084
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
int sosuu[100]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451,1471,1481,1511,1531,1571,1601,1621,1721,1741,1801,1811,1831,1861,1871,1901,1931,1951,2011,2081,2111,2131,2141,2161,2221,2251,2281,2311,2341,2351,2371,2381,2411,2441,2521,2531,2551,2591,2621,2671,2711,2731,2741,2791};
signed main(){
    int n;cin>>n;
        rep(i,0,n){
            if(i!=0)cout<<" ";
            cout<<sosuu[i];
        }cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,maxn=0,minn=99999999;
int main(){
	cin>>n>>m;
	for(int i=1,j,k;i<=m;i++){
		cin>>j>>k;
		maxn=max(maxn,j);
		minn=min(minn,k);
	}
	if(minn-maxn+1<=0)cout<<'0';
	else cout<<minn-maxn+1;
	return 0;
}

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

const int MAX = 100000;
int main() {
	static int N, h[MAX];
	cin >> N;
	for (int i = 0;i < N;++ i) cin >> h[i];
	static int dp[MAX];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2;i < N;++ i) dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	cout << dp[N - 1];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

基本的なdpだねー
*/

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

using namespace std;
int main(){
signed long long n,num=10,ans;
cin >> n;
int flag = 1;
signed long long cnt=0;
if (n%2!=0)
{
  flag = 0;
  ans = 0;
}
if (flag)
{
  while(n/num>=1){
  
    cnt += n/num;
    num = num * 5;
  }
}
cout << cnt<<endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

void solve()
{
	int sum;
	while(cin >> sum, sum)
	{
		for(int i = 0; i < 9; ++i)
		{
			int price;
			cin >> price;
			sum -= price;
		}
		cout << sum << endl;		
	}
}

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

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, W;
        public long MOD = 1000000007;
        public long[] WS;
        public long[] VS;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                W = line[1];
            }

            WS = new long[N];
            VS = new long[N];

            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadIntArray();
                WS[i] = line[0];
                VS[i] = line[1];
            }

            long[,] DP = new long[N, W+1];
            DP[0, WS[0]] = VS[0];
            for (int i = 1; i < N; i++)
            {
                for (int w = 0; w <= W; w++)
                {
                    DP[i, w] = DP[i - 1,w];
                    if (w >= WS[i])
                    {
                        DP[i, w] = Math.Max(DP[i - 1, w - WS[i]] + VS[i], DP[i, w]);
                    }
                }
            }

            long ret = 0;
            for (int w = 0; w <= W; w++)
            {
                ret = Math.Max(ret, DP[N - 1, w]);
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 90976
def check(mid,n):
    total = 26*(pow(26,mid)-1)//25
    if total <= n:
        return True

    return False

def find(n):
    low = 1
    high = 10
    x = 0
    while low <= high:
        mid = (low+high)//2
        if check(mid,n):
            x = mid
            low = mid+1
        else:
            high = mid-1

    return x

def find2(n,x,curr_len):
    low = 0
    high = 26
    while low <= high:
        mid = (low+high)//2
        if mid*pow(26,x-curr_len-1) < n:
            low = mid+1
            k = mid
        else:
            high = mid-1

    return k

def main():
    n = int(input())
    if n <= 26:
        print(chr(ord('a')+n-1))
        return
    
    ans = ''
    x = find(n)
    n -= 26*(pow(26,x)-1)//25
    if n == 0:
        for i in range(x):
            ans += 'z'
    else:
        x += 1
        #print(n)
        while len(ans) != x:
            k = find2(n,x,len(ans))
            if k == 0:
                ans += chr(ord('a')+k)
            else:
                ans += chr(ord('a')+k)
                n -= k*pow(26,x-len(ans))

            #print(ans,n,k)

    print(ans)
            
    
main()


Measured memory_bytes: 61984
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
const ll INF = 1e17;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
ll dist[500][500],gas[500][500];
ll a[MAX],b[MAX],c[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,m,l;
    cin>>n>>m>>l;
    for(int i=1; i<=m; i++)
        cin>>a[i]>>b[i]>>c[i];
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
            dist[i][j]=INF,gas[i][j]=INF;
        gas[i][i]=0;
        dist[i][i]=0;
    }
    for(int i=1; i<=m; i++)
    {
        gas[a[i]][b[i]]=min(gas[a[i]][b[i]],c[i]);
        gas[b[i]][a[i]]=min(gas[b[i]][a[i]],c[i]);
    }
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                gas[i][j]=min(gas[i][j],gas[i][k]+gas[k][j]);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(i==j)
                continue;
            if(gas[i][j]<=l)
                dist[i][j]=min(dist[i][j],1ll);
        }
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    int q;
    cin>>q;
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        if(dist[x][y]==INF)
            cout<<"-1"<<endl;
        else
            cout<<dist[x][y]-1<<endl;
    }



    return 0;
}


Measured memory_bytes: 7012
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,n) for(i=0;i<(n);i++)
using namespace std;
using ll = long long;

int main(){
	int a,b,h,ans = 0;
	cin >> a >> b >> h;
	ans = (a + b)*h / 2;
	cout << ans;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b, c := read(), read(), read()

	var aint, bint, cint int
	aint, _ = strconv.Atoi(a) //文字列から１０進整数への変換
	bint, _ = strconv.Atoi(b)
	cint, _ = strconv.Atoi(c)
	count := 0

	for i := 0; i < cint; i++ {
		bint = bint - aint
		if bint >= 0 {
			count++
		}
	}

	if count > cint {
		fmt.Println(cint)
	} else {
		fmt.Println(count)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef struct edge{
    ll to, yen, snu;
}edge;


int main() {
    ll s, t;
    cin>>N>>M>>s>>t;
    --s; --t;
    vector<vector<edge> > G(N, vector<edge>(0));
    rep(i,M){
        ll u, v;
        cin>>u>>v>>A>>B;
        --u; --v;
        edge e;
        e.to = v;
        e.yen = A;
        e.snu = B;
        G[u]. push_back(e);
        e.to = u;
        G[v].push_back(e);
    }
    mat dist(2, vec(N,INF));
    dist[0][s] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.emplace(0, s);
    while(!que.empty()){
        P p = que.top();
        que.pop();
        if(p.fi > dist[0][p.se]) continue;
        for(edge e : G[p.se]){
            if(p.fi + e.yen < dist[0][e.to]){
                dist[0][e.to] = p.fi + e.yen;
                que.emplace(dist[0][e.to], e.to);
            }
        }
    }
    dist[1][t] = 0;
    que.emplace(0, t);
    while(!que.empty()){
        P p = que.top();
        que.pop();
        if(p.fi > dist[1][p.se]) continue;
        for(edge e : G[p.se]){
            if(p.fi + e.snu < dist[1][e.to]){
                dist[1][e.to] = p.fi + e.snu;
                que.emplace(dist[1][e.to], e.to);
            }
        }
    }
    vec ans(N, 1e+15);
    ll temp = INF;
    Rrep(i,N){
        temp = min(temp, dist[0][i] + dist[1][i]);
        ans[i] -= temp;
    }
    rep(i,N) cout<<ans[i]<<endl;
}

Measured memory_bytes: 13696
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
#define INF 1e14
typedef long long int ll;
const ll N=1e6+5;
bool x[N+1]={false};
ll fast(ll n,ll a)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a)%Mod;
        if(n%2==0)
        {
            return (((res%Mod)*(res%Mod))%Mod);
        }
        else{
            return (((((res%Mod)*a)%Mod)*res)%Mod);
        }
    }
}
int main()
{
  ll l,r,i,j;
  cin>>l>>r;
  vector<ll> vec;
  for(i=l;i<=min(r,l+2019);i++)
  {
      vec.push_back(i%2019);
  }
  ll ans=1e8;
  for(i=0;i<vec.size();i++)
  {
      for(j=0;j<vec.size();j++)
      {
          if(i!=j)
          {
              ll s=vec[i]*vec[j];
              s=s%2019;
              ans=min(ans,s);
          }
      }
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=2e5+500;
const ll inf=1e9+800;

ll findbeh1(ll a){
	if(a%2==1)return a;
	if(a==0)return -1;
	return a-1;
}
ll findbeh2(ll a){
	if(a==0)return -2;
	if(a%2==1)return a-1;
	return a;
}

ll a[maxn];
ll cnt[maxn][3];

ll d[maxn];
ll y[maxn];
ll b[maxn];
ll beh1[maxn];
ll beh2[maxn];

ll mxa[maxn];
ll mxd[maxn];
ll mxb[maxn];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	ll n,sum=0;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}	
	for(ll i=1;i<=n;i++){
		beh1[i]=findbeh1(a[i]);
		beh2[i]=findbeh2(a[i]);
	}
	for(ll i=1;i<=n;i++){
		d[i]=d[i-1]+beh2[i];
	}
	for(ll i=1;i<=n;i++){
		y[i]=y[i-1]+beh1[i];
	}
	for(ll i=0;i<=n;i++){
		b[i]=y[i]-d[i];
	}
	for(ll i=0;i<=n;i++){
		a[i]=-d[i];
	}
	mxa[0]=a[0];
	for(ll i=1;i<=n;i++){
		mxa[i]=max(mxa[i-1],a[i]);
	}
	mxd[n]=d[n];
	for(ll i=n-1;i>=0;i--){
		mxd[i]=max(mxd[i+1],d[i]);
	}
	mxb[n]=b[n]+mxd[n];
	for(ll i=n-1;i>=0;i--){
		mxb[i]=max(mxb[i+1],b[i]+mxd[i]);
	}
	ll ans=-inf;
	for(ll j=0;j<=n;j++){
			ans=max(ans,mxa[j]-b[j]+mxb[j]);
	}
	cout<<sum-ans;
}




















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

int main() {
    using namespace std;
    unsigned long X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<unsigned long> A(X), B(Y), C(Z);
    for(auto &i : A)cin >> i;
    for(auto &i : B)cin >> i;
    for(auto &i : C)cin >> i;
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());

    vector<unsigned long> ans;
    for(unsigned long i = 1; i <= X; ++i)
        for(unsigned long j = 1, ij = i; j <= Y && ij <= K; ++j, ij += i)
            for(unsigned long k = 1, ijk = ij; k <= Z && ijk <= K; ++k, ijk += ij)
                ans.push_back(A[i - 1] + B[j - 1] + C[k - 1]);

    partial_sort(ans.begin(), ans.begin() + K, ans.end(), greater<>());
    for_each(ans.cbegin(), ans.cbegin() + K, [](const auto i){cout << i << endl;});
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll MOD = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N;
	int a[100005], b[100005];
	vector<pii> v;

	cin >> N;
	rep(i,N) cin >> a[i], v.emplace_back(a[i], 1);
	rep(i,N) cin >> b[i], v.emplace_back(b[i], -1);

	sort(all(v));

	ll ans = 1, cur = 0;
	for(auto p: v){
		if( cur * p.Y < 0 ) ans = (ans * abs(cur)) % MOD;
		cur += p.Y;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2932
using System;

public class Test
{
	public static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		long ans = (n / 11) * 2;
		if (n % 11 > 6)
		{
			ans += 2;
		}
		else if (n % 11 != 0)
		{
			ans++;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 2648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
char s[maxn];
bool check(int l, int r)
{
	for(int i = l, j = r; i <= j; ++i, --j)
		if(s[i] != s[j])
			return 0;
	return 1;
}
int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	if(check(1, n) && check(1, (n - 1) / 2) && check((n + 3) / 2, n))
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  var s;
  s = new Date(input.split('\n')[0]);
  if(s <= new Date(2019, 3, 30)){
    console.log('Heisei');  
  }else{
    console.log('TBD');  
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7368
package main

import "fmt"

func maxsum(s []int, k int) int {
	maxi := 0
	max := s[0]
	for i, v := range s {
		if max < v {
			maxi = i
			max = v
		}
	}
	for i := 0; i < k; i++ {
		s[maxi] *= 2
	}

	sum := 0
	for _, v := range s {
		sum += v
	}
	return sum
}

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	s := []int{a, b, c}

	fmt.Println(maxsum(s, k))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=100009;
int32_t main(){
	if(fopen("input.txt", "r"))
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ios::sync_with_stdio(0),cin.tie(0);
	int n,d,a,ans=0;
	cin >> n >> d >> a;
	pair <int,int> v[n];
	int x[n+1],y[n+1]={0};
	int p=0;
	for(int i=0;i<n;i++){
		cin >> v[i].f >> v[i].s;
	}
	sort(v,v+n);
	for(int i=0;i<n;i++)x[i]=v[i].f;
	for(int i=0;i<n;i++){
		p-=y[i];
		v[i].s-=p*a;
		if(v[i].s<=0)v[i].s=0;
		int k=v[i].s/a+(v[i].s%a!=0);
		p+=k;
		ans+=k;
		int pos=upper_bound(x,x+n,v[i].f+2*d)-x;
		y[pos]+=k;
	}
	cout << ans;
}

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

char trump;

int to(char ch){
	if(isdigit(ch)){
		return ch-'0';
	}
	else if(ch=='T')return 10;
	else if(ch=='J')return 11;
	else if(ch=='Q')return 12;
	else if(ch=='K')return 13;
	else if(ch=='A')return 14;
	else {
		assert(1);
		return 0;
	}
}

bool bigger(string a,string b){
	if(b=="*")return true;
	if(a[1]==trump&&b[1]!=trump)return true;
	else if(a[1]!=trump&&b[1]==trump)return false;
	else{
		int x,y;
		x = to(a[0]);
		y = to(b[0]);
		return x>y;
	}
}

int solve(vector<string> v,int led){
	char ls = v[led][1];
	string maxi = "*";
	int pos = -1;
	rep(i,4){
		if(v[i][1]!=trump&&v[i][1]!=ls)continue;
		if(bigger(v[i],maxi)){
			maxi = v[i];
			pos = i;
		}
	}
	return pos;
}

int main(){
	while(cin>>trump&&trump!='#'){
		int led = 0;
		string str[4][13];
		rep(i,4)rep(j,13)cin>>str[i][j];
		
		int ns=0,ew=0;
		rep(i,13){
			vector<string> v;
			rep(j,4)v.pb(str[j][i]);
			int win = solve(v,led);
			if(win%2==0)ns++;
			else ew++;
			led = win;
		}
		
		if(ns>ew)cout<<"NS "<<ns-6<<endl;
		else cout<<"EW "<<ew-6<<endl;
	}
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

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

    int n; cin >> n;
    repr(i, 1, 10) repr(j, 1, 10){
        if(i*j == n){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";

    return 0;
} 


Measured memory_bytes: 256
#include<stdio.h>
#define N 1201

int main(){
  char str[N];
  int i=0,j;
  int number[26];
  char Eng[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  int num;
  for(j=0;j<26;j++){
    number[j]=0;
  }  
  
  while(1){
    if(scanf("%c",&str[i])==EOF)break;
    if('A'<=str[i]&&str[i]<='Z'){
      str[i]=str[i]+('a'-'A');
    }
    num=str[i] - 'a';
    number[num]++;
    i++;
  }

  for(i=0;i<26;i++){
    printf("%c : %d\n",Eng[i],number[i]);
  }

  return 0;
}

Measured memory_bytes: 540
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    A, B = map(int, rl().split())
    
    for i in range(A, B + 1):
        if i % K == 0:
            print('OK')
            exit()
    print('NG')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  double d;
  int ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++){
    int x, y;
    cin >> x >> y;
    double v = pow(x, 2) + pow(y, 2);
    double k = sqrt(v);
    if (k <= d) {
      ans++;
    }
  } 
  cout << ans << endl;
}

Measured memory_bytes: 3712
import java.util.*;class Main{public static void main(String[]z){int n,r,m,p;for(Scanner s=new Scanner(System.in);(n=s.nextInt())+(r=s.nextInt())>0;System.out.println(n-p)){int[][]a=new int[r][2];for(m=r;m-->0;a[m][1]=s.nextInt())a[m][0]=s.nextInt()-1;for(m=p=0;m<r;++m)if(p<a[m][1])p+=a[m][0];else if(p<a[m][0]+a[m][1])p-=a[m][1];}}}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+5;
int a[maxn];
int b[maxn];
int main()
{
	int flag=1;
	string s;
	string t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	{
		int mid1,mid2;
		mid1=s[i]-'a';
		mid2=t[i]-'a';
		a[mid1]++;
		b[mid2]++;
	}
	sort(a,a+26);
	sort(b,b+26);
	for(int i=0;i<26;i++)
	{
		if(a[i]!=b[i])
		{
			flag=0;
			break;
		}
	}
	if(flag)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

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

vector<double> p(3000);
int n; 
double tb[3000][3000];
bool v[3000][3000];
 
double dp(int i, int amt){
	if(i == n){
		if(amt > n/2) return 1;
		else return 0;	
	}
	
	if(v[i][amt]) return tb[i][amt];
	
	v[i][amt] = true;
	return tb[i][amt] = dp(i+1, amt+1)*p[i]+
						dp(i+1, amt)*(1-p[i]);
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	memset(v, false, sizeof(v));
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> p[i];
	}
	
	printf("%.10f", dp(0,0));
	
	return 0;
}

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


int main(){


    int n, t, mat, mit, abt, i;

    int ma = -10000000;

    int mi = 10000000;


    vector<int> a;

 
    cin >> n;


    for( i = 1 ; i < n + 1 ; i = i + 1 ){

         cin >> t;

         a.push_back(t);

         if( t > ma ){

             ma = t;

             mat = i;

             }

         else if( t < mi ){

                  mi = t;

                  mit = i;

                  }

         }


    if( mi >= 0 ){

        cout << n - 1 << endl;


        for( i = 1 ; i < n ; i = i + 1 ){

             cout << i << " " << i + 1 << endl;

             }

        }
        

    else if( ma <= 0 ){

             cout << n - 1 << endl;


             for( i = n ; 1 < i ; i = i - 1 ){

                  cout << i << " " << i - 1 << endl;

                  }

             }

    
    else{

           if( ma > -mi ){

               cout << 2 * n - 1 << endl;


               for( i = 1 ; i < n + 1 ; i = i + 1 ){

                    cout << mat << " " << i << endl;

                    }
 
  
               for( i = 1 ; i < n ; i = i + 1 ){

                    cout << i << " " << i + 1 << endl;

                    }

               }

           else{ 

                 cout << 2 * n - 1 << endl;


                 for( i = 1 ; i < n + 1 ; i = i + 1 ){

                      cout << mit << " " << i << endl;

                      }


                 for( i = n ; 1 < i ; i = i - 1 ){

                      cout << i << " " << i - 1 << endl;

                      }

                 }

            } 


    return 0;


    }

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		string h = s.substr(0, 2);
		if(h == ">'") {
			s += "!";
			if(s.find('#') != string::npos && s.find('=') != string::npos) {
				int pos = s.find('#');
				int size = pos-2;
				REP(i, pos-2) {
					if(s[i+2] == s[i+pos+1] && s[i+2] == '=') {

					} else {
						cout << "NA" << endl;
						goto next;
					}
				}
				if(s[pos+size+1] == '~' && s[pos+size+2] == '!') {
					cout << "A" << endl;
					goto next;
				} else {
					cout << "NA" << endl;
					goto next;
				}
				 
			} else {
				cout << "NA" << endl;
				goto next;
			}			
		} else if(h == ">^") {
			s += "!!";
			int b = 2;
			bool flag = false;
			while(s.substr(b, 2) == "Q=") {
				b += 2;
				flag = true;
			}

			if(s.substr(b, 2) == "~~" && s.substr(b+2, 2) == "!!" && flag) {
				cout << "B" << endl;
				goto next;
			} else {
				cout << "NA" << endl;
				goto next;
			}
		} else {
			cout << "NA" << endl;
			goto next;
		}
		next:;
	}

	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        for(int i = 0; ; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if( (a == 0)&&(b == 0)){
                break;
            }
            if(a > b){
                System.out.println(b + " " + a);
            }else{
                System.out.println(a + " " + b);
            }
        }
    }
}



Measured memory_bytes: 35060
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;
signed main() {
    string s;
    int ansa=0;
    int ansb=0;
    cin>>s;
    ansa+=s[0]-'0'-1;
    ansb+=s[0]-'0';
    for(int i=1;i<s.size();i++){
        ansa+=9;
        ansb+=s[i]-'0';
    }
    if(ansa<ansb) cout<<ansb;
    else cout<<ansa<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>

const int MAXN = 100000;

int h[MAXN];
int cost[MAXN];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &h[i]);

    cost[0] = 0;

    for (int i = 1; i < n; ++i)
    {
        cost[i] = std::abs(h[i] - h[i - 1]) + cost[i - 1];
        for (int j = i - 1; j >= 0 && j >= i - k; --j)
            cost[i] = std::min(cost[i], std::abs(h[i] - h[j]) + cost[j]);
    }

    printf("%d\n", cost[n - 1]);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main() {
	int t, i, j, k;
	int a, b, c ,F=0;
	char A[100];
	
	cin >> A;

	cout << A[0] << A[1] << A[2] << A[3] << A[4] << " "
		<< A[6] << A[7] << A[8] << A[9] << A[10] << A[11] << A[12] << " "
		<< A[14] << A[15] << A[16] << A[17] << A[18]
		
		
		
		<< endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int N = fs.nextInt();
		int K = fs.nextInt();
		boolean[] sunuke = new boolean[N];

		for(int i = 0; i < N; i++) {
			sunuke[i] = false;
 		}
		for(int i = 1; i <= K; i++) {
			int d = fs.nextInt();
			for(int j = 0; j < d; j++) {
				sunuke[fs.nextInt() - 1] = true;
			}
		}
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(!sunuke[i]) count++;
 		}
		System.out.println(count);
	}

}


Measured memory_bytes: 26468
fn main() {
    let n = read::<usize>();
    let mut nums = vec![vec![0; 10]; 10];
    for i in 1..n+1 {
        let a: Vec<char> = i.to_string().chars().collect();
        let ini: usize = a[0].to_digit(10).unwrap() as usize;
        let last: usize = a[a.len()-1].to_digit(10).unwrap() as usize;
        nums[ini][last] += 1;
    }

    let mut ret = 0;
    for i in 1..10 {
        for j in 1..10 {
            ret += nums[i][j] * nums[j][i]
        }
    }

    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 110
using namespace std;

int n,cnt[MAXN];

int main(){
	scanf("%d",&n);
	int d=0;
	for(int i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		if(t>d) d=t;
		cnt[t]++;
	}
	int minl=d;
	for(int i=0;i<=d;i++){
		int l=max(i,d-i);
		if(l<minl) minl=l;
		if(!cnt[l]){
			puts("Impossible");
			return 0;
		}
		cnt[l]--;
	}
	for(int i=1;i<=minl;i++)
		if(cnt[i]){
			puts("Impossible");
			return 0;
		}
	puts("Possible");
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>

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

using namespace std;

char goal[3][3],gx,gy;

char T[3][3],F[3][3],R[3][3]; // top, front, right

int hstar(int ex,int ey,int gx,int gy){
	int cnt=0;
	rep(i,3) rep(j,3) if(!(i==ey && j==ex) && T[i][j]!=goal[i][j]) cnt++;
	return max(cnt,abs(ex-gx)+abs(ey-gy));
}

int ub;
bool dfs(int t,int ex,int ey,int pre){ // 経過ターン, スペースの位置, 直前移動した方向
	bool end=true;
	rep(i,3) rep(j,3) if(!(i==ey && j==ex) && T[i][j]!=goal[i][j]) end=false;
	if(end) return true;

	if(t+hstar(ex,ey,gx,gy)>ub) return false;

	char tmp1,tmp2,tmp3;
	// (ex,ey-1)
	if(ey>0 && pre!=1){
		tmp1=T[ey][ex]=F[ey-1][ex];
		tmp2=F[ey][ex]=T[ey-1][ex];
		tmp3=R[ey][ex]=R[ey-1][ex];
		if(dfs(t+1,ex,ey-1,0)) return true;
		F[ey-1][ex]=tmp1;
		T[ey-1][ex]=tmp2;
		R[ey-1][ex]=tmp3;
	}
	// (ex,ey+1)
	if(ey<2 && pre!=0){
		tmp1=T[ey][ex]=F[ey+1][ex];
		tmp2=F[ey][ex]=T[ey+1][ex];
		tmp3=R[ey][ex]=R[ey+1][ex];
		if(dfs(t+1,ex,ey+1,1)) return true;
		F[ey+1][ex]=tmp1;
		T[ey+1][ex]=tmp2;
		R[ey+1][ex]=tmp3;
	}
	// (ex-1,ey)
	if(ex>0 && pre!=3){
		tmp1=T[ey][ex]=R[ey][ex-1];
		tmp2=F[ey][ex]=F[ey][ex-1];
		tmp3=R[ey][ex]=T[ey][ex-1];
		if(dfs(t+1,ex-1,ey,2)) return true;
		R[ey][ex-1]=tmp1;
		F[ey][ex-1]=tmp2;
		T[ey][ex-1]=tmp3;
	}
	// (ex+1,ey)
	if(ex<2 && pre!=2){
		tmp1=T[ey][ex]=R[ey][ex+1];
		tmp2=F[ey][ex]=F[ey][ex+1];
		tmp3=R[ey][ex]=T[ey][ex+1];
		if(dfs(t+1,ex+1,ey,3)) return true;
		R[ey][ex+1]=tmp1;
		F[ey][ex+1]=tmp2;
		T[ey][ex+1]=tmp3;
	}
	return false;
}

int main(){
	for(int ex,ey;scanf("%d%d",&ex,&ey),ex;){
		ex--; ey--;
		rep(i,3) rep(j,3) {
			scanf(" %c",goal[i]+j);
			if(goal[i][j]=='E') gx=j, gy=i;
			T[i][j]='W';
			F[i][j]='R';
			R[i][j]='B';
		}

		for(ub=(abs(ex-gx)+abs(ey-gy))%2;ub<=30&&!dfs(0,ex,ey,-1);ub+=2);

		printf("%d\n",ub<=30?ub:-1);
	}

	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
int dp[1000000];
int a[1000000];
int getans(int i,int n)
{
    if(i==n)
    {
        return 0;
    }
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    int cost=abs(a[i]-a[i+1])+getans(i+1,n);
    if(i+2<=n)
    {
         cost=min(cost,abs(a[i]-a[i+2])+getans(i+2,n));
        //return cost;
    }
    return dp[i]=cost;
 // return dp[i];
}
int main()
{
    int n;
    cin>>n;
   // int a[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    int ans=getans(1,n);
    cout<<ans<<endl;
}


Measured memory_bytes: 14096
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int x;
    cin >> x;
    if(x < 600) cout << 8 << endl;
    else if(x < 800) cout << 7 << endl;
    else if(x < 1000) cout << 6 << endl;
    else if(x < 1200) cout << 5 << endl;
    else if(x < 1400) cout << 4 << endl;
    else if(x < 1600) cout << 3 << endl;
    else if(x < 1800) cout << 2 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
    int h,w,i,j;

    while(1){
        scanf("%d %d",&h,&w);
        if(h==0&&w==0) break;

        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if(i%2==0){
                    if(j%2==0)
                        printf("#");
                    else printf(".");
                }
                if(i%2!=0){
                    if(j%2==0)
                        printf(".");
                    else printf("#");
                }
            }printf("\n");
        }printf("\n");
    }

    return 0;
}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,K;
    cin >> N >> K;
    vector<pll> dt(N);
    REP(i, N){
        cin >> dt[i].se >> dt[i].fi;
    }

    auto calc = [](ll t, int x){return t+(ll)x*x;};

    RSORT(dt);
    priority_queue<ll,vector<ll>, greater<ll>> q;
    map<int,int> num;
    ll total = 0;

    REP(i, K){
        total += dt[i].fi; //上からK個取ったときの最大値
        if(num[dt[i].se] == 0)
            num[dt[i].se]++;
        else
            q.push(dt[i].fi); //同じ種類が二個目以上のときキューに入れる  

    }
    ll ans = calc(total, num.size());

    //残りのN-K個をチェック
    if(!q.empty())
    for (int i = K; i < N; i++) {
        if(num[dt[i].se]!=0)continue;
        ll f = q.top();q.pop();
        total -= f;
        total += dt[i].fi;
        num[dt[i].se]++;
        chmax(ans, calc(total, num.size()));
    }   
    pr(ans);
}

Measured memory_bytes: 5244
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    rep(i,n){
        int ans = 0;
        int x = sqrt(i+1);
        for(int j = 1;j <=x;j++){
            for(int k = j;k <= x;k++){
                for(int l = k;l <= x;l++){
                    if(j*j+k*k+l*l+j*k+k*l+l*j == i+1){
                        if(j==k && k==l)ans++;
                        else if(j!=k && k!=l && l!=j)ans+=6;
                        else ans+=3;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int[] arr = new int[count+1];
        for(int i=1;i<=count;i++){
            arr[i] = sc.nextInt();
        }
        for(int i=count/2;i>0;i--){
            MaxHeap(arr,i);
        }

        for(int i=1;i<=count;i++){
            System.out.print(" "+arr[i]);
        }
        System.out.println();

    }
/*
     3
  11     6
9   4
 */
    public static void MaxHeap(int[] arr,int i){//3 4 6 9 11
       int left = 2*i;
       int right = 2*i+1;
       int largest;
       if(left<=arr.length-1&&arr[left]>arr[i]){
           largest = left;
       }else{
           largest = i;
       }
       if(right<=arr.length-1&&arr[right]>arr[largest]){
           largest = right;
       }
       if(largest!=i){
           swap(arr,i,largest);
           MaxHeap(arr,largest);
       }

    }

    public static void swap(int a[], int i, int largest){
        int temp = a[i];
        a[i] = a[largest];
        a[largest] = temp;
    }


}



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


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

	int x;
	if ( 1.0*S / N - floor(1.0*S / N) > ceil(1.0*S / N) - 1.0*S / N) {
		x = ceil(1.0*S / N);
	}
	else {
		x = floor(1.0*S / N);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += (a[i] - x)*(a[i] - x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arrA = new int[n];
		for (int i = 0; i < n; i++) {
		    arrA[i] = sc.nextInt();
		}
		int[] arrB = new int[n];
		for (int i = 0; i < n; i++) {
		    arrB[i] = sc.nextInt();
		}
		int[] arrC = new int[n];
		for (int i = 0; i < n; i++) {
		    arrC[i] = sc.nextInt();
		}
		Arrays.sort(arrA);
		Arrays.sort(arrB);
		Arrays.sort(arrC);
		int[] baSize = new int[n];
		int left = 0;
		for (int i = 0; i < n; i++) {
		    if (arrA[left] < arrB[i]) {
		         baSize[i] = left + 1;
		    }
		    while (left + 1 < n && arrA[left + 1] < arrB[i]) {
		        left++;
		        baSize[i] = left + 1;
		    }
		}
		int[] bcSize = new int[n];
		int right = n - 1;
		for (int i = n - 1; i >= 0; i--) {
		    if (arrB[i] < arrC[right]) {
		        bcSize[i] = n - right;
		    }
		    while(right - 1 >= 0 && arrB[i] < arrC[right - 1]) {
		        right--;
		        bcSize[i] = n - right;
		    }
		}
		long total = 0;
		for (int i = 0; i < n; i++) {
		    total += (long)baSize[i] * bcSize[i];
		}
       System.out.println(total);
	}
}


Measured memory_bytes: 92644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	if(n==1){
		puts("Hello World");
	}else{
		ll a,b;
		scanf("%lld%lld",&a,&b);
		printf("%lld",a+b);
	}
}

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


public class Main {

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

		int N = Integer.parseInt(br.readLine());
		for (int i = 0 ; i < N ; i++) {
			String[] balls = br.readLine().split("\\s");
			int max1 = 0, max2 = 0;
			boolean isFault = false;
			for (int j = 0 ; j < 10 ; j++) {
				int num = Integer.parseInt(balls[j]);
				if (num > max1) max1 = num;
				else if (num > max2) max2 = num;
				else isFault = true;
			}
			if (isFault) System.out.println("NO"); else System.out.println("YES");
		}

	}
}

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

using namespace std;

int main()
{
    int r,d,x;  cin >> r >> d >> x;
    for(int i = 0;i<10;i++){
        cout << x * r - d << '\n';
        x = x*r - d;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int n,l;
	vector<string>vec;
	cin>>n>>l;
	fore(i,0,n){
		string t;
		cin>>t;
		vec.push_back(t);
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<n;i++){
		cout<<vec[i];
	}
	cout<<endl;
}

Measured memory_bytes: 256
from itertools import permutations
def dist(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
tot = 0
cnt = 0
for z in permutations(range(N)):
    cnt += 1
    for i in range(1,N):
        tot += dist(X[z[i]],X[z[i-1]])
print(tot/cnt)

Measured memory_bytes: 40812
#include <stdio.h>

#define MAX (105)

void search(int now_h, int now_w);

int h, w;
char map[MAX][MAX];
char map_flag[MAX][MAX];

int main(void)
{
    int i, j;
    
    while (1){
        scanf("%d %d", &h, &w);
        if ((h != 0) && (w != 0)){
            for (i = 0; i < MAX; i++){
                for (j = 0; j < MAX; j++){
                    map[i][j] = '\0';
                    map_flag[i][j] = '0';
                }
            }
            for (i = 0; i < h; i++){
                scanf("%s", map[i]);
            }
            search(0, 0);
        }
        else {
            break;
        }
    }
    
    return (0);
}

void search(int now_h, int now_w)
{
    if (map_flag[now_h][now_w] == '1'){
        printf("LOOP\n");
        return;
    }
    if (map[now_h][now_w] == '.'){
        printf("%d %d\n", now_w, now_h);
        return;
    }
    if (map[now_h][now_w] == '>'){
        map_flag[now_h][now_w] = '1';
        search(now_h, now_w + 1);
    }
    else if (map[now_h][now_w] == '<'){
        map_flag[now_h][now_w] = '1';
        search(now_h, now_w - 1);
    }
    else if (map[now_h][now_w] == '^'){
        map_flag[now_h][now_w] = '1';
        search(now_h - 1, now_w);
    }
    else if (map[now_h][now_w] == 'v'){
        map_flag[now_h][now_w] = '1';
        search(now_h + 1, now_w);
    }
    
}

Measured memory_bytes: 0