akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

using namespace std;


int main() {
	speed;
	string s;
	cin >> s;
	string ans="0";
	bool flag = false;
	if (s[0] == '0') {
		if ('1' <= s[1] && s[1] <= '9') {
			ans = "MMYY";
			flag = true;
		}
	}
	if (s[0] == '1') {
		if ('0' <= s[1] && s[1] <= '2') {
			ans = "MMYY";
			flag = true;
		}
	}

	if (s[2] == '0') {
		if ('1' <= s[3] && s[3] <= '9') {
			ans = "YYMM";
			if(flag)ans = "AMBIGUOUS";
		}
	}
	if (s[2] =='1') {
		if ('0' <= s[3] && s[3] <= '2') {
			ans = "YYMM";
			if (flag)ans = "AMBIGUOUS";
		}
	}
	if (ans == "0")ans = "NA";

	cout << ans;
	ed;
	return 0;
}


Measured memory_bytes: 256
A, B = map(int, input().split())

max_x = min((A+1)/0.08, (B+1)/0.1)
min_x = max(A/0.08, B/0.1) 

ans = -1
for i in list(reversed(range(int(min_x-1), int(max_x+1)))):
    if min_x <= i and i< max_x:
        ans = i

print(ans)

Measured memory_bytes: 3060
k,s,S,m,M,n;main(d){for(;~scanf("%d",&d);!k?S=M=0,m=1e3,k=d,n=d-2:--k||printf("%d\n",(S-m-M)/n))S+=d,d>M?M=d:0,d<m?m=d:0;}

Measured memory_bytes: 0
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    LOOP(3) {
        std::string s;
        std::cin >> s;
        std::cout << (char)std::toupper(s.front());
    }
    std::cout << '\n';
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  static Long[][]cache;
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int w=sc.nextInt();
    int []x=new int[n];
    int []v=new int[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
      v[i]=sc.nextInt();
    }
    cache=new Long[n+1][w+1];
    System.out.println(dfs(x,v,w,0));
    
  }
  public static long dfs(int []x,int []v,int W,int index){
 
        if(index==x.length || W==0) return 0;
        if(cache[index][W]!=null)return cache[index][W];
        long include=0,exclude;
        if(x[index]<=W){
            include=v[index]+dfs(x,v,W-x[index],index+1);
            exclude=dfs(x,v,W,index+1);
        }
        else{
            exclude=dfs(x,v,W,index+1);
        }
        return cache[index][W]=Math.max(include,exclude);
    }
}

Measured memory_bytes: 278544
#include <iostream>
using namespace std;
int main(int argc, char const* argv[])
{
	string s1, s2, s3;
	cin >> s1 >> s2;
	s3 = s1 + s1;
	for (int i=0; i<s1.size()+s2.size()-1; i++){
		for (int j=0; j<s2.size(); j++) {
			if (s3[i+j] != s2[j]) {
				break;
			}
			if (j == s2.size()-1) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 1188
n = int(input())
T, A = map(int, input().split())
h = list(map(int, input().split()))
dist = 10000
ans = 0
for i in range(n):
    if dist > abs(A - (T - h[i] * 0.006)):
        dist = abs(A - (T - h[i] * 0.006))
        ans = i
print(ans + 1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  ill n, d;
  cin >> n >> d;
  vector<ill> x(n), y(n);
  rep(i, 0, n) cin >> x[i] >> y[i];
  ill sum = 0;
  rep(i, 0, n) {
    if(x[i]*x[i] + y[i]*y[i] <= d*d) sum++;
  }
  cout << sum << "\n";
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, d;
  cin >> n >> d;
  int res = 0;
  for (int i = 0; i < n; i++) {
    double x, y;
    cin >> x >> y;
    double D = (double) sqrt(x * x + y * y);
    if (d - D >= 0) ++res;
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 3768
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	if (abs(N - M) >= 2)cout << 0 << endl;
	else {
		vector<int>v(N + M + 1);
		v[0] = 1;
		rep(i, 1, v.size())v[i] = (v[i - 1] * i) % MOD;
		int a = max(N, M);
		int b = min(N, M);
		if (abs(N - M) == 0) {
			cout << v[N] * (v[N] + v[N]) % MOD << endl;
		}
		else {
			cout << v[N] * v[M] % MOD << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<list>
#include<string>
#include<algorithm>
#include <utility>
#include<stdio.h>
#include<climits>
#include <vector>

using namespace std;

int main(void){
    int n;
    vector<int> v;
    int i,j;
    v.push_back(2);
    for(j = 3;j < 300000;j++){
        for(i = 0;i < v.size();i++){
            if(j%v[i] == 0) break;
            if(v[i]*v[i] > j){
                v.push_back(j);
                break;
            }
        }
    }
    while(1){
        cin >> n;
        if(!n) break;
        j = 0;
        for(i = 0;i < v.size();i++){
            if(v[i] > 2*n) break;
            if(n < v[i]) j++;
        }
        cout << j << endl;
    }
}

Measured memory_bytes: 1344
from collections import deque

n=int(input())

a=[3,5,7]

b=deque(a)

while b:
  v=b.popleft()
  
  x=v*10+3
  y=v*10+5
  z=v*10+7
  if x<=n:
    a.append(x)
    b.append(x)
    
  if y<=n:
    a.append(y)
    b.append(y)
    
  if z<=n:
    a.append(z)
    b.append(z)
ans=0    
for i in a:
  l=str(i)
  if '3' in l and '5' in l and '7' in l:
    ans+=1
    
print(ans)

Measured memory_bytes: 75228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
 
 
int main(){
    int n;
    cin>>n;
    double x[n],y[n];
    rep(i,n) cin>>x[i]>>y[i];
    double ans=0;
    vector<int> v;
    for(int i=0;i<n;i++){
        v.push_back(i);
    }
    do{
        for(int i=1;i<n;i++){
            ans+=sqrt((x[v[i]]-x[v[i-1]])*(x[v[i]]-x[v[i-1]])+(y[v[i]]-y[v[i-1]])*(y[v[i]]-y[v[i-1]]));
            //cout<<v[i-1]<<" "<<v[i];
            //cout<<sqrt((x[i]-x[i-1])*(x[i]-x[i-1])+(y[i]-y[i-1])*(y[i]-y[i-1]))<<" ";
        }
        //cout<<endl;
    }while(next_permutation(v.begin(),v.end()));
    double r=1;
    rep(i,n){
        r*=(i+1);
    }

    ans/=r;
    cout<<setprecision(10)<<ans<<endl;
    //cout<<r<<endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long int

int main() {
  int n, m;
  std::cin >> n >> m;
  std::map<ll, int> ab;
  for (int i = 0; i < n; i++) {
    ll ai;
    int bi;
    std::cin >> ai >> bi;
    auto itr = ab.find(ai);
    if(itr != ab.end() ) {
      ab[ai] += bi;
    } else {
      ab[ai] = bi;
    }
  }
  ll sum = 0;
  for(auto itr = ab.begin(); itr != ab.end(); ++itr) {
    ll i1 = itr->first;
    int i2 = itr->second;
    if (i2 > m) {
      i2 = m;
    }
    sum += i1 * i2;
    m -= i2;
    if (m <= 0) {
      std::cout << sum << std::endl;
      return 0;
    }
  }
}

Measured memory_bytes: 6528
N = int(input())
D, X = map(int, input().split())

A = []
for i in range(N):
    x = int(input())
    A.append(x)

s = X
for a in A:
    d = 1
    for i in range(100):
        if d + i*a <= D:
            s += 1
        else:
            break
print(s)


Measured memory_bytes: 3060
n = int(input())

def sol(n):
    res = n
    for i in range(n+1):
        cc = 0
        t = i
        while t > 0:
            cc += t % 6
            t = t // 6
        t = n - i
        while t > 0:
            cc += t % 9
            t = t // 9
        if res > cc:
            res = cc
    return res

print(sol(n))

Measured memory_bytes: 3064
#include<complex>
#include<cmath>
#include<iostream>
#include <iomanip>
using namespace std;
typedef complex<double> P;

//real()、実部
//imag()、虚部
//abs、原点からの距離
//norm、ノルム(absの二乗)
//足し算と引き算は複素数と同様
//掛け算は回転

//conjは共役複素数
//内積を求める
double dot_product(P a,P b){return (conj(a)*b).real();}

//ベクトルa,bの張る三角形の面積(外戚の1/2)(符号つき)
double triangle_area_product(P a,P b){return (conj(a)*b).imag()/2;}

//射影ベクトルを求める
//ベクトルa上にbを正射影する
P projection(P a,P b){return a*dot_product(a,b)/norm(a);}


int main(){
  cout <<  fixed << setprecision(1);
  int n;cin >>n;
  double x1,y1;double x2,y2;double x3,y3;
  cin >> x1 >> y1;cin >> x2 >> y2;cin >> x3 >> y3;
  P p1(x1,y1);P p2(x2,y2);P p3(x3,y3);
  double S=triangle_area_product(p2-p1,p3-p1);
  p2.real(x3);p2.imag(y3);
  for(int i=0;i<n-3;i++){
    cin >> x3 >>y3;
    p3.real(x3);p3.imag(y3);
    S+=triangle_area_product(p2-p1,p3-p1);
    p2.real(x3);p2.imag(y3);
  }
  cout << S << endl;
}



Measured memory_bytes: 3280
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int dfs(vector<int>&A, int i=0, int m=1) {
	if (!(i < A.size())) {
		return (m & 1 ? 0 : 1);
	}
	return dfs(A, i + 1, m*A[i]) + dfs(A, i + 1, m*(A[i] - 1)) + dfs(A, i + 1, m*(A[i] + 1));
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> A(N); rep(i, 0, N) { cin >> A[i]; }
	cout << dfs(A) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
const int N = 110;
int n,x;
bool st[N];

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    quickread();
    cin >> x >> n;
    if(n == 0) {
        cout << x << endl;
        return 0;
    }
    int p;
    for(int i = 1; i <= n; i ++) {
        cin >> p;
        st[p] = true;
    }
    int res = 0;
    for(int i = 0; i <= 109; i ++) {
        //cout << res << endl;
        if(st[i]) continue;
        else {
            if(abs(i - x) < abs(res - x)) {
                res = i;
            }
        }
        
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3648
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e3 + 7;
const ld pi = 3.14159265359;
const int INF = 1e20 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

ll n, a[N], sum, ans;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> n;

  for(int i = 1; i <= n; i++){
    cin >> a[i];
    sum += a[i];
  }

  ll ave = 0;

  if(sum > 0){
    ave = ((double)((double)sum / (double)n) + 0.5);
  }

  else if(sum < 0){
    ave = ((double)((double)sum / (double)n) - 0.5);
  }


  for(int i = 1; i <= n; i++){
    ans += (abs(a[i] - ave) * abs(a[i] - ave));
  }

  cout << ans;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<cmath>
#include<iomanip>
using namespace std;

int main(void)
{
    double a, b, x;
    cin >> a >> b >> x;

    double v = a * a * b;
    double halfV = v / 2.0;

    double halfTheta = atan2(b, a);
    //cout << halfTheta * 180 / M_PI << endl;

    double left = 0;
    double right = 90 * M_PI / 180;
    for (int i = 0; i < 100; i++) {
        double mid = (left + right) / 2;

        if (mid <= halfTheta) {
            double vo = a * a * tan(mid) / 2 * a;
            if (x <= v - vo)
                left = mid;
            else
                right = mid;
        }
        else {
            double theta = M_PI / 2 - mid;
            double vi = b * b * tan(theta) / 2 * a;
            if (x <= vi)
                left = mid;
            else
                right = mid;
        }
    }

    cout << fixed << setprecision(30) << left * 180 / M_PI << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int a = sc.nextInt();
    int b = sc.nextInt();

    int ans = Math.max(0, a - 2 * b);
    os.println(ans);
  }
}

Measured memory_bytes: 22228
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

A,B=rl()
A -= 1

a2 = format(A,'b')
al = len(a2)
b2 = format(B,'b')
bl = len(b2)


bc = [0]*bl
bc[0] += (B+1)//2
bc[0] -= (A+1)//2
for i in range(1,bl):
    bc[i] += (B+1)//(2**(i+1))*(2**i) + max(0, (B%(2**(i+1)) - (2**i-1)))
    bc[i] -= (A+1)//(2**(i+1))*(2**i) + max(0, (A%(2**(i+1)) - (2**i-1)))

ans = 0
for i in range(bl):
    if bc[i]%2==1:
        ans += 2**i

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    private int N;
    HashSet<string> Ans = new HashSet<string>(StringComparer.Ordinal);

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();

        Search(0, '0', '0', "");
        var ar = Ans.ToArray();
        Array.Sort(ar, StringComparer.Ordinal);
        Console.WriteLine(string.Join("\n",ar));
    }

    void Search(int i, char p, char max, string s)
    {
        if (i == 0)
        {
            for (int j = i + 1; j <= N; j++)
            {
                Search(j, 'a', 'a', s + new string('a', j));
            }
        }
        else if (i < N)
        {
            for (int j = i + 1; j <= N; j++)
            {
                for (char k = 'a'; k <= max + 1; k++)
                {
                    if (p == k) continue;
                    Search(j, k, (char) Math.Max(max, k), s + new string(k, j - i));
                }
            }
        }
        else
        {
            Ans.Add(s);
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

const int maxn = 200005;

int a[maxn], b[maxn], aa[maxn], bb[maxn];
int n;

int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d", &b[i]);
    }
    int answer=0;
    for(int i=0;i<=28;i++){
        for(int j=1;j<=n;j++){
            aa[j]=a[j]%(1<<(i+1));
            bb[j]=b[j]%(1<<(i+1));
        }
        sort(bb+1,bb+n+1);
        int t=(1<<i);
        int sum=0;
        for(int j=1;j<=n;j++){
            int p1=lower_bound(bb+1,bb+n+1,t-aa[j])-bb;
            int p2=lower_bound(bb+1,bb+n+1,2*t-aa[j])-bb;
            int s1=lower_bound(bb+1,bb+n+1,3*t-aa[j])-bb;
            int s2=lower_bound(bb+1,bb+n+1,4*t-aa[j])-bb;
            sum+=(p2-p1)+(s2-s1);
        }
        if(sum&1)
        answer+=(1<<i);
    }
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int j = 0; j < M; j++) {
    cin >> t.at(j);
  }
  vector<int> sum(N);
  vector<bool> comp(N, false);
  for (int k = 0; k < N; k++) {
    if (comp.at(k) == true) {
      continue;
    }
    for (int l = 0; l < N; l++) {
      if (s.at(l) == s.at(k)) {
        sum.at(k)++;
        comp.at(l) = true;
      }
    }
    for (int m = 0; m < M; m++) {
      if (t.at(m) == s.at(k)) {
        sum.at(k)--;
      }
    }
  }
  int score = 0;
  for (int n = 0; n < N; n++) {
    if (score < sum.at(n)) {
      score = sum.at(n);
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};


int main(int argc, char const *argv[]) {
	int tree[250];
	for (int i = 0; i < 250; ++i) {
		tree[i] = 2000000001;
	}
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> tree[i];
	}

	for (int i = 0; i < N; ++i) {
		cout << "node " << i + 1 << ": key = " << tree[i] << ",";
		if (i != 0) {
			cout << " parent key = " << tree[(i - 1) / 2] << ",";
		}
		if (i * 2 + 1 < 250 && tree[i * 2 + 1] != 2000000001) {
			cout << " left key = " << tree[i * 2 + 1] << ",";
		} 
		if (i * 2 + 2 < 250 && tree[i * 2 + 2] != 2000000001) {
			cout << " right key = " << tree[i * 2 + 2] << ",";
		} 
		cout << " " << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import math
import itertools

ceil = math.ceil

def main():
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
    l = [A, B, C, D, E]
    ans = float('inf')
    for p in itertools.permutations(l):
        anstmp = 0
        for i, f in enumerate(p):
            if i == 4:
                anstmp += f
            else:
                anstmp += ceil(f/10)*10
        ans = min(ans, anstmp)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
// Problem : C - Replacing Integer
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int main(){
	long long n,k;
	cin >> n >> k;
	
	cout << min(n % k,abs(n % k - k)) << endl;
	return 0;	
}


Measured memory_bytes: 256
N,D=map(int,input().split())

xy=[map(int,input().split()) for i in range(N)]
x,y=[list(i) for i in zip(*xy)]

ans=0


for x,y in zip(x,y):
    if (x**2+y**2)**0.5<=D:
        ans+=1
        
print(ans)

Measured memory_bytes: 116684
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,ans=0;
  cin >> n;
  vi p(n);
  rep(i,0,n)  cin >> p[i];

  sort(all(p));
  p[n-1] /= 2;

  rep(i,0,n){
    ans += p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[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'};
char moji2[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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int a,b,t;
    cin >> a >> b >> t;
    cout << int(t /a) * b << endl;

}


Measured memory_bytes: 256
main :: IO ()
main = do
    n <- readLn
    ss <- sequence $ replicate n getLine
    putStrLn $ "AC x " ++ (show $ count "AC" ss)
    putStrLn $ "WA x " ++ (show $ count "WA" ss)
    putStrLn $ "TLE x " ++ (show $ count "TLE" ss)
    putStrLn $ "RE x " ++ (show $ count "RE" ss)
        where 
            count _ [] = 0
            count y (x:xs) 
                | x == y = 1 + count y xs
                | otherwise = count y xs

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

char s[10];

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}

inline void writ(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x){writ(x);putchar('\n');}

int main()
{
	int ans=700;
	scanf("%s",s+1);
	for (int i=1;i<=3;++i) if (s[i]=='o') ans+=100;
	write(ans);
	return 0;
}

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

int gcd(int p, int q) {
  if (p % q == 0) return q;
  return gcd(q, p % q);
}

int main() {
  int x, y;
  cin >> x >> y;
  if(x >= y && gcd(x, y) == y) cout << -1 << endl;
  else cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[100010],ans;
int abs(int x)
{
	return x<0?-x:x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]),ans+=abs(a[i]-a[i-1]);
	ans+=abs(a[n]);
	for(int i=1;i<=n;i++)
	printf("%d\n",ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

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

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		byte[] time = new byte[5];
		for (int i=0; i<5; i++) time[i] = scanner.nextByte();

		int base = 0;
		for (byte t : time) base += up(t);

		int min1 = 10;
		for (byte t: time) {
			if (t%10!=0) min1 = Math.min(min1, t%10);
		}

		System.out.println(base-10+min1);
	}

	static int up(byte b) {
		double d = b/10d;
		return (int) Math.ceil(d)*10;
	}
}

Measured memory_bytes: 23508
import heapq

N = int(input())
L = input().split()
L = [int(a) for a in L]

heapq.heapify(L)

sum = 0

for i in range(N):
    k1 = heapq.heappop(L)
    k2 = heapq.heappop(L)
    sum += k1

print(sum)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;

int nearestPowerOfTwo(int n){
	int ans = 1;
	while(ans < n) ans <<= 1;
	return ans;
}

__int128_t powerMod(__int128_t b, __int128_t e, __int128_t m){
	__int128_t ans = 1;
	e %= m-1;
	if(e < 0) e += m-1;
	while(e){
		if(e & 1) ans = ans * b % m;
		e >>= 1;
		b = b * b % m;
	}
	return ans;
}

template<lli p, lli g>
void ntt(vector<lli> & X, int inv){
	int n = X.size();
	for(int i = 1, j = 0; i < n - 1; ++i){
		for(int k = n >> 1; (j ^= k) < k; k >>= 1);
		if(i < j) swap(X[i], X[j]);
	}
	vector<__int128_t> wp(n>>1, 1);
	for(int k = 1; k < n; k <<= 1){
		__int128_t wk = powerMod(g, inv * (p - 1) / (k<<1), p);
		for(int j = 1; j < k; ++j)
			wp[j] = wp[j - 1] * wk % p;
		for(int i = 0; i < n; i += k << 1){
			for(int j = 0; j < k; ++j){
				lli u = X[i + j], v = X[i + j + k] * wp[j] % p;
				X[i + j] = u + v < p ? u + v : u + v - p;
				X[i + j + k] = u - v < 0 ? u - v + p : u - v;
			}
		}
	}
	if(inv == -1){
		__int128_t nrev = powerMod(n, p - 2, p);
		for(int i = 0; i < n; ++i)
			X[i] = X[i] * nrev % p;
	}
}

template<lli p, lli g>
vector<lli> sq(vector<lli> A){
	int sz = A.size();
	int size = nearestPowerOfTwo(2*A.size() - 1);
	A.resize(size);
	ntt<p, g>(A, 1);
	for(int i = 0; i < size; i++)
		A[i] = (__int128_t)A[i] * A[i] % p;
	ntt<p, g>(A, -1);
	for(int i = sz; i < size; ++i){
		A[i % sz] += A[i];
	}
	A.resize(sz);
	return A;
}

const int P = 2e5 + 3;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<int> LOG(P);
	vector<int> g_pow(P-1, 1);
	for(int i = 1; i < P-1; ++i){
		g_pow[i] = (lli)g_pow[i-1] * 5 % P;
		assert(g_pow[i] != 1);
		LOG[g_pow[i]] = i;
	}
	int n;
	cin >> n;
	vector<lli> poly(P-1);
	for(int i = 0; i < n; ++i){
		int ai;
		cin >> ai;
		if(ai){
			poly[LOG[ai]]++;
		}
	}
	auto freq = sq<17169973579350017ll, 3>(poly);
	for(int i = 0; i < P-1; ++i){
		freq[2*i % (P-1)] -= poly[i];
	}
	for(int i = 0; i < P-1; ++i){
		assert(freq[i] % 2 == 0);
		freq[i] /= 2;
	}
	lli ans = 0;
	for(int i = 0; i < P-1; ++i){
		ans += g_pow[i] * freq[i];
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 14528
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()



signed main(){
  double a,b,x;
  cin >> a >> b >> x;
  if(a*a*b/2<x) cout << setprecision(8) << atan(2*b/a-2*x/(a*a*a)) * 180 / M_PI << endl;
  else cout << setprecision(8) << atan(a*b*b/2/x) * 180 / M_PI << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, W = rli()
	items = []
	for _ in range(n):
		w, v = rli()
		items.append((w, v))
	dp = [0 for _ in range(W + 1)]
	for w, v in items:
		for i in range(W, -1, -1):
			if i - w >= 0:
				dp[i] = max(dp[i], dp[i-w] + v)
	print(dp[-1])
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 45296
nm = [int(x) for x in input().split(' ')]
vote = [int(v) for v in input().split(' ')]

sum_vote = sum(vote)
thresh = sum_vote / (4 * nm[1])

vote_valid = [True if v >= thresh else False 
              for v in vote]

sum_vote_valid = sum(vote_valid)
if sum_vote_valid >= nm[1]:
  print('Yes')
else:
  print('No')

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 3000 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int Idx(int op, int id, int len) {
	return ((id - 1) * 22 + len) * 2 + op;
}

struct Adj {
	int v, w;
};
vector<Adj> a[N];
string s[N];
int c[N];
ll dis[N];

bool MirrorEqual(string x, string y) {
	reverse(all(x));
	return x == y;
}

queue<int> q;
bool inQ[N];

void SPFA() {
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (auto e: a[u]) {
			if (dis[e.v] > dis[u] + e.w) {
				dis[e.v] = dis[u] + e.w;
				if (!inQ[e.v]) {
					inQ[e.v] = 1;
					q.push(e.v);
				}
			}
		}
		inQ[u] = 0;
	}
}

int main() {
	ios::sync_with_stdio(0);

	memset(dis, 0x3f, sizeof(dis));

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i] >> c[i];
		int len = s[i].size();
		for (int j = 0; j <= len; j++) {
			// left: 0
			if (MirrorEqual(s[i].substr(len - j, j), s[i].substr(len - j, j))) {
				int u = Idx(0, i, len - j);
				q.push(u);
				inQ[u] = 1;
				dis[u] = c[i];
			}
			// right: 1
			if (MirrorEqual(s[i].substr(0, j), s[i].substr(0, j))) {
				int u = Idx(1, i, len - j);
				q.push(u);
				inQ[u] = 1;
				dis[u] = c[i];
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		int len = s[i].size();
		// left: 0
		for (int j = 0; j <= len; j++)
			for (int k = 1; k <= n; k++) {
				if (s[k].size() < j) {
					if (!MirrorEqual(s[i].substr(j - s[k].size(), s[k].size()), s[k])) continue;
					int u = Idx(0, i, j);
					int v = Idx(0, i, j - s[k].size());
					int w = c[k];
					a[u].push_back((Adj){v, w});
				} else {
					if (!MirrorEqual(s[i].substr(0, j), s[k].substr(0, j))) continue;
					int u = Idx(0, i, j);
					int v = Idx(1, k, s[k].size() - j);
					int w = c[k];
					a[u].push_back((Adj){v, w});
				}
			}

		// right: 1
		for (int j = 0; j <= len; j++)
			for (int k = 1; k <= n; k++) {
				if (s[k].size() < j) {
					if (!MirrorEqual(s[i].substr(len - j, s[k].size()), s[k])) continue;
					int u = Idx(1, i, j);
					int v = Idx(1, i, j - s[k].size());
					int w = c[k];
					a[u].push_back((Adj){v, w});
				} else {
					if (!MirrorEqual(s[i].substr(len - j, j), s[k].substr(s[k].size() - j, j))) continue;
					int u = Idx(1, i, j);
					int v = Idx(0, k, s[k].size() - j);
					int w = c[k];
					a[u].push_back((Adj){v, w});
				}
			}
	}

	SPFA();

	ll ans = INF_LL;
	for (int i = 1; i <= n; i++) {
		int len = s[i].size();
		ans = min(ans, dis[Idx(0, i, 0)]);
		ans = min(ans, dis[Idx(1, i, 0)]);
	}
	if (ans == INF_LL)
		cout << -1 << endl;
	else
		cout << ans << endl;

	return 0;
}


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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int g[10][10];

int main(){
	//IO();
	scanf("%d%d",&n,&m);
	printf("%d\n",(n+m-1)/m);
}


Measured memory_bytes: 256
#include<stdio.h>
#define S_MAX 1000000

int S[S_MAX], n;

int binary(int key)
{
 int left=0;
 int right=n;
 int mid; 
   
 while(left < right){
   mid=(left+right)/2;
   
   if(S[mid] == key){
     return 1;
   }
   
   else if(S[mid] > key){
     right = mid;
   }
   else
     left = mid+1;
 }
 
  return 0;
}

int main()
{
  int q, C=0, key;
  int i, j;

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


  scanf("%d", &q);
  for(i=0 ; i<q ; i++){
    scanf("%d", &key);
    if(binary(key)){
      C++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int K, A, B;
    cin >> K >> A >> B;

    for (int i = A; i < B + 1; i++){
        if (i % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100050;
struct node{
	int a,b;
}a[N];
int r[N];
inline bool cmp1(const node &a,const node &b){return a.b<b.b;}
inline bool cmp2(int x,int y){return a[x].a<a[y].a;}
int main(){
	int n,i,p,tot=1;
	scanf("%d",&n);
	for(i=1;i<=n;++i){scanf("%d",&a[i].a);r[i]=i;}
	for(i=1;i<=n;++i)scanf("%d",&a[i].b);
	sort(a+1,a+n+1,cmp1);sort(r+1,r+n+1,cmp2);
	for(i=1;i<=n;++i)if(a[r[i]].a>a[i].b){
		puts("No");
		return 0;
	}
	for(i=1;i<n;++i)if(a[r[i+1]].a<=a[i].b){
		puts("Yes");
		return 0;
	}
	for(p=r[1];p!=1;p=r[p])++tot;
	puts(tot==n?"No":"Yes");
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7, N = 205;
ll comb[N][N];
ll f(vector<int> arr){
    vector<ll> dp(arr.size()+1);
    dp[0] = 1;
    for(int i = 1; i <= arr.size(); ++i){
        for(int j = 0; j < i; ++j)
            if(j == 0 || arr[i-1] > arr[j-1])
                dp[i] += dp[j];
    }
    ll ans = 0;
    for(int i = 1; i <= arr.size(); ++i){
        ans += dp[i];
        //cout << i << ' ' << dp[i] << '\n';
    }
    return ans;
}
int main(){
    ll n;
    cin >> n;
    vector<int> ans(1,1);
    int next_letter = 1;
    while(f(ans) < n){
        ++next_letter;
        for(int i = ans.size(); i >= 0; --i){
            auto cp = ans;
            cp.insert(cp.begin()+i,next_letter);
            if(f(cp) <= n){
                ans = cp;
                break;
            }
        }
    }
    //cout << f(ans) << '\n';
    int s = ans.size();
    for(int i = 1; i <= s; ++i)
        ans.push_back(i);
    cout << ans.size() << '\n';
    for(int i = 0; i < ans.size(); ++i)
        cout << ans[i] << " \n"[i==(int)ans.size()-1];
}


Measured memory_bytes: 256
R,G,B,n = map(int,input().split())
ans = 0
for r in range(n+1):
    for g in range(n+1):
        if r*R + g*G <= n:
            p = n - r*R - g*G
            if p%B == 0:
                ans += 1
                #print(r,g,p//B)



print(ans)

Measured memory_bytes: 41324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


int main(){
    int n;
    cin >> n;
    vector<int> yes;
    int v = 2;
    while(v*(v+1)/2<=n){
        yes.push_back(v*(v+1)/2);
        v++;
    }
    int exist = -1;
    for(int i = 0; i < yes.size(); i++){
        if(yes[i] == n){
            exist = i;
        }
    }
    if(n == 1){
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << "1 1" << endl;
        cout << "1 1" << endl;
        return 0;
    }
    if(exist == -1){
        cout << "No" << endl;
        return 0;
    }

    exist += 2;
    vector<vector<int>> ans(exist+1,vector<int>(exist,0));
    int num = 1;
    for(int cur = 0; cur < exist; cur++){
        for(int i = 0; i < exist - cur; i++){
            ans[cur][cur+i] = num;
            ans[cur+1+i][cur] = num;
            num++;
        }
    }
    cout << "Yes" << endl;
    cout << exist+1 << endl;
    for(int i = 0; i < exist+1; i++){
        cout << exist << " ";
        for(int j = 0; j < exist-1; j++){
            cout << ans[i][j] << " ";
        }
        cout << ans[i][exist-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<int> find_all(const string str, const string subStr){
  vector<int> result;

  int subStrSize = subStr.size();
  int pos = str.find(subStr);

  while(pos != string::npos){
    result.push_back(pos);
    pos = str.find(subStr, pos + subStrSize);
  }

  return result;
}

int main()
{
    int n;
    int cnt_AB_all = 0;
    int cnt_A_all = 0;
    int cnt_B_all = 0;
    int cnt_BA_all = 0;
    string s;
    cin >> n;
    for(int i = 0;i < n; i++){
      cin >> s;
      cnt_AB_all += find_all(s, "AB").size();
      if(s[0] == 'B' && s[s.length() - 1] == 'A'){
        cnt_BA_all++;
      }else if(s[0] == 'B'){
        cnt_B_all++;
      }else if(s[s.length() - 1] == 'A'){
        cnt_A_all++;
      }
    }
    int ans_BA = 0;
    int ans_AorB = 0;
    if(cnt_BA_all > 0){
      if(cnt_B_all > 0){
        ans_BA++;
        cnt_B_all -= 1;
      }
      if(cnt_A_all > 0){
        ans_BA++;
        cnt_A_all -= 1;
      }
      ans_BA += cnt_BA_all - 1;
    }
    
    if(cnt_B_all >= cnt_A_all){
      ans_AorB = cnt_A_all;
    }else{
      ans_AorB = cnt_B_all;
    }
    cout << cnt_AB_all + ans_BA + ans_AorB << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String len = Integer.toString(s.length()-2);
        System.out.println(s.charAt(0) + len + s.charAt(s.length()-1));
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cctype>
#include <queue>
using namespace std;
typedef pair<int, int> P;

const int INF = 100000000;
const int MAX_N = 9;
const int MAX_H = 1000;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

int H, W, N;
P A[MAX_N + 1];
int d[MAX_H][MAX_H];
char field[MAX_H][MAX_H + 1];

int bfs(int s) {
  queue<P> que;
  for (int i = 0; i < H; i++) 
    for (int j = 0; j < W; j++) d[i][j] = INF;
  que.push(A[s]);
  d[A[s].first][A[s].second] = 0;
  while(que.size()) {
    P p = que.front(); que.pop();
    if (p == A[s + 1]) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] != 'X' && d[nx][ny] == INF) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[A[s + 1].first][A[s + 1].second];
}

int main() {
  scanf("%d%d%d", &H, &W, &N);
  for (int i = 0; i < H; i++) {
    scanf("%s", field[i]);
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == 'S') {
        A[0] = P(i, j);
      } else if (isdigit(field[i][j])) {
        A[field[i][j] - '0'] = P(i, j);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    res += bfs(i);
  }
  printf("%d\n", res);
  return 0;
}

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

int main() {
    int N;
    cin>>N;
    map<string, int>map;
    string arr[N];
    bool ans = true;
    for(int i=0;i<N;++i){
        cin>>arr[i];
        if(map[arr[i]]!=0)ans = false;
        map[arr[i]]++;
    }
    for(int i=1;i<N;++i){
        if(arr[i-1][arr[i-1].size()-1] != arr[i][0])ans=false;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

LL N,K;
vector<int> sushi[100000];
vector<int> top,other;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	cin >> N >> K;
	for(int i=0; i<N; i++){
		int t,d;
		cin >> t >> d;
		t--;
		sushi[t].push_back(d);
	}
	for(int i=0; i<N; i++) sort(sushi[i].begin(), sushi[i].end(), greater<int>());
	for(int i=0; i<N; i++){
		if(sushi[i].size() > 0){
			top.push_back(sushi[i][0]);
			for(int j=1; j<sushi[i].size(); j++) other.push_back(sushi[i][j]);
		}
	}
	sort(top.begin(), top.end(), greater<int>());
	sort(other.begin(), other.end(), greater<int>());

	LL ans = 0;
	if(top.size() >= K){
		LL tmp = 0;
		for(int i=0; i<K; i++) tmp += top[i];
		ans = max(ans, tmp+K*K);
		for(int i=1; i<K; i++){
			if(i-1 >= other.size()) break;
			tmp -= top[K-i];
			tmp += other[i-1];
			ans = max(ans, tmp+(K-i)*(K-i));
		}
	}
	else{
		LL tmp = 0;
		for(int i=0; i<top.size(); i++) tmp += top[i];
		for(int i=0; i<K-top.size(); i++) tmp += other[i];
		ans = max(ans, tmp+(LL)top.size()*(LL)top.size());
		for(int i=1; i<top.size(); i++){
			if(K-top.size()+i-1 >= other.size()) break;
			tmp -= top[top.size()-i];
			tmp += other[K-top.size()+i-1];
			ans = max(ans, tmp+(LL)(top.size()-i)*(LL)(top.size()-i));
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 6396
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};




int main (){
      int N;
      cin>>N;
      int a[N],b[N];
      rep0(i,N) cin>>a[i];
      rep0(i,N) cin>>b[i];
      int ans=0;
      for(int k=29;k>=0;k--){
            int hoge = 1ll<<(k+1);
            rep0(i,N) a[i]%=hoge;
            rep0(i,N) b[i]%=hoge;
            sort(b,b+N);
            int T = 1ll<<k;
            int piyo=0;
            rep0(i,N){
                  int huga =lower_bound(b,b+N,2*T-a[i])-lower_bound(b,b+N,T-a[i]);
                  int mochi =lower_bound(b,b+N,4*T-a[i])-lower_bound(b,b+N, 3*T-a[i]);
                  huga= (huga<0)? 0 : huga;
                  mochi=(mochi<0)? 0 : mochi;
                  piyo=(piyo+huga+mochi)%2;
                  //if(k==29)cout<<huga<<" "<<mochi<<" "<<piyo<<endl;
            }
            ans=2*ans+piyo;
      }
      cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> pys;
  vector<vector<int>> mp(N + 1);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    pys.push_back(make_pair(p, y));
    mp[p].push_back(y);
  }

  for (auto &e : mp) {
    sort(e.begin(), e.end());
  }

  for (auto &p : pys) {
    int pi = p.first;
    vector<int> &v = mp[pi];
    auto iter = lower_bound(v.begin(), v.end(), p.second);
    int x = iter - v.begin() + 1;

    cout << setw(6) << setfill('0') << pi;
    cout << setw(6) << setfill('0') << x;
    cout << "\n";
  }

  return 0;
}

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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;
#define call(a) for(auto i:(a))cout<<i<<" ";cout<<endl;
#define ENDL printf("\n");
signed main(){
  int n;
  cin>>n;
  vint c(n),s(n),f(n);
  rep(i,n-1)cin>>c[i]>>s[i]>>f[i];

  rep(i,n){
    if(i==n-1){cout<<0<<endl;return 0;}
    int time=0;
    for(int j=i;j<n-1;++j){
      if(time==0)time+=c[j]+s[j];
      else if(time>s[j])time=c[j]+s[j]+f[j]*((time-s[j]+f[j]-1)/f[j]);
      else time=c[j]+s[j];
    }
    cout<<time<<endl;
  }

  return 0;
}


Measured memory_bytes: 256