akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const ld PI=3.141592;
int main(){
    ld r;cin>>r;
    cout<<fixed<<setprecision(10);
    cout<<2*r*PI<<endl;
}

Measured memory_bytes: 3792
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include<limits.h>


#define eps 1e-8
#define PI 3.141592653589793
#define bsize 512

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define bs 1000000007

using namespace std;

int longestCommonSubsequence(string s1, string s2, vector<vector<int>>& dp) 
{
    for (int i = 1; i <= s1.size(); i++) 
    {
        for (int j = 1; j <= s2.size(); j++) 
        {
            if (s1[i-1] == s2[j-1]) 
                dp[i][j] = dp[i-1][j-1] + 1;

            dp[i][j] = max({dp[i][j], dp[i][j-1], dp[i-1][j]});
        }
    }
    return dp[s1.size()][s2.size()];
}

int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    
    string s1, s2; 
    cin >> s1 >> s2;

    vector<vector<int>> dp(s1.size()+1, vector<int>(s2.size()+1, 0));
    int count = longestCommonSubsequence(s1, s2, dp);   // This will give count of lcs and change the dp vector

    string s = "";
    int i = s1.size(), j = s2.size();
    while (i > 0 && j > 0) 
    {
        if (dp[i-1][j-1] + 1 == dp[i][j] && dp[i-1][j] + 1 == dp[i][j] && dp[i][j-1] + 1 == dp[i][j]) 
        {
            i--; 
            j--; 
            s = s1[i] + s; //As we are travelling backward reverse the string
        }
        else if (dp[i][j-1] > dp[i-1][j]) 
            j--;
        else
            i--;
    }
    cout << s << endl;

    return 0;
}

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

const int INF = 1e9;
const ll LINF = 1e18;


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

    if (h == 1 || w == 1)
        cout << 1 << endl;
    else
        cout << (h * w + 1) / 2;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;






int main()
{
	string s,t;
	cin >> s;
	t = s;
	for (int i = 0; i < s.size(); i++) {
		t[i] = s[s.size() - i-1];
	}
	cout << t << endl;


}

Measured memory_bytes: 1180
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

// ------------ combination mod ------------ 
ll comb2(ll n) {
    if (n < 2) return 0;
    return (ll) n * (n-1) / 2;
}


int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  map<int, int> mp;
  rep(i, n){
    mp[a[i]]++;
  }
  ll ans = 0;
  for(pi x: mp){
    ans += comb2(x.second);
  }

  rep(i, n){
    ll c_ans = ans;
    if (mp[a[i]] >= 2) c_ans -= (mp[a[i]] - 1);
    cout << c_ans << endl;
  }

  return 0;
}

Measured memory_bytes: 9856
#include <stdio.h>

int main()
{
    int n,a[100000],i = 0,j,pm = 0,ans = 1;

    scanf("%d",&n);
    for (i = 0; i < n; i++)scanf("%d",&a[i]);

    for (i = 0; i < n - 1; i++)
    {
        if(pm == 2)
        {
            if(a[i] < a[i + 1])
            {
                pm = 0;
                ans++;
            }
        }
        else if(pm == 1)
        {
            if(a[i] > a[i + 1])
            {
                pm = 0;
                ans++;
            }
        }
        else
        {
            if(a[i] > a[i + 1])pm = 2;
            else if(a[i] == a[i + 1])pm = 0;
            else pm = 1;
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 512
S = input()
N = len(S)

i = 0
p = ''
ans = 0
while i < N:
    if p == S[i]:
        if i+1 < N:
            p = S[i:i+2]
            i += 1
        else:
            break
    else:
        p = S[i]
    ans += 1
    i += 1

print(ans)

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

long long int extgcd(long long int a, long long int b, long long int& x, long long int& y)
{
  long long int d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

long long int mod_inverse(long long int a, long long int m)
{
  long long int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}							

int main()
{
  const long long int p = 9999991LL;
  const long long int q = 9999973LL;
  
  int N;
  while (cin >> N) {
    long long int Xp = 0, Xq = 0;
    for (int i = 0; i < N; ++i) {
      int o, Y;
      scanf("%d %d", &o, &Y);
      if (o == 1) {
	Xp = (Xp + Y) % p;
	Xq = (Xq + Y) % q;
      } else if (o == 2) {
	Xp = (Xp + p - Y) % p;
	Xq = (Xq + q - Y) % q;
      } else if (o == 3) {
	Xp = (Xp * Y) % p;
	Xq = (Xq * Y) % q;
      } else {
	Xp = (Xp * mod_inverse(Y, p)) % p;
	Xq = (Xq * mod_inverse(Y, q)) % q;
      }
    }

    long long int x, y;
    extgcd(p, q, x, y);
    long long int ans = (Xp * q * y + Xq * p * x) % (p * q);

    if (ans < (1LL << 31))
      ans = ans + p*q;
    if (ans >= (1LL << 31))
      ans = ans - p*q;

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

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  int c0=0,c1=0,c2=0,c3=0;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    if(s.compare("AC")==0) c0++;
   else if(s.compare("WA")==0) c1++;
       else if(s.compare("TLE")==0) c2++;
       else if(s.compare("RE")==0) c3++;
  }
  cout << "AC x " << c0<< endl;
    cout << "WA x " << c1<< endl;
    cout << "TLE x " << c2<< endl;
    cout << "RE x " << c3<< endl;
  return 0;
}

Measured memory_bytes: 3612
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    var s = readLine()!! 
    val k = readLine()!!.toInt()

    var point = s[k-1]

    var list = mutableListOf<Char>()


    for(i in 0..n-1){
        if(s[i] != point){
            list.add('*')
        }
        else{
            list.add(s[i])

        }

    }

for(i in 0..n-1){
    print(list[i])
}
println()
}

Measured memory_bytes: 31812
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
string ring;
int l,cou;
int main(){
    cin>>ring>>l;
    for(int i=0;i<l;i++){
        string a,b,c;
        cin>>a;
        b.resize(a.size()*2);
        c.resize(ring.size());
        for(int j=0;j<a.size()*2;j++){
            b[j]=a[j%a.size()];
        }
        for(int j=0;j<a.size()*2-ring.size();j++){
            for(int k=0;k<ring.size();k++){
                c[k]=b[j+k];
            }
            if(ring==c){
                cou++;
                break;
            }
        }
    }
    cout<<cou<<endl;
return 0;
}

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

using namespace std;

const int NMAX = 200000 + 1;
int ar1[NMAX] = {};
int ar2[NMAX] = {};

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


    set<int> st1, st2;
    while (m--) {
        int a, b;
        cin >> a >> b;
        if (a == 1) ar1[b] = 1;
        if (b == n) ar2[a] = 1;
    }

    bool flag = false;
    for (int i = 2; i < n; ++i) {
        if (ar1[i] == 1 and ar2[i] == 1) {
            flag = true;
            break;
        }
    }

    if (flag) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

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

using ll = long long;


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

    sort(A.begin(), A.end(), std::greater<int>());

    bool result = true;
    int check = accumulate(A.begin(), A.end(), 0);
    for(int i=0; i<M; i++) {
        if(A[i]*(4*M) < check) {
            result = false;
            break;
        }
    }

    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc164A
    {
        public static void Main()
        {
            var sw = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            Console.WriteLine(sw[0] <= sw[1] ? "unsafe" : "safe");
        }
    }
}


Measured memory_bytes: 19032
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
	int w, h, num, x, y, a, i;
	cin >> w >> h >> num;
	int xmin = 0, xmax = w, ymin = 0, ymax = h;
	for (i = 0; i < num; i++) {
		scanf("%d%d%d", &x, &y, &a);
		switch (a) {
		case 1:
			xmin = max(xmin, x);
			break;
		case 2:
			xmax = min(xmax, x);
			break;
		case 3:
			ymin = max(ymin, y);
			break;
		case 4:
			ymax = min(ymax, y);
			break;
		}
	}
	if (xmax <= xmin || ymax <= ymin)
		printf("0\n");
	else
		cout << (xmax - xmin) * (ymax - ymin) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int prime[300001];

int main() {
	memset(prime, -1, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= 150000; i++) {
		if (prime[i] == 0) continue;
		for (int j = 2; i*j <= 300000; j++) {
			prime[i*j] = 0;
		}
	}
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		int count = 0;
		for (int i = n+1; i <= 2*n; i++) {
			if (prime[i] == 0) continue;
			count++;
		}
		cout << count <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String str = sc.nextLine();
		String sl[] = str.split(" ");
		
		long n = Long.parseLong(sl[0]);
		long yen = Long.parseLong(sl[1]);
		
		for(long x = 0; x <= n; x++)
		{
			long y = (yen - 1000 * n - 9000 * x) / 4000;
			long z = n - x - y;
			if(x + y + z == n && 1000 * z + 5000 * y + 10000 * x == yen && x >= 0 && y >= 0 && z >= 0)
			{
				System.out.printf("%d %d %d", x, y, z);
				System.exit(0);
			}
		}

		System.out.printf("%d %d %d", -1, -1, -1);
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

struct LCA {
    vector<vector<int>> par;
    vector<int> d;
    int n;
    LCA(vector<vector<int>> graph, int root) {
        n = graph.size();
        par.resize(n, vector<int>(30));
        d.resize(n, 0);
        function<void(int, int, int)> dfs = [&](int c, int p, int depth) {
            d[c] = depth;
            par[c][0] = p;
            for (auto ch : graph[c]) {
                if (ch != p) dfs(ch, c, depth + 1);
            }
        };
        dfs(0, 0, 0);
        for (int j = 1; j < 30; j++) {
            REP(i, n) { par[i][j] = par[par[i][j - 1]][j - 1]; }
        }
    }
    int getdistance(int u, int v) { return (d[u] + d[v]) - 2 * (d[query(u, v)]); }
    int query(int u, int v) {
        if (d[u] > d[v]) {
            swap(u, v);
        }
        for (int i = 29; 0 <= i; i--) {
            if (d[u] <= d[par[v][i]]) {
                v = par[v][i];
            }
        }
        /* LCA */
        for (int i = 29; 0 <= i; i--) {
            if (par[v][i] != par[u][i]) {
                v = par[v][i];
                u = par[u][i];
            }
        }
        if (u == v) {
            return u;
        } else {
            return par[v][0];
        }
    }
};

struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
int n, m;
vector<vector<int>> graph;
void aoj(vector<int> bs) {
    REP(i, bs.size() - 1) { cout << bs[i] << " "; }
    cout << bs[bs.size() - 1] << endl;
}

signed main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = n;
    REP(i, n) {
        if (s == t) {
            cout << ans << endl;
            return 0;
        } else {
            ans++;
        }
        t.pop_back();
        reverse(s.begin(), s.end());
        s.pop_back();
        reverse(s.begin(), s.end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long

using namespace std;

int main() {
    pair<int,int> x, y;
    cin >> x.first >> y.first;
    set<int> a, b, c;
    a = { 1,3,5,7,8,10,12 }; // 1
    b = { 4,6,9,11 }; // 2
    c = { 2 }; // 3
    if (a.find(x.first) != a.end())
    {
        x.second = 1;
    }
    else if (b.find(x.first) != b.end())
    {
        x.second = 2;
    }
    else
    {
        x.second = 3;
    }


    if (a.find(y.first) != a.end())
    {
        y.second = 1;
    }
    else if (b.find(y.first) != b.end())
    {
        y.second = 2;
    }
    else
    {
        y.second = 3;
    }


    if (x.second == y.second)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int W, H;
vector<vector<char>> s;

// cost[y][x] = スタートから(x, y)までの最短経路
vector<vector<int>> cost;
int bfs(){
    // 移動可能なマスをループで簡単に列挙
    int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

    // 座標をpair(y, x)でもってqueueに入れる
    queue<pair<int, int>> que;
    // スタートは(0, 0) (0-indexedに読み替える)
    que.push(make_pair(0, 0));
    cost[0][0] = 0;

    while(!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        if(p == make_pair(H-1, W-1)){
            // ゴールに到達
            return cost[p.first][p.second];
        }
        for(int i = 0; i < 4; i++) {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            // 壁orマスの外
            if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
            if(s[ny][nx] == '#') continue;
            // 既に探索済み
            if(cost[ny][nx] != -1) continue;

            cost[ny][nx] = cost[p.first][p.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }
    return -1;
}

int main() {
    cin >> H >> W;
    s = vector<vector<char>>(H, vector<char>(W));
    int white = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> s[i][j];
            if(s[i][j] == '.') white++;
        }
    }
    cost = vector<vector<int>>(H, vector<int>(W, -1));
    int min_cost = bfs();
    if(min_cost == -1) cout << -1 << endl;
    else cout << white - (min_cost+1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, c, d, ans;
	/*入力*/
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	/*計算*/
	d = a - b;
    ans = c - d;

	if (ans > 0)
		printf("%d\n", ans);

	else {
		
		printf("0\n");
	}


	return 0;
}
	



Measured memory_bytes: 128
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<29
lINF = 1<<35

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

def main():
    a,b,h,m = readInt()
    v1 = 30
    v2 = 6
    r1 = h * v1 + (m / 60) * v1
    r2 = m * v2
    r = abs(r1-r2)
    if r>180:
        r = 360 - r
    ans = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(r)))
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9544
Scanf.scanf "%d" (fun n ->
    let k = (match n mod 10 with
    | 2 | 4 | 5 | 7 | 9 -> "hon"
    | 0 | 1 | 6 | 8 -> "pon"
    | 3 -> "bon"
    | _ -> failwith "??")
    in
    Printf.printf "%s\n" k
)

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

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

ll pow5(ll x){
    ll xx=x*x;
    ll xxxx=xx*xx;
    return xxxx*x;
}

int main(){
    ll x;
    cin >> x;
    ll i=0;
    repi(i,-120,121){
        ll a=pow5(i);
        repi(j,-120,121){
            ll b=pow5(j);
            if(a-b==x){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  ll mn = 1;
  ll ans = 0;
  rep(i, n) {
    if(A[i] == mn) mn++;
    ll tmp = (A[i]-1)/mn;
    ans += tmp;
    if(tmp) A[i] = 1;
    mn = max(A[i]+1, mn);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3984
a, b, c, d  = map(int,input().split())
def divbyk(k):
    return    b//k-(a-1)//k

def gcd(x,y):
    n = min(x,y)
    m = max(x,y)
    if n == 0:
        return m
    else:
        return round(gcd(n,m-(m//n)*n))

ans = b-(a-1) - divbyk(c) - divbyk(d) + divbyk(c*d//gcd(c,d))
print(int(ans))

Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    lateinit var calc: (IntArray) -> Unit

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val D = sc.next().toInt()
        val c = IntArray(26) { sc.next().toInt() }
        val s = Array(D) { IntArray(26) { sc.next().toInt() } }
//        val t = IntArray(D) { sc.next().toInt() }
//        val M = sc.next().toInt()
//        val dq = Array(M) { Pair(sc.next().toInt(), sc.next().toInt()) }

        // calc result
        calc = { t: IntArray ->
            val d = IntArray(26)
            var ans = 0L
            for (i in 0 until D) {
                ans += s[i][t[i] - 1]
                d[t[i] - 1] = i + 1
                for (j in 0 until 26) {
                    ans -= c[j] * (i + 1 - d[j])
                }
                pw.println(ans)
            }
        }

        val ans = (0 until D).map { it % 26 + 1 }.toIntArray()
        pw.println(ans.joinToString("\n"))

        //calc(ans)
    }
}


Measured memory_bytes: 47124
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    ll n,k;
    cin>>n>>k;

    vl v(n);

    forn(i,0,n)
    {cin>>v[i];}

    sort(all(v));

    ll mini = inf;

    for(int i = 0; i <= n-k; i++)
    {
        mini = min(mini,(v[i+k-1] - v[i]));
    }

    cout<<mini;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int A[1000000],n;

//線形探索
int binarySearch(int key){
	int left=0;
	int right=n;
	int mid;
	while(left<right){
		mid=(left+right)/2;
		if(key==A[mid])return 1;	//keyを発見
		if(key>A[mid])left=mid+1;	//後半を探索
		else if(key<A[mid])right=mid;//前半を探索
	}
	return 0;
}

int main(){
	int i,q,k,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&k);
		if(binarySearch(k))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 980
import numpy as np


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    N = ii()
    S = input()
    e = 0
    for v in S:
        if v == 'E': e += 1

    min_n_turn = N
    ec = 0
    for i in range(N):
        ew = (N - i - 1) - (e - ec - int(S[i] == 'E'))
        n_turn = N - 1 - ec - ew
        if S[i] == 'E':
            ec += 1
        # print(ec, ew, n_turn)
        min_n_turn = min(min_n_turn, n_turn)

    return min_n_turn

if __name__ == '__main__':
    print(main())

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll N = pow(10, 9);

int main() {
  string ishi;
  int n;
  cin >> n;
  cin >> ishi;
  int rcnt = 0;
  int wcnt = 0;
  rep(i,n) {
    if(ishi.at(i) == 'R') rcnt++;
  }
  rep(i, rcnt){
    if(ishi.at(i) == 'W') wcnt++;
  }
  cout << wcnt;
}

Measured memory_bytes: 3708
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	defer out.Flush()

	var n, m int

	fmt.Fscanf(in, "%d %d\n", &n, &m)

	output := n * n + m * m - n - m

	output /= 2

	fmt.Println(output)





}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define nmax
#define inf
using namespace std;

int main()
{
    int n;
    cin>>n;
    while (n){
        if (n % 10 == 7){
            cout<<"Yes\n";
            return 0;
        }
        n/=10;
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3632
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

using namespace std;

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 305, K = 205, MOD = 998244353;
const ll MX = 1e15;
vector<ii> banned[2][N + N][N + N];
int sq[800005];
int C[2][N + N][N + N];
vector<ii>go[2][2];
void dfs(bool f, int i, int j, int c) {
	if (~C[f][i][j]) {
		assert(C[f][i][j] == c);
		return;
	}
	C[f][i][j] = c;
	if((~C[0][i][j])&&(~C[1][i][j])){
    go[C[0][i][j]][C[1][i][j]].emplace_back(i,j);
	}
	for (auto x : banned[f][i][j]) {
		dfs(f, x.F, x.S, c ^ 1);
	}
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	memset(sq, -1, sizeof sq);
	for (int i = 0; i * i <= 800000; i++)
		sq[i * i] = i;

	int n, d1, d2;
	cin >> n >> d1 >> d2;

	set<ii> st;

	for (int i = 0; i < 2 * n; i++)
		for (int j = 0; j < 2 * n; j++) {
			for (int ii = 0; ii < 2 * n; ii++) {
				int tmp = (ii - i) * (ii - i);
				///tmp + (jj - j) * (jj - j) = d1
				///(jj - j) * (jj - j) = d1 - tmp
				if (d1 >= tmp) {
					int x = d1 - tmp;
					x = sq[x];
					if (~x) {
						///find jj such that (jj - j) = x, jj = x + j
						///or (j - jj) = x, j = jj + x, jj = j - x

						if (j - x < n + n && j - x >= 0)
							banned[0][i][j].pb( { ii, j - x });
						if (j + x < n + n && j + x >= 0)
							banned[0][i][j].pb( { ii, j + x });
					}
				}
				if (d2 >= tmp) {
					int x = d2 - tmp;
					x = sq[x];
					if (~x) {
						///find jj such that (jj - j) = x
						///or (j - jj) = x
						if (j - x < n + n && j - x >= 0)
							banned[1][i][j].pb( { ii, j - x });
						if (j + x < n + n && j + x >= 0)
							banned[1][i][j].pb( { ii, j + x });
					}
				}
			}
		}

	memset(C, -1, sizeof C);
	for (int i = 0; i < n + n; i++)
		for (int j = 0; j < n + n; j++){
			if (C[0][i][j] == -1){
				dfs(0, i, j, 0);
			}
			if (C[1][i][j] == -1){
				dfs(1, i, j, 0);
			}
		}

  int f1 = 0, f2 = 0;

  for(int i = 0; i < 2; i++)
  for(int j = 0; j < 2; j++)
      if(go[i][j].size()>go[f1][f2].size()){
        tie(f1,f2)=tie(i,j);
      }
  go[f1][f2].resize(n*n);
	for (auto x : go[f1][f2])
		cout << x.F << ' ' << x.S << '\n';

	return 0;
}


Measured memory_bytes: 190352
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0){
        c -= b;
        if(c <= 0) break;
        a -= d;
    }

    if(a > c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n;
		int count;

		n = scanner.nextInt();
		while (n != 0) {
			count = 0;
			int change = 1000 - n;
			while (500 <= change) {
				change -= 500;
				count++;
			}
			while (100 <= change) {
				change -=100;
				count++;
			}
			while (50 <= change) {
				change -=50;
				count++;
			}
			while (10 <= change) {
				change -=10;
				count++;
			}
			while (5 <= change) {
				change -=5;
				count++;
			}
			while (1 <= change) {
				change -=1;
				count++;
			}
			System.out.println(count);
			n = scanner.nextInt();
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main{
  public static void heisei(){
    System.out.println("Heisei");
  }

  public static void tbd(){
    System.out.println("TBD");
  }


  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String ss = s.replace("/","");

    if(ss.compareTo("20190430")<=0){
      heisei();
    }else{
      tbd();
    }

  }
}

Measured memory_bytes: 22740
/* 161-B.cpp
 *     Created on : Apr 4, 2020
 *     Time		  : 6:05:04 PM
 *     Author     : null_ptr
 */

#include<bits/stdc++.h>

using namespace std;

#define F_Input freopen("input.in","r",stdin)
#define push emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

template<typename T>
void Swap(T &a,T &b){
a^=b;b^=a;a^=b;}

template<class type>
void show(type name)
{for(auto& nm:name)cerr<<nm<<' ';cerr<<'\n';}

using lint=long long;
using ivec=vector<int>;
using ipair=pair<int,int>;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n,k;
	cin>>n>>k;
	int sum=0,cnt=0;
	ivec nums(n);
	for(int i=0;i<n;++i){
		cin>>nums[i];
		sum+=nums[i];
	}
	
	for(int i=0;i<n;++i)
	{
		if(sum<=nums[i]*4*k)cnt++;
	}
	if(cnt>=k)cout<<"Yes\n";
	else cout<<"No\n";
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m;

int main() {
	while (cin >> n >> m&&n + m) {
		int sum[2] = {};
		int s[2][110];
		REP(i, n) {
			cin >> s[0][i];
			sum[0] += s[0][i];
		}
		REP(i, m) {
			cin >> s[1][i];
			sum[1] += s[1][i];
		}
		P ans = { -1,-1 };
		int k = INF;
		REP(i, n) {
			REP(j, m) {
				if (sum[0] - s[0][i] + s[1][j] == sum[1] - s[1][j] + s[0][i]) {
					if (s[0][i] + s[1][j] < k) {
						ans = { s[0][i],s[1][j] };
						k = s[0][i] + s[1][j];
					}
				}
			}
		}
		if (ans.first == -1)cout << -1 << endl;
		else cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 3036
class Car
  num = 1
  
  define_method(:initialize) do |wait_time|
    @num = num
    num += 1
    @time = wait_time
  end
  attr_accessor :num, :time
  
  define_singleton_method(:clear) {num = 1}
end

class ParkingLot
  Space = Struct.new(:upper, :lower)
  
  def initialize(num)
    @spaces = num.times.map {|i| Space.new}
  end
  
  def add_car(waiting_time)
    idx = @spaces.index {|sp| sp.lower.nil?}
    if idx
      @spaces[idx].lower = Car.new(waiting_time)   #下のスペースが空いている
    else
      return false if @spaces.all?(&:upper)        #満車
      
      #下は空いていないが満車でない場合
      idxs = @spaces.map.with_index {|sp, i| i unless sp.upper}.compact
      idx = idxs.map do |i|
        diff = @spaces[i].lower.time - waiting_time
        diff >= 0 ? [diff, i] : nil
      end.compact.sort.first&.last
      unless idx
        idx = idxs.map {|i| [waiting_time - @spaces[i].lower.time, i]}.sort.first.last
      end
      
      @spaces[idx].upper = @spaces[idx].lower.dup
      @spaces[idx].lower = Car.new(waiting_time)
    end
    true
  end
  
  def next
    @spaces.each do |sp|
      if sp.lower
        sp.lower.time -= 1
        sp.upper.time -= 1 if sp.upper
      end
    end
    
    out = []
    2.times do
      @spaces.each do |sp|
        if sp.lower and sp.lower.time <= 0
          out << sp.lower.num
          sp.lower = sp.upper.dup
          sp.upper = nil
        end
      end
    end
    
    out
  end
  
  #車庫が空か
  def empty?
    @spaces.all? {|sp| sp.lower.nil?}
  end
end


until (given = gets.split.map(&:to_i)) == [0, 0]
  m, n = given
  parking_time = n.times.map {gets.to_i}
  pl = ParkingLot.new(m)
  result = []
  wait = []
  Car.clear
  t = 0
  
  loop do
    result += pl.next
    
    wait << parking_time.shift if (t % 10).zero?
    t += 1
    while (wait_time = wait.shift)
      unless pl.add_car(wait_time)
        wait.unshift(wait_time)    #満車の場合
        break
      end
    end
    
    break if pl.empty?
  end
  
  puts result.join(" ")
end


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

int par[100000];    //添え字として0~99999を許容する

int root(int i){
    if(par[i]==i){
        return i;
    }
    return par[i] = root(par[i]);

}
int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; ++i){
        par[i] = i;
    }
    for(int i = 0; i < m; ++i){
        int k1, k2;
        cin >> k1 >> k2;
        k1--;k2--;
        par[root(k1)] = root(k2);
    }
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(root(i)==i){
            cnt++;
        }
    }
    cout << (cnt - 1);
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  
  double x[N];
  string u[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> u[i];
  }
  
  double ans = 0;
  for (int i = 0; i < N; i++) {
    if (u[i] == "JPY") {
      ans += x[i];
    } else if (u[i] == "BTC") {
      ans += x[i] * 380000.0;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
K, N = map(int, input().split())
array = list(map(int, input().split()))
array_distance = []

for i in range(N):
    min = 0
    if i == N-1:
        min = abs(array[0] - array[N-1])
        if min>=K/2:
            min = abs(K-min)
        array_distance.append(min)
    else:
        min = abs(array[i] - array[i+1])

        array_distance.append(min)

array_distance= sorted(array_distance, reverse = True)
# print(array_distance)
# print(array_distance[0])
# print(sum(array_distance))
print(sum(array_distance) - array_distance[0])



Measured memory_bytes: 26436
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a=0,b=0,c=0,d=0,n,max=-1,k,ans=0;
    string s,s2;
    cin >> d >> n;
    if(n==100) n++;

    if (d==0) cout << n <<endl;
    else if (d==1) cout << n*100 <<endl;
    else if(d==2) cout << n*10000 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b, max;

  scanf("%d %d", &a, &b);

  if (a + b > a - b) 
    max = a + b > a * b ? a + b : a * b;
  else
    max = a - b > a * b ? a - b : a * b;

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


Measured memory_bytes: 128
n=int(input())
d=[input().split() for i in range(n)]
flag=False
for i in range(n-2):
  if d[i][0]==d[i][1]:
    if d[i+1][0]==d[i+1][1]:
      if d[i+2][0]==d[i+2][1]:
        flag=True
print("Yes" if flag else "No")

Measured memory_bytes: 9212
def weight
  master = Array.new(10) { |i| 2**i }
  while gets
    wei = $_.to_i
    spindles = master.select { |i| i <= wei }
    result = []
    while true
      break if wei <= 0
      minus = spindles.max
      if minus > wei
				spindles.delete(minus)
        next
      end
      wei -= minus
      result << spindles.delete(minus)
    end
    puts result.sort.join(' ')
  end
end

weight

Measured memory_bytes: 8556
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int ans = 0;
    rep(i,n)rep(j,n){
        if(i==j) continue;
        else ans += d[i]*d[j];
    }

    cout << ans/2;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    map<int, int> mp;
    vector<bool> dp(A.at(N - 1), true);
    for (int i = 0; i < N; i++) {
        if (!mp.count(A.at(i))) mp[A.at(i)] = 1;
        else mp.at(A.at(i))++;
    }
    int j;
    for (int i = 0; i < N; i++) {
        j = 2 * A.at(i);
        while (j <= A.at(N - 1)) {
            dp.at(j - 1) = false;
            j += A.at(i);
        }
    }
    int ans = 0;
    for (int i = 0; i <= A.at(N - 1); i++) {
        if (mp.count(i)) {
            if (mp.at(i) == 1 && dp.at(i - 1) == true) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector< int > B(M);
  cin >> B;
  int ret = 0;
  for(int i = 0; i < N; i++) {
    vector< int > A(M);
    cin >> A;
    int add = 0;
    for(int j = 0; j < M; j++) {
      add += A[j] * B[j];
    }
    add += C;
    ret += add > 0;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
import Data.List
main = getContents >>= putStrLn . solve 'a' . lines

solve :: Char -> [String] -> String
solve 'a' [a : as, bs, cs] = solve a [as, bs, cs]
solve 'a' _= "A"
solve 'b' [as, b : bs, cs] = solve b [as, bs, cs]
solve 'b' _ = "B"
solve _ [as, bs, c : cs] = solve c [as, bs, cs]
solve _ _ = "C"


Measured memory_bytes: 508
n = int(input())
 
dp = [float("inf")] * (n + 1)
 
dp[0] = 0
 
for i in range(n):
    six = 1
    while i + six <= n:
        dp[i + six] = min(dp[i + six], dp[i] + 1)
        six *= 6
 
    nine = 1
    while i + nine <= n:
        dp[i + nine] = min(dp[i + nine], dp[i] + 1)
        nine *= 9
 
print(dp[n])

Measured memory_bytes: 3828
#include <cstdio>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <utility>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))

int digit(int n, int m)
{
	return ((n / (int)pow(10, m)) % 10);
}

int main(int argc, char* argv[])
{
	int N;
	scanf("%d", &N);
	if(digit(N, 0) == digit(N, 1) && digit(N, 0) == digit(N, 2))
	{
		printf("Yes\n");
	}
	else if(digit(N, 1) == digit(N, 2) && digit(N, 1) == digit(N, 3))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}


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

int main(){
    for (;;) {
        int a,b;
        char op[5];
        scanf("%d %c %d",&a,op,&b);
        if (op[0]=='?') break;
        if (op[0]=='+') printf("%d\n",a+b);
        if (op[0]=='-') printf("%d\n",a-b);
        if (op[0]=='/') printf("%d\n",a/b);
        if (op[0]=='*') printf("%d\n",a*b);
    }
    return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '


const int MAXN = 2*1e5;
char a[MAXN];   

int main() {
    int n = 0, x = 0;
    cin >> n >> x;
    vector<int> l(n);
    int s = 0;
    int res = 0;
    for(int i = 0; i < n; ++i){
        cin >> l[i];
        s+=l[i];
        if(s <= x){
            ++res;
        }
    }
    ++res;
    cout << res << endl;
    
    

    return 0;
} 


Measured memory_bytes: 256
import java.io.*;
 
class Main {
    public static void main(String[] arg)throws IOException{
        BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
        String s = b.readLine();
        String[] spl = s.split(" ");
        int tate =  Integer.parseInt(spl[0]);
        int yoko =  Integer.parseInt(spl[1]);
        System.out.println(tate*yoko + " "+ 2*(tate+yoko));
    }   
}

Measured memory_bytes: 24020
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int x;
  vector<int>a;
  for(int i=0;i<10;i++){
    cin>>x;
    a.push_back(x);
  }
  sort(a.begin(),a.end()); 
  cout<<a[9]<<endl;
  cout<<a[8]<<endl;
  cout<<a[7]<<endl;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	int cnt = 0;
	REP(i,s.length()){
		if(s[i] == 'o') cnt++;
	}
	if(cnt + 15 - s.length()>= 8)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

using namespace std;


int main()
{
	int a[3],num;
	int i;
	scanf("%d",&num);
	for(i = 0; i < num; i++){
		scanf("%d %d %d",&a[0],&a[1],&a[2]);
		sort(a,a+3);
		if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    string str, sub;
    int m, min = INT_MAX;

    cin >> str;

    for (int i = 0; i < (int)str.length()-2; i++) {
        sub = str.substr(i, 3);
        m = abs(753 - atoi(sub.c_str()));
        if (min > m) {
            min = m;
        }

    }

    cout << min << endl;

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;
V <V <int> > G;
V <int> DP;

int dis(int u) {
	if(DP[u] != -1) {
		return DP[u];
	}
	int &x = DP[u];
	for(int i : G[u]) {
		x = max(x, 1 + dis(i));
	}
	x = max(x, 0);
	return x;
}

int main() {fio;
	int n, m;
	cin >> n >> m;
	G.resize(n), DP.resize(n, -1);
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		G[u - 1].push_back(v - 1);
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans = max(ans, dis(i));
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 7552
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]

cand = []
for i in range(N):
    xa,ya = xy[i]
    for j in range(i+1,N):
        xb,yb = xy[j]
        cand.append([(xa+xb)/2,(ya+yb)/2])
        for k in range(j+1,N):
            xc,yc = xy[k]
            if (xa-xb)*(ya-yc)-(xa-xc)*(ya-yb)!=0:
                x = (ya-yc)*(xa**2+ya**2-xb**2-yb**2)-(ya-yb)*(xa**2+ya**2-xc**2-yc**2)
                y = -(xa-xc)*(xa**2+ya**2-xb**2-yb**2)+(xa-xb)*(xa**2+ya**2-xc**2-yc**2)
                x /= 2*((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb))
                y /= 2*((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb))
                cand.append([x,y])

ans = float('inf')
for x,y in cand:
    d = 0
    for i in range(N):
        d = max(d,((xy[i][0]-x)**2+(xy[i][1]-y)**2)**0.5)
    ans = min(ans,d)
print(ans)

Measured memory_bytes: 46696
while 1:
  n = input()
  if n == 0:  break
  d = range(1, 7)
  ans = 1
  for i in range(n):
    c = raw_input()[0]
    if c == 'N': S = [1,5,2,3,0,4]
    elif c == "S": S = [4,0,2,3,5,1]
    elif c == "E": S = [3,1,0,5,4,2]
    elif c == "W": S = [2,1,5,0,4,3]
    elif c == "R": S = [0,2,4,1,3,5]
    elif c == "L": S = [0,3,1,4,2,5]
    d = [d[s] for s in S]
    ans += d[0]
  print ans

Measured memory_bytes: 4844