akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>

using namespace std;

#define fto(i,a,b) for (int i = (a); i <= b; i++)
#define fdw(i,a,b) for (int i = (a); i >= b; i--)
#define rep(i,a) for(int i = 0; i < a; i++) 
#define read(a) cin >> a
#define read2(a, b) cin >> a >> b
#define read3(a, b, c) cin >> a >> b >> c
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define write(a, b) cout << a << b
#define writeln(a) cout << a << "\n"

#define PI 3.14159265
#define oo 1000000000
#define ooLL 100000000000000000
#define log(a) cerr << #a << " = " << a << endl

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define next thongdeptrai
#define prev thongbachuthegioi
#define y1 thongsieucapvutru
#define y0 thongnotgay

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

#define maxn 100005

using namespace std;

int n, a[maxn], res;

int main() {

    // checking input file is not available with atCoder
   // freopen("in.inp", "r", stdin);
    
    read(n);
    for(int i = 1; i <= n; i++) read(a[i]);

    res = 0;
    for(int i = 1; i < n; i++) 
        if (a[i] == i) {
            swap(a[i], a[i + 1]);
            res++;
        }

    if (a[n] == n) res++;

    cout << res << endl;
    

 	#ifndef ONLINE_JUDGE
    	cout << endl;
    	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  int n;
  string s,t;
  cin >> n >> s >> t;
  string ans="";
  rep(i,n) {
    ans+=s[i];
    ans+=t[i];
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main(){
  double x1,y1,x2,y2,xq,yq;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)>0){
    complex<double> p[2],q;
    p[0]=complex<double>(x1,y1);
    p[1]=complex<double>(x2,y2);
    q   =complex<double>(xq,yq);

    complex<double> r;
    r=conj((q-p[0])*conj(p[1]-p[0]))/conj(p[1]-p[0])+p[0];
    cout << r.real() << ' ' << r.imag() << endl;
  }

  return 0;
}

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

using namespace std;

const int MAX_N = 200000;
const double PI = 3.141592653589793;
int a,b,c,d;
int n;
pair<int, int> f[MAX_N];

int main()
{
  cin >> a >> b >> c >> d >> n;
  if (a > c) { swap(a,c); swap(b,d); }

  for (int i = 0; i < n; ++i) {
    cin >> f[i].first >> f[i].second;
  }

  sort(f, f+n);
  int l = lower_bound(f, f+n, make_pair(a, 0)) - f;
  int r = upper_bound(f, f+n, make_pair(c, INT_MAX)) - f;

  if (l >= n) {
    printf("%.15f\n", 100.0*(abs(c - a) + abs(d - b)));
    return 0;
  }

  vector<int> bd;
  if (d < b) {
    swap(b, d);
    reverse(f+l, f+r);
  }
  for (int i = l; i < r; i++)
    if (b <= f[i].second && f[i].second <= d)
      bd.push_back(f[i].second);

  int lis[bd.size()];
  fill_n(lis, bd.size(), INT_MAX);
  for (int i = 0; i < bd.size(); i++) {
    *lower_bound(lis, lis+bd.size(), bd[i]) = bd[i];
  }

  int k = lower_bound(lis, lis+bd.size(), INT_MAX) - lis;

  int s = c - a + d - b, p, q;
  if (min(c - a, d - b) + 1 == k) {
    p = k-1;
    q = 1;
  } else {
    p = k;
    q = 0;
  }

  printf("%.15f\n", 100.0 * s + (5.0*p + 10.0*q) * PI - 20.0 * (p + q));

  return 0;
}


Measured memory_bytes: 3444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] v = new int[n];
            int[] c = new int[n];
            for (int i = 0; i < n; i++)
                v[i] = in.nextInt();
            for (int i = 0; i < n; i++)
                c[i] = in.nextInt();
            int max = 0;
            for (int i = 0, lim = 1 << n; i < lim; i++) {
                int x = 0, y = 0;
                for (int j = 0; j < n; j++)
                    if ((i & (1 << j)) > 0) {
                        x += v[j];
                        y += c[j];
                    }
                max = Math.max(max, x - y);
            }
            out.println(max);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N, X, Y = map(int, input().split(' '))
Y -= 1
X -= 1

count = [0] * (N-1)
for i in range(N):
    for j in range(i + 1, N):
        if i <= X and X <= j <= Y:
            min_d = min(j - i, X - i + (Y - j) + 1)
        elif i <= X and Y <= j:
            min_d = X - i + (j - Y) + 1
        elif X <= i <= Y and Y <= j:
            min_d = min(j - i, (i - X) + 1 + (j - Y))
        elif X <= i <= j <= Y:
            min_d = min(j - i, i - X + 1 + (Y - j))
        else:
            min_d = j - i
        # print(i+1, j+1)
        # print(min_d)
        count[min_d-1] += 1

for x in count:
    print(x)


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

int main(){

    // 読み込み
    int r, c;
    int x;
    int rowSum;

    cin >> r >> c;

    int ary[c + 1];
    for(int i = 1; i <= c; i++){
        ary[i] = 0;
    }


    for(int i = 1; i <= r; i++){
        rowSum = 0;
        for(int j = 1; j <= c; j++){
            cin >> x;
            cout << x << " ";
            rowSum += x;
            ary[j] += x;
        }
        cout << rowSum << endl;
    }
    int sum = 0;
    for(int i = 1; i <= c; i++){
        cout << ary[i] << " ";
        sum += ary[i];
    }
    cout << sum << endl;

    // 出力





    return 0;
}


Measured memory_bytes: 3100
N = int(input())
H = [int(i) for i in input().split()]

ans = 0
dp = 0
for i in range(N-1):
  if H[i]>=H[i+1]:
    dp += 1
  else:
    ans = max(ans, dp)
    dp = 0
ans = max(ans, dp)
print(ans)

Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

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

int main()
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc107_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int[] arr = ReadLine().Split().Select(int.Parse).ToArray();
            int n = input[0];
            int k = input[1];

            long min=int.MaxValue;
            for(int i=0; i<=n-k; i++){
                var left = Abs(arr[i]) + Abs(arr[i+k-1] - arr[i]);
                var right = Abs(arr[i+k-1]) + Abs(arr[i] - arr[i+k-1]);
                min = Min(min, Min(left,right));
            }
            WriteLine(min);
        }
    }
}

Measured memory_bytes: 23520
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, k,count=0;
	cin >> a >> b >> k;
	vector<int>sum(b,0);
	for (int i = 1; i <=min(a,b) ; i++) {
		if (a%i == 0 && b%i == 0) {
			sum[count] += i;
			count++;
		}
	}
	cout << sum[count - k] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
long K,A[2<<17],B[2<<17];
main()
{
	cin>>N>>M>>K;
	long S=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S+=A[i];
	}
	for(int i=0;i<M;i++)cin>>B[i];
	int ans=0;
	int j=0;
	for(int i=N;i>=0;i--)
	{
		if(i<N)S-=A[i];
		while(j<M&&S+B[j]<=K)
		{
			S+=B[j++];
		}
		if(S<=K)ans=max(ans,j+i);
	}
	cout<<ans<<endl;
}


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

ll a[1000005], basis[65];

void add(ll x){
    for(ll i = 63; i >= 0; i--)
        if(x & (1LL << i)){
            if(!basis[i]){
                basis[i] = x;
                return; //tu deu continue era return
            }
            x ^= basis[i]; 
        } // hehe
}

int main(){
    ll n; cin >> n;
    ll sum = 0;
    for(ll i = 0; i < n; i++)
        cin >> a[i], sum ^= a[i];
    // sort(a, a+n); reverse(a, a+n);
    // o q aconteceu
    
    // n sei oq vou fazer da minha vida ;-;
    
    for(int i = 0; i <= 60; i++){
        if(sum & (1LL << i)){
            for(int j = 0; j < n; j++){
                if(a[j] & (1LL << i)) a[j] -= (1LL << i);
            }
        }
    }
    
    for(ll i = 0; i < n; i++)
        add(a[i]);

    ll res = 0;
    for(int i = 63; i >= 0; i--){
        if(res & (1LL << i)) continue;
        if(!basis[i]) continue;
        res ^= basis[i];
    }
    // cout << res << " " << sum << endl;
    cout << res + (sum ^ res) << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Text;

namespace ITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var ch = new char[301];
            for(int i = 0; i < 301; i++)
            {
                ch[i] = i % 2 == 0 ? '#' : '.';
            }
            var memo = new string(ch);

            var sb = new StringBuilder();
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                if (input.All(s => s == "0"))
                    break;
                var H = int.Parse(input[0]);
                var W = int.Parse(input[1]);
                var p1 = memo.Substring(0, W);
                var p2 = memo.Substring(1, W);
                for(int i = 0; i < H; i++)
                {
                    sb.AppendLine(i % 2 == 0 ? p1 : p2);
                }
                sb.AppendLine();
            }
            Console.Write(sb);
        }
    }
}

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

int main() {
  int N, L;
  cin >> N >> L;

  int apple[200];
  for (int i = 0; i < N; i++) {
    apple[i] = L + i;
  }
  int a_min = 100;
  for (int i = 0; i < N; i++) {
    if (abs(apple[i]) < abs(a_min)) a_min = apple[i];
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += apple[i];
  }
  sum -= a_min;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace ITP1_7_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int l = int.Parse(input[2]);

            int[,] A = MakeMap(n, m);
            int[,] B = MakeMap(m, l);
            long[,] C = new long[n, l];
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < m; j++)
                {
                    for(int k = 0; k < l; k++)
                    {
                        C[i, k] += A[i, j] * B[j, k];
                    }
                }
            }

            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < n; i++)
            {
                sb.Append(C[i, 0]);
                for(int j = 1; j < l; j++)
                {
                    sb.Append(" " + C[i, j]);
                }
                sb.AppendLine();
            }
            Console.Write(sb);
        }

        static int[,] MakeMap(int a,int b)
        {
            int[,] ret = new int[a, b];
            for(int i = 0; i < a; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                for(int j = 0; j < b; j++)
                {
                    ret[i, j] = int.Parse(input[j]);
                }
            }
            return ret;
        }
    }
}

Measured memory_bytes: 10108
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
long long n,a,b;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&n);
	printf("%lld\n",a*min(b-1,n)/b-a*(min(b-1,n)/b));
return 0;
}

Measured memory_bytes: 3832
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,x;
    cin >> a >> b >> x;
    if(a > x){
        cout << "NO" <<endl;
    }
    else if(a <= x){
        if(a+b <x) cout << "NO" << endl;
        else if(a+b >= x) cout << "YES" << endl;
    }
}



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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n;
  LL m;
  cin >> m >> n;
  LL tot = 0;
  for (int i = 1; i <= n; i++) {
    LL x;
    cin >> x;
    tot += x;
  }
  if (tot > m) cout << -1 << endl;
  else cout << m - tot << endl;
  return 0;
}



Measured memory_bytes: 3656
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;

    bool ans = false;
    for (int i = 0; i < 10000000; i++) {
        if ((a * i) % b == c) {
            ans = true;
            break;
        }
    }

    if (ans) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  int n;
  cin >> n;
  
  int time[100][10];
  
  REP(i,n)
    REP(j,10)
      cin >> time[i][j];
  
  int p[100][11];
  REP(i,n)
    REP(j,11)
      cin >> p[i][j];
  

  //10bitの二進数の1,0で開店、閉店を全探索 ->高々1023通り
  int ans = -MOD;
  FOR(i,1,1<<10){
    int sum = 0;
    REP(j,n){
      int count = 0;
      REP(k,10){
        // iをk回右シフトしたものの最下位ビット(１との＆)
        if(i >> k & 1 == time[j][k]) count++;
      }
      sum += p[j][count];
    }
    ans = max(ans,sum);
  }
  
  cout << ans << endl;
  

 return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    sum = 0
    num = -1
    for i in range(N):
        if A[i] == num+1:
            sum += C[num-1]

        num = A[i]
        sum += B[num-1]
        save = num


    print(sum)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#define MN 201000

typedef long long ll;
int fa[MN];
int c1[MN], c2[MN];
int Min[MN];
ll D; int a[MN];
int X[MN], Y[MN];
int x[MN], y[MN];
ll ans = 0;
int bl;
int n;

int Abs(int a) {return a > 0 ? a : -a;}
ll F(int i) {return i ?  i * D + a[i] : 1e18;}
ll G(int i) {return i ? -i * D + a[i] : 1e18;}
ll H(int i, int j) {if(i == 0 || j == 0) return 1e18; return Abs(i - j) * D + a[i] + a[j];}

void add(int *c, int x, int v, int type)
{
	for(int i = x; i <= n; i += i & -i)
	{
		if(!type) if(F(v) < F(c[i])) c[i] = v;
		if( type) if(G(v) < G(c[i])) c[i] = v;
	}
}

int query(int *c, int x, int type)
{
	int ans = 0;
	for(int i = x; i; i -= i & -i)
	{
		if(!type) if(F(c[i]) < F(ans)) ans = c[i];
		if( type) if(G(c[i]) < G(ans)) ans = c[i];
	}
	return ans;
}

int Find(int x) {return fa[x] == x ? x : fa[x] = Find(fa[x]);}

void solve()
{
	memset(x, 0, sizeof x);
	memset(y, 0, sizeof y); 
	memset(c1, 0, sizeof c1);
	memset(c2, 0, sizeof c2);
	memset(Min, 0, sizeof Min);
	for(int i = 1; i <= n; i++)
	{
		int u = Find(i);
		int x = query(c1, u - 1, 1);
		int y = query(c2, n - u, 1);
		if(G(x) > G(y)) x = y;
		if(H(x, i) <= H(Min[i], i)) Min[i] = x;
		add(c1, u, i, 1);
		add(c2, n - u + 1, i, 1);
	}
	memset(c1, 0, sizeof c1);
	memset(c2, 0, sizeof c2);
	for(int i = n; i >= 1; i--)
	{
		int u = Find(i);
		int x = query(c1, u - 1, 0);
		int y = query(c2, n - u, 0);
		if(F(x) > F(y)) x = y;
		if(H(x, i) <= H(Min[i], i)) Min[i] = x;
		add(c1, u, i, 0);
		add(c2, n - u + 1, i, 0);
	}
	for(int i = 1; i <= n; i++)
	{
		int u = Find(i);
		if(H(i, Min[i]) < H(x[u], y[u])) x[u] = i, y[u] = Min[i];
	}
	int tot = 0;
	for(int i = 1; i <= n; i++)
	{
		int u = Find(i);
		++tot; X[tot] = x[u]; Y[tot] = y[u];
	}
	for(int i = 1; i <= tot; i++)
	{
		int x = Find(X[i]), y = Find(Y[i]);
		if(x == y) continue;
		ans += H(X[i], Y[i]);
		fa[x] = y;
		bl--;
	}
}

int main()
{
	scanf("%d%lld", &n, &D);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), fa[i] = i;
	bl = n;
	while(bl > 1) solve();
	printf("%lld\n", ans);
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  int m = in();
  rep(i,m){
    n -= in();
  }
  cout << max(-1,n) << endl;
  return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);
const int MAX_LOG = (int)(4e1 + 5);

int n;
ll k;
vector<ll> vec_a;

int cnt[MAX_LOG];
int best[MAX_LOG];

ll ans;

ll calc(ll x) {
  ll ret = 0LL;

  for (auto &a : vec_a) {
    ret += x ^ a;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &k);

  for (int i = 0; i < n; ++i) {
    ll a;
    scanf("%lld", &a);
    vec_a.push_back(a);
  }

  for (auto &a : vec_a) {
    for (int i = 0; i < MAX_LOG; ++i) {
      if (a >> i & 1LL) cnt[i] += 1;
    }
  }
  for (int i = 0; i < MAX_LOG; ++i) {
    int cnt_1 = cnt[i];
    int cnt_0 = n - cnt[i];

    if (cnt_1 >= cnt_0)
      best[i] = 0;
    else
      best[i] = 1;
  }

  ans = calc(k);

  for (int i = 0; i < MAX_LOG; ++i) {
    if (k >> i & 1LL) {
      vector<int> tmp(MAX_LOG);

      for (int j = 0; j < i; ++j) {
        tmp[j] = best[j];
      }

      tmp[i] = 0;

      for (int j = i + 1; j < MAX_LOG; ++j) {
        tmp[j] = (k >> j & 1) ? 1 : 0;
      }

      ll x = 0LL;

      for (int j = 0; j < MAX_LOG; ++j) {
        x += (ll)(tmp[j]) * 1LL << j;
      }

      ans = max(ans, calc(x));
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    char s[n][11];
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    for(int i = 0; i < n; i++){
        sort(s[i], s[i] + 10);
    }

    string t[n];
    for(int i = 0; i < n; i++){
        t[i] = s[i];
    }
    sort(t, t + n);
    
    string u = t[0];
    long int ans = 0;
    long int num = 1;
    for(int i = 1; i < n; i++){
        if (u == t[i]) num++;
        else {
            ans += (num * (num - 1)) / 2;
            u = t[i];
            num = 1;
        }
    }
    ans += (num * (num - 1)) / 2;
    printf("%ld\n", ans);
    
}

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

ll mod(ll a, ll b) {return (a % b + b) % b;}

ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

using namespace std;

int main() 
{	
	fast;
	ll k; cin>>k;
	ll a,b; cin>>a>>b; ll flag = 0;
	for(ll i = a; i <= b; i++)
	{
		if(i % k == 0)
		{
			flag = 1;
			break;
		}
	}
	if(flag == 1) cout << "OK" << endl;
	else cout << "NG" << endl;
 	return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){
    ll N;
    cin >> N;
    ll M = N - 1;
    ll ans = 0;
    // for(ll i = 1; i < N; i++){
    //     ans += i % (i + 1);
    // }
    ans = M * (M - 1) / 2 + (N - 1);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int next = 1;
        int result = 0;
        for(int i = 0; i < N; i++){
            int R = sc.nextInt();
            if(R == next){
                next++;
            }else{
                result++;
            }
        }
        System.out.println(result == N ? -1 : result);
    }
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm

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

    string st;
    cin >> st;

    if (st[0] == '9' || st[1] == '9') {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        for(int i=n-1;i>=0;i--){
            System.out.print(a[i]);
            if(i!=0){
            	System.out.print(" ");
            }
        }
        System.out.println();
        sc.close();
    }
}


Measured memory_bytes: 26340
x = input()

s = []
for i in range(len(x)):
    if x[i] == "S":
        s.append(x[i])
    else:
        if len(s) != 0 and s[-1] == "S":
            s.pop(-1)
        else:
            s.append(x[i])

print(len(s))

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

struct State {
  int x, y, t, w;
  bool operator < (const State &s) const {
    return w > s.w;
  }
};

const int MAXSIZE = 202;
const int INF = 1<<28;
const int dx[7] = {0,1,1,0,-1,-1,0};
const int dy[2][7] = {{1,0,-1,-1,-1,0,0},{1,1,0,-1,0,1,0}};

int sx, sy, gx, gy, lx, ly;
int H, W;
int G[MAXSIZE][MAXSIZE];
int cost[MAXSIZE][MAXSIZE][6];

int dijkstra() {
  priority_queue<State> que;
  fill(cost[0][0], cost[MAXSIZE][0], INF);
  cost[sy][sx][0] = 0;
  que.push((State){sx, sy, 0, 0});
  while (que.size()) {
    const State s = que.top();
    que.pop();
    if (cost[s.y][s.x][s.t] < s.w) continue;
    if (s.x == gx && s.y == gy) return s.w;
    const int c = (abs(s.x-lx) % 6) * (abs(s.y-ly) % 6) % 6 * s.t % 6;
    for (int k = 0; k < 7; ++k) {
      const State t = {s.x + dx[k], s.y + dy[abs(s.x-lx)%2][k],
                       (s.t + 1) % 6, s.w + (c != k)};
      if (t.x < 0 || t.x >= W) continue;
      if (t.y < 0 || t.y >= H) continue;
      if (G[t.y][t.x]) continue;
      if (cost[t.y][t.x][t.t] <= t.w) continue;
      cost[t.y][t.x][t.t] = t.w;
      que.push(t);
    }
  }
  return -1;
}

int main() {
  while (cin >> sx >> sy >> gx >> gy) {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i];
    }
    memset(G, 0, sizeof(G));
    cin >> lx >> ly;
    H = 2 * ly + 1;
    W = 2 * lx + 1;
    sx += lx;
    sy += ly;
    gx += lx;
    gy += ly;
    for (int i = 0; i < n; ++i) {
      G[y[i]+ly][x[i]+lx] = true;
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 2464
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner( System.in );
		int a = Integer.parseInt( scan.nextLine() );
		int b = Integer.parseInt( scan.nextLine() );
		int h = Integer.parseInt( scan.nextLine() );
		
		System.out.println( (a+b)*h/2 );
	}
}

Measured memory_bytes: 8788
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    int n,k;cin >> n >> k;
    int ans = 0;
    while(n){
        n /= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

if M == 1:
	print(1)
	sys.exit()

def factorization(n):
   arr = []
   temp = n
   for i in range(2, int(-(-n**0.5//1))+1):
       if temp%i==0:
           cnt=0
           while temp%i==0:
               cnt+=1
               temp //= i
           arr.append([i, cnt])
   if temp!=1:
       arr.append([temp, 1])
   if arr==[]:
       arr.append([n, 1])
   return arr

fact_max = 10**6  # 必要そうな階乗の限界を入れる
factorial = [1]
for i in range(1, fact_max):
    factorial.append(factorial[i-1] * i % mod)

def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod

def C(n, r):
    return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod

x_inv = [0] * fact_max
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(fact_max-2, -1, -1):
    x_inv[i] = x_inv[i+1] * (i+1) % mod

fact = factorization(M)
ans = 1
for n, power in fact:
	ans = (ans * C(power+N-1, power))%mod

print(ans)


Measured memory_bytes: 96208
while True:
    entry = map(str, raw_input().split())
    a  = int(entry[0])
    op = entry[1]
    b  = int(entry[2])
    if op == "?":
        break
    elif op == "+":
        ans = a + b
    elif op == "-":
        ans = a - b
    elif op == "*":
        ans = a * b
    elif op == "/":
        ans = a / b
    print(ans)

Measured memory_bytes: 6452
#include <stdio.h>

int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int l=a+b;
    int r=c+d;
    if(r==l){
        printf("Balanced\n");
    }else{
        printf("%s\n", r>l?"Right":"Left");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

int a, b, c, d, e, f, g;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
	}
	return 0;
}

// type below
vector<int> V[200050];
void solve()
{
	cin >> a >> b;
	int arr[a + 50];
	for(int i=1; i<=a; i++)
		cin >> arr[i];
	for(int i=0; i<b; i++)
	{
		int x, y; cin >> x >> y;
		V[x].push_back(y);
		V[y].push_back(x);
	}
	bool check[a + 50] = {0};
	int ans = 0;
	for(int i=1; i<=a; i++)
	{
		if(check[i]) continue;
		bool yes = true;
		for(int x : V[i])
		{
			if(arr[x] >= arr[i])
			{
				yes = false;
			}
			else
			{
				check[x] = true;
			}
		}
		if(yes) ans ++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 11600
#include <bits/stdc++.h>
using namespace std;
#define fin(ans) cout << ans << endl

int main(void) {
  long long int n;
  cin >> n;
  while(1){
    bool flag = true;
    for (int i = 2; i  < n; i++) {
      if (n % i == 0) {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      fin(n);
      return 0;
    }
    n++;
  }
  return 0;
}


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

using namespace std;

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

vector<int> nails[5010];

int main() {
  rep (i, 5010) rep (j, i + 10) nails[i].push_back(0);
  int n, m;
  cin >> n >> m;
  rep (i, m) {
    int a, b, x;
    cin >> a >> b >> x;
    --a;
    --b;
    ++nails[a][b];
    --nails[a][b + 1];
    --nails[a + x + 1][b];
    ++nails[a + x + 2][b + 1];
    ++nails[a + x + 1][b + x + 2];
    --nails[a + x + 2][b + x + 2];
  }
  rep (i, n + 3) rep (j, i + 3) {
    nails[i][j + 1] += nails[i][j];
  }
  rep (i, n + 3) rep (j, i + 3) {
    nails[i + 1][j] += nails[i][j];
  }
  rep (i, n + 3) rep (j, i + 3) {
    nails[i + 1][j + 1] += nails[i][j];
  }
  int res = 0;
  rep (i, n + 3) rep (j, i + 3) {
    if (nails[i][j] > 0) ++res;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 63144
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

const ll MOD = 1e9+7;

int main(){
  ll n,m,q; cin >> n >> m >> q;
  vector<vector<ll>> cnt(n+1,vector<ll>(n+1,0));
  vector<vector<ll>> sum(n+1,vector<ll>(n+1,0));
  REP(i,m){
    ll l,r; cin >> l >> r;
    cnt[l][r]++;
  }
  FOR(i,1,n+1) FOR(j,1,n+1) sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + cnt[i][j];
  REP(i,q){
    ll p,q; cin >> p >> q;
    cout << sum[q][q] - sum[p-1][q] - sum[q][p-1] + sum[p-1][p-1] << endl;
  }
}


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

//Minimum Macros
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define rep(_i,_n) for(ll _i = 0; _i < _n; ++_i)
#define rep2(_i,_s,_n) for(ll _i = _s; _i < _n; ++_i)
#define elif else if
//Vector Macros
#define vec vector
#define append(_x) push_back(_x)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) vec<int> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecL(_name, _n) vec<long> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecLL(_name, _n) vec<ll> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecUL(_name, _n) vec<ul> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecULL(_name, _n) vec<ull> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecS(_name, _n) vec<string> _name(_n);rep(_i, _n)cin >> _name[_i];
#define maxIdx(_name) distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec) cout << "{";rep(i, _vec.size()-1)cout << _vec[i] << ",";cout << _vec[_vec.size()-1];cout << "}\n";
//Graph Macros
using Graph = vec<vec<long>>;
inline vec<long> BFS(Graph _g, long start){
  vec<long> _ans(_g.size(), -1); _ans[start] = 0; queue<long> _que; _que.push(start);
  while(!_que.empty()){
    long _target = _que.front(); _que.pop();
    for(long _towhere : _g[_target]){
      if(_ans[_towhere] == -1){
        _ans[_towhere] = _ans[_target] + 1; _que.push(_towhere);
      }
    }
  }
  return _ans;
}

int main()
{
    ull N;
    cin >> N;
    ull buf1 = 1, buf2 = 0;
    ull ans = 0;
    ull last = 2;
    if(N == 1){
      cout << "0" << endl;
      return 0;
    }
    for(ull i = 2; i * i <= N;){
      if(N % i == 0){
        last = i;
        N /= i;
        buf2++;
        if(buf2 >= buf1){
          buf2 = 0;
          buf1++;
          ans++;
        }
      }
      else{
        buf1 = 1; buf2 = 0;
        i++;
      }
    }
    if(last == N){
      buf2++;
      if(buf2 >= buf1){
        buf2 = 0;
        buf1++;
        ans++;
      }
    }
    else{
      ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int n;ll l;
    cin >> n >> l;

    vector<ll> rope(n);
    for(ll& a:rope){
        cin >> a;
    }

    int pos=-1;
    forn(i,n-1){
        if(rope[i]+rope[i+1]>=l)pos=i;
    }
    if(pos!=-1){
        cout << "Possible" << endl;
        forn(i,pos)cout << i+1 << endl;
        dforsn(i,pos+1,n)cout << i << endl;
    }
    else cout << "Impossible" << endl;

	
	return 0;
}



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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s,t,u;
    cin >> s >> t >> u;;
    cout << 'A' << t.at(0) << 'C' << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
}



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

bool pal(string S)
{
  string T = S;
  reverse(T.begin(), T.end());
  return (T == S);
}

int main()
{
  string S;
  cin >> S;
  int64_t N = S.size();
  string s1 = S.substr(0, N / 2);
  string s2 = S.substr(N / 2 + 1, N / 2);
  if (pal(S) && pal(s1) && pal(s2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*c, a*d), max(b*c, b*d)) << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    for (int i=0, n=s.size(); i<n; i++) {
        ans++;
        if (i+1<n && s[i]==s[i+1]) {
            if (i+2>=n) break;
            ans++;
            i+=2;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 720
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
 
  
int main(){
  int h,a;
  cin>>h>>a;
  h+=a-1;
  h/=a;
  cout<<h<<"\n";  
  return 0;
}

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

int main() {
  string a;
  cin >> a;
  if(a.at(2)==a.at(3) && a.at(4)==a.at(5)){
    cout << "Yes" << endl; 
  }
  else{
  cout << "No" << endl; 
  }  
}

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

int w,h;
int board[30][30];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int ans = 1000000;

void dfs(int y_,int x_,int cnt) {
    if(cnt == 10) return;
    //cout<<y_<<","<<x_<<","<<cnt<<endl;
    rep(i,4) {
        int x = x_ + dx[i];
        int y = y_ + dy[i];
        if(!((0<=y&&y<h) && (0<=x&&x<w))) continue;
        if(board[y][x] == 1) continue;
        
        while(1) {
            //cout<<y<<","<<x<<endl;
            if(!((0<=y&&y<h) && (0<=x&&x<w))) {
                break;
            }

            if(board[y][x] == 3) {
                ans = min(ans,cnt+1);
                return;
            }
            if(board[y][x] == 1) {
                board[y][x] = 0;
                dfs(y-dy[i],x-dx[i],cnt+1);
                board[y][x] = 1;
                break;
            }
            y+=dy[i];
            x+=dx[i];
        }
        
    }
}
void solve() {
    rep(i,30) rep(j,30) board[30][30] = 0;
    ans = 100000000;
    int sx,sy;
    rep(i,h) rep(j,w) {
        cin>>board[i][j];
        if(board[i][j] == 2) {
            sy = i;
            sx = j;
        }
    }

    dfs(sy,sx,0);
    if(ans == 100000000) ans = -1;
    cout<<ans<<endl;


}
int main() {
    while(cin>>w>>h) {
        if(w+h==0) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,i,j;
	char s[101][101]={0};
	cin>>n>>m;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>s[i][j];
			if(s[i][j]!='#'){
				s[i][j]='0'; 
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(s[i][j]!='#'){
				if(s[i-1] [j]=='#')s[i] [j]++;
				if(s[i+1] [j]=='#')s[i] [j]++;
				if(s[i] [j+1]=='#')s[i] [j]++;
				if(s[i] [j-1]=='#')s[i] [j]++;
				if(s[i-1] [j+1]=='#')s[i] [j]++;
				if(s[i-1] [j-1]=='#')s[i] [j]++;
				if(s[i+1] [j+1]=='#')s[i] [j]++;
				if(s[i+1] [j-1]=='#')s[i] [j]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++)
			cout<<s[i][j];
		cout<<endl;
	}
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using P = pair<int,int>;
using node = pair<string,ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;


int main(void) {
  string s;
  cin >> s;
  string mm = s.substr(5,2);
  cout << (mm > "04" ? "TBD" : "Heisei") << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    int ans = 10000;
    for (int i = 0; i <= n; i++) {
        int left = 0;
        for (int j = 0; j < i; j++) {
            left += w[j];
        }
        int right = 0;
        for (int j = i; j < n; j++) {
            right += w[j];
        }
        ans = min(ans, abs(left - right));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
MAX_K: int = 200

gt = [[0 for _ in range(MAX_K + 1)] for _ in range(MAX_K + 1)]

def gcd(x: int, y: int) -> int:
    if gt[x][y] > 0:
        return gt[x][y]
    ret: int = 0
    if x < y:
        ret = gcd(y, x)
    elif y == 0:
        ret = x
    elif y == 1:
        ret = 1
    else:
        ret = gcd(y, x % y)
    gt[x][y] = ret
    # print(f"gcd({x}, {y}) = {ret}")
    return ret

k = int(input())
print(sum([gcd(gcd(i + 1, j + 1), l + 1) for i in range(k) for j in range(k) for l in range(k)]))


Measured memory_bytes: 209592