akhauriyash/Code-Regression huggingface dataset:
// queue
#include <iostream>
#define LEN 100005
using namespace std;

struct work
{
    std::string s;
    int t;
} ;

work qline[LEN];
int head, tail, n;


void enqueue(work x){
    qline[tail] = x;
    tail = (tail + 1) % LEN;

}


work dequeue(){
    work x = qline[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){
    return a<b?a:b;
}


int main(){
    int elapsedtime=0;
    int c;
    int i, q;
    work u;
    /*
    cout << "test" << endl;
    cin >> u.s;
    cin >> u.t;

    cout << u.s << " " << u.t << endl;
    */

    cin >> n >> q;

    for(i=1; i<=n; i++){
        cin >> qline[i].s >> qline[i].t;
    }
    head = 1;
    tail = n+1;

    // run
    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= q;
        elapsedtime += c;
        if(u.t>0){
            enqueue(u);
        }
        else{
            cout << u.s << " " << elapsedtime << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 6960
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int n,m,l;
  cin >> n;
  vector<int> a;
  REP(i,n){
    cin >> m;
    a.push_back(m);
  }
  SORT(a);
  m = a[n-1];
  l = 0;
  REP(i,n){
    if (m > abs(a[n-1]-a[i]*2)) {
      m = abs(a[n-1]-a[i]*2);
      l = a[i];
    }
  }
  cout << a[n-1] << " " << l;
  return 0;
}

Measured memory_bytes: 892
s = input()
n = len(s)
k = int(input())

dp = [[[0 for _ in range(2)] for _ in range(k + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for l in range(n):
    for m in range(k + 1):
        for o in range(2):
            nd = int(s[l])
            for d in range(10):
                nl, nm, no = l + 1, m, o
                if d != 0:
                    nm += 1
                if nm > k:
                    continue
                if 0 == o:
                    if d > nd:
                        continue
                    if d < nd:
                        no = 1
                dp[nl][nm][no] += dp[l][m][o]
print(sum(dp[-1][-1]))


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

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n+1],b[n+1],c[n+1],dp[n+1][3];
   for(int x=1;x<=n;x++)
   {
       cin>>a[x]>>b[x]>>c[x];
   }
   for(int x=0;x<n+1;x++)
   {
       for(int y=0;y<3;y++)
       {
           dp[x][y]=-1;
       }
   }
   dp[0][0]=dp[0][1]=dp[0][2]=0;
   for(int x=1;x<=n;x++)
   {
       dp[x][0]=max(dp[x-1][1]+a[x],dp[x-1][2]+a[x]);
       dp[x][1]=max(dp[x-1][0]+b[x],dp[x-1][2]+b[x]);
       dp[x][2]=max(dp[x-1][0]+c[x],dp[x-1][1]+c[x]);
   }
   cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;;
}








Measured memory_bytes: 5896
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int R0 = sc.nextInt();
			int W0 = sc.nextInt();
			int C = sc.nextInt();
			int R = sc.nextInt();
			if(R0==0 && W0==0 && C==0 && R==0) break;
			int min=0;
			for(int i=0; ; i++) {
				if(W0 * C <= R0 + R * i) {
					min = i;
					break;
				}
			}
			System.out.println(min);
		}
	}
}



Measured memory_bytes: 26484
k, n = map(int, input().split())
lst = list(map(int, input().split()))

dlst = []
for i in range(1, n):
      dlst.append(lst[i] - lst[i-1])
    
dlst.append(lst[0] + (k - lst[-1]))

dlst.remove(max(dlst))
ans = sum(dlst)
print(ans)

Measured memory_bytes: 26000
#include <iostream>

using namespace std;

int main(void)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a * b > c * d) {
		cout << a * b << endl;
	}
	else {
		cout << c * d << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc045/tasks/arc061_a?lang=ja

int main() {
    string S; cin >> S;
    int len = S.length();
    ll ans = 0;

    for (int msk = 0; msk < 1 << (len-1); msk++) {
        ll num = S[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (msk & 1 << i) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> r(n), g(n), b(n);
    r.resize(0); g.resize(0); b.resize(0);
    rep(i, n)
    {
        auto c = s[i];
        if(c == 'R')
        {
            r.push_back(i);
        }
        else if(c == 'G')
        {
            g.push_back(i);
        }
        else
        {
            b.push_back(i);
        }
    }
    ll ans = 0;
    for(auto ri : r)
    {
        for(auto gi : g)
        {
            auto h = max(ri, gi);
            auto l = min(ri, gi);
            auto diff = h - l;
            auto exclude = 0;
            if(binary_search(b.begin(), b.end(), l - diff))
            {
                exclude++;
            }
            if(binary_search(b.begin(), b.end(), h + diff))
            {
                exclude++;
            }
            if(diff % 2 == 0)
            {
                if(binary_search(b.begin(), b.end(), l + diff / 2))
                {
                    exclude++;
                }
            }
            ans += (int)b.size() - exclude;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
int H,W,h,w;
int board[105][105];
int mxindex,mxchain=0;
int X;
int main(void)
{
  cin >> X;
  if(X ==3 || X==5 || X==7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int abs(int a) {
    if (a < 0) return -a;
    return a;
}

int main() {
    int N = 0, K = 0;
    scanf("%d %d", &N, &K);

    int (*candle) = new int[N]();
    for (int i = 0; i < N; i++) {
        scanf("%d", &(candle[i]));
    }

    if (K == 1) {
        printf("%d\n", abs(candle[0]));
        return 0;
    }

    int i = 0, j = 0;
    long sum = 0, rlt = ((unsigned long)-1) >> 1;

    for (; j + 1 < K; j++) {
        sum += abs(candle[j] - candle[j + 1]);
    }
    // printf("[DEBUG] sum[0] = %ld\n", sum);

    for (; j < N; i++, j++) {
        // printf("[DEBUG] [%d][%ld][%d]\n", candle[i], sum, candle[j]);
        long temp = (abs(candle[i]) < abs(candle[j])) ? (sum + abs(candle[i])) : (sum + abs(candle[j]));
        // printf("[DEBUG] rlt = %ld -> %ld\n", rlt, temp);
        if (temp < rlt) {
            rlt = temp;
        }

        sum = sum - abs(candle[i + 1] - candle[i]) + abs(candle[j + 1] - candle[j]);
        // printf("[DEBUG] sum = %ld\n", sum);
    }
    printf("%ld\n", rlt);

    return 0;
}


Measured memory_bytes: 640
from numpy import prod
N = int(input())
S = input()
appearances = {"R": 0, "G": 0, "B": 0}
for c in S:
    appearances[c] += 1
print(prod(list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1)))


Measured memory_bytes: 27228
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	cards := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	pointA, pointB := 0, 0
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			pointA += cards[i]
		} else {
			pointB += cards[i]
		}
	}

	fmt.Println(pointA - pointB)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1505;
typedef long long ll;
template <typename T> inline void chkmax(T &x, T y) {x = (x > y) ? x : y; }
template <typename T> inline void chkmin(T &x, T y) {x = (x < y) ? x : y; } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN][MAXN];
short l[MAXN][MAXN], r[MAXN][MAXN];
int n, a[MAXN][MAXN], res[MAXN][MAXN];
int main() {
	read(n);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= n; j++)
			if (s[i][j] == '#') a[i][j] = 0;
			else a[i][j] = s[i][j] - '0';
	}
	ll finalans = 0;
	for (int i = n; i >= 1; i--)
	for (int j = n; j >= 1; j--) {
		if (a[i][j] != 0) {
			if (a[i + 1][j] == 0 && a[i][j + 1] == 0) l[j][i] = r[j][i] = j;
			else if (a[i + 1][j] == 0) {
				memcpy(l[j] + i, l[j + 1] + i, sizeof(short) * (n - i + 1));
				memcpy(r[j] + i, r[j + 1] + i, sizeof(short) * (n - i + 1));
				l[j][i] = j, res[i][j] = res[i][j + 1];
			} else if (a[i][j + 1] == 0) {
				l[j][i] = r[j][i] = j;
				res[i][j] = res[i + 1][j];
			} else {
				short Max = 0; int ans = res[i + 1][j] + res[i][j + 1];
				l[j][i] = j, r[j][i] = r[j + 1][i];
				for (int k = i + 1; k <= n; k++) {
					if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > Max) ans -= res[k][l[j + 1][k]];
					chkmax(Max, r[j][k]);
					chkmax(r[j][k], r[j + 1][k]);
					chkmin(l[j][k], l[j + 1][k]);
				}
				res[i][j] = ans;
			}
			finalans += a[i][j] * res[i][j];
			res[i][j] += a[i][j];
		} else {
			memset(l[j] + i, 0x3f, sizeof(short) * (n - i + 1));
			memset(r[j] + i, 0, sizeof(short) * (n - i + 1));
		}
	}
	cout << finalans << endl;
	return 0;
}

Measured memory_bytes: 29056
object Main extends App{
    def qABC087B(a:Int,b:Int,c:Int,x:Int) = {
        (
            for(x<-0 to a;y<-0 to b; z<-0 to c) 
                yield(x*500+y*100+z*50)
        ).count(_==x)
    }
    println(qABC087B(readInt, readInt, readInt, readInt))
}


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

using namespace std;

struct AP {
    int n;
    vector<vector<int>> g;
    set<int> points;
    vector<int> parent;
    vector<int> discTime;
    vector<int> lowTime;
    vector<bool> visited;
    vector<pair<int, int>> bridges;
    int time = 0;
    
    AP(int n): n(n) {
        g.assign(n, vector<int>());
        parent.assign(n, -1);
        discTime.assign(n, 0);
        lowTime.assign(n, n + 1);
        visited.assign(n, false);
    }
    
    void addEdge(int from, int to) {
        g[from].push_back(to);
        g[to].push_back(from);
    }
    
    int solve() {
        dfs(0, -1);
        
        int son = 0;
        for (int i = 1; i < n; i++) {
            int p = parent[i];
            if (p == 0) {
                son++;
            }
            else if (discTime[p] <= lowTime[i]) {
                points.insert(p);
            }
            //For bridges
            if (discTime[p] < lowTime[i]) {
                bridges.push_back(make_pair(min(p, i), max(p, i)));
            }
        }
        if (son > 1) {
            points.insert(0);
        }
//        for (int point: points) {
//            cout << point << endl;
//        }
        return points.size();
    } 
    
    void dfs(int u, int p) {
        discTime[u] = time++;
        lowTime[u] = discTime[u];
        visited[u] = true;
        for (int v : g[u]) {
            if (!visited[v]) {
                parent[v] = u;
                dfs(v, u);
                lowTime[u] = min(lowTime[u], lowTime[v]);
            }
            else if (v != p) {
                lowTime[u] = min(lowTime[u], discTime[v]);
            }
        }
    }   
};

int main() {
    int n, m;
    cin >> n >> m;
    AP ap(n);
    
    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        ap.addEdge(from, to);
    }
    
    int ans = ap.solve();
    sort(ap.bridges.begin(), ap.bridges.end());
    for (pair<int, int> p : ap.bridges) {
        cout << p.first << " " << p.second << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4328
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    const ll N=26;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(N,vi(D));
    rep(i,0,N){
        rep(j,0,D) cin>>A[i][j];
    }
    vi last(N,-1);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[j][i]+(i-last[j])*C[j]){
                max=A[j][i]+(i-last[j])*C[j];
                memo=j;
            }
        }
        cout<<memo+1<<endl;
        last[memo]=i;
    }
}


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

int main(){
  string s;
  int x, y;
  for (int i = 0; i < 9; i++) {
    std::cin >> s >> x >> y;
    std::cout << s << " " << x + y << " " << 200*x + 300*y << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    h = N[2:]
    K = N[1]
    N = N[0]

    h.sort(reverse=True)
    ans = max(h) - min(h)
    for i in range(0, N - K + 1):
        d = h[i] - h[i + K -1]
        if d < ans:
            ans = d
    print(ans)


main()

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)


int main() {
	int h, w;
	cin >> h >> w;
	vector<string> grid;
	FOR(i, 0, h-1) {
		string s;
		cin >> s;
		grid.push_back(s);
	}
	while (1) {
		bool oped1=false;
		bool oped2=false;

		set<int> delset = {};
		FOR(i, 0, h - 1) {
			bool isyoko = true;
			oped1 = false;
			FOR(j, 0, w - 1) {
				if (grid[i][j] == '#') {
					isyoko = false;
				}
			}
			if (isyoko) {
				oped1 = true;
				delset.insert(i);
			}
		}
		vector<string>ngrid;
		FOR(i,0,h-1) {
			if (delset.count(i)) {
				continue;
			}
			else {
				ngrid.PB(grid[i]);
			}
		}
		h -= delset.size();
		grid = ngrid;


		delset = {};
		ngrid = {};
		FOR(j, 0, w - 1) {
			bool istate = true;
			oped2 = false;
			FOR(i, 0, h - 1) {
				if (grid[i][j] == '#') {
					istate = false;
				}
			}
			if (istate) {
				oped2 = true;
				delset.insert(j);
			}
		}
		FOR(i, 0, h - 1) {
			string tmp;
			FOR(j, 0, w - 1) {
				if (delset.count(j)) {
					continue;
				}
				else {
					tmp.PB(grid[i][j]);
				}
			}
			ngrid.PB(tmp);
		}
		w -= delset.size();
		grid = ngrid;


		if (oped1 || oped2) {
			continue;
		}
		else {
			break;
		}
	}

	FOR(i, 0, h - 1) {
		cout << grid[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3620
#include"bits/stdc++.h"
using namespace std;
#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 int long long
using vi=vector<int>;
using vvi=vector<vi>;

//#define INF 0x3f3f3f3f

signed main() {
	cout << fixed << setprecision(10);
	int N, K, T, U, V, L; cin >> N >> K >> T >> U >> V >> L;
	vector<int> D(N);
	vector<bool> c(L + 1);
	rep(i, 0, N) {
		cin >> D[i];
		c[D[i]] = true;
	}

	double ans = 0;
	int k = 0;
	int life = 0;
	rep(i, 1, L + 1) {
		if (life) {
			ans += 1.0 / V;
			life--;
		}
		else {
			ans += 1.0 / U;
		}

		if (c[i]) {
			if (k == K) {
				life = V * T;
			}
			else {
				k++;
			}
		}

		if (life == 0 && k) {
			k--;
			life += V * T;
		}

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
char st[200009];
int main(){

   // freopen("input.txt","r",stdin);
    scanf("%s",st);
    //printf("%s",st);
    int n=strlen(st),cur_siz=1,cnt=1,lst=st[0]-'a';
    for(int i=1;i<n;){

        if(cur_siz==1&&st[i-1]-'a'==st[i]-'a'){

            if(i+1<n){
                cnt++;
                cur_siz=2;
                i+=2;
            }
            else
                i++;
        }
        else{
            cnt++;
            lst=st[i]-'a';
            cur_siz=1;
            i++;
        }

    }
    printf("%d\n",cnt);
}




Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
 
int main(int argc, char const *argv[])
{
	int n;
	int l,r;

	scanf("%d",&n);
	l = n / 100;
	r = n % 100;

	if( 1 <= l && l <= 12 )
	{
		if( 1 <= r && r <= 12 )
			puts("AMBIGUOUS");
		else
			puts("MMYY");
	}
	else{
		if( 1 <= r && r <= 12 )
			puts("YYMM");
		else
			puts("NA");
	}

	return 0;
}

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

int main(){
  int n,d;
  cin >> n >> d;
  vector< vector<int> > x(20,vector<int>(20,0));
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> x[i][j];
    }
  }
  int ans=0;
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      double s=0;
      for(int k=0; k<d; k++){
        s += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
      }
      //ここで距離が整数かどうか判定
      //cout << sqrt(s) << endl;
      for(int l=0; l<160; l++){
        if(sqrt(s) == l){
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		int W = Integer.parseInt(st.nextToken());
		int[] v = new int[n];
		int[] w = new int[n];
		for (int i = 0; i < n; i++) {
			st = new StringTokenizer(reader.readLine());
			v[i] = Integer.parseInt(st.nextToken());
			w[i] = Integer.parseInt(st.nextToken());
		}		
		reader.close();
		System.out.println(getMaxValue(n, W, v, w));
	}
	private int getMaxValue(int n, int W, int[] v, int[] w) {
		int[][] dp = new int[n+1][W+1];
		for (int i = 0; i < n; i++) {
			int vl = v[i];
			int wt = w[i];
			for (int j = 0; j <= W; j++) {
				if (wt > j) {
					dp[i+1][j] = dp[i][j];
				} else {
					dp[i+1][j] = Math.max(dp[i][j], dp[i][j-wt] + vl);
					dp[i+1][j] = Math.max(dp[i][j], dp[i+1][j-wt] + vl);
				}
			}
		}
		return dp[n][W];
	}
}


Measured memory_bytes: 29276
// Aizu Vol-1 0178: TETORIS
// 2017.8.23 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 5002
typedef struct { int p, n; char w, f[6]; } T;
T tbl[MAX+10];
int top[6], tt;

void adj(int x, int h)
{
	int i, xx, lim;
	int prev, next;

	for (xx = x, i = 0; i < h; i++, xx = tbl[xx].n); lim = xx;
	if (lim < tt ) lim = tt;
	for (i = 0; i < h; i++, x = tbl[x].n) {
		if (tbl[x].w == 5) {
			prev = tbl[x].p, next = tbl[x].n;
			tbl[prev].n = next, tbl[next].p = prev;
		}
	}
	for (xx = -1, i = 1; i <= 5; i++) {
		for (h = 0, x = tbl[0].n; x != lim; x = tbl[x].n) if (tbl[x].f[i]) h = x;
		if ((top[i] = tbl[h].n) > xx) xx = top[i];
	}
	tt = xx;
}

int main()
{
	int n, d, p, q;
	int i, j, h, x, ans;

	while (scanf("%d", &n) && n) {
		for (i = 1; i < MAX; i++) {
			tbl[i].n = i+1, tbl[i].p = i-1, tbl[i].w = 0;
			for (j = 1; j <= 5; j++) tbl[i].f[j] = 0;
		}
		tbl[0].n = 1, tt = 1; for (i = 1; i <= 5; i++) top[i] = 1;
		while (n-- > 0) {
			scanf("%d%d%d", &d, &p, &q);
			if (d == 1) {	// yoko
				for (h = -1, i = 0; i < p; i++) {
					if (top[q+i] > h) h = top[q+i];
				}
				tbl[h].w += p;
				for (i = 0; i < p; i++) tbl[h].f[q+i] = 1;
				adj(h, 1);
			} else {
				x = h = top[q];
				for (i = 0; i < p; i++, x = tbl[x].n) tbl[x].w++, tbl[x].f[q] = 1;
				adj(h, p);
			}
		}
		for (ans = 0, x = tbl[0].n; x != tt; x = tbl[x].n) ans += tbl[x].w;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 676
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define INF 1000000 
#define M 1000000007
#define PI 2 * acos(0.0)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
bool is_palindrome(string s){
     ll j = s.length()-1;
     ll i = 0;
     while(i < j){
         if(s[i] != s[j]){
             return false;
         }
         i++;
         j--;
     }
     ll n = s.length();
     ll o = ((n-1)/2) - 1;
     i = 0;
     while(i < o){
         if(s[i] != s[o]) return false;
         i++;
         o--;
     }
     ll r = (n+3)/2 - 1;
     j = n-1;
     while(r < j){
         if(s[r] != s[j]) return false;
         r++;
         j--;
     }
     return true;
}
int main(){
    fast_io 
    string s;
    cin>>s;
    if(is_palindrome(s) == true){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int n;
  cin>>n;
  vv(string) ans(11);
  ans[0].pb("a");
  rep(i,n){
    for(auto s:ans[i]){
      set<char> se;
      for(int sk=0 ; sk<s.length();sk++){
        se.insert(s[sk]);
      }
      rep(j,se.size()+1){
        char c = 'a'+j;
        ans[i+1].pb(s+(string){c});
      }
    }
  }
  sort(rng(ans[n-1]));
  for(auto s:ans[n-1]){
    cout<<s<<endl;
  }

} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 47592
N_str = input()

ans = 0
if len(N_str) % 2 == 1:
    N = int(N_str)
    ans += N - 10**(len(N_str)-1) + 1

for i in range(0, len(N_str)-1, 2):
    ans += 10**(i+1) - 10**i

print(ans)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	long long int n, k;
	cin >> n >> k;
	int cnt=0;
	for (int i = 1; i < 1000; i++)
	{
		if (pow(k, i) > n)
		{
			cnt = i;
			break;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3948
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

bool f(string s) {
  vs t;
  t.pb("the");
  t.pb("the.");
  t.pb("this");
  t.pb("this.");
  t.pb("that");
  t.pb("that.");
  stringstream ss;
  ss << s;
  string x;
  while (ss >> x) {
    if (find(all(t), x) != t.end()) return true;
  }
  return false;
}

void nextS(string &s) {
  rep(i, s.size()) {
    if ('a' <= s[i] && s[i] <= 'z') {
      s[i] = (s[i] - 'a' + 1) % 26 + 'a';
    }
  }
}

void solve() {
  string s;
  while (getline(cin, s)) {
    do {
      if (f(s)) {
        cout << s << endl;
        break;
      }
    } while (nextS(s), 1);
  }
}

Measured memory_bytes: 3072
import math


def resolve():
    import sys
    input = sys.stdin.readline
    row1 = [int(x) for x in input().rstrip().split(" ")]
    s = row1[0]

    x = int(s / 1.08)

    if math.floor(x*1.08) == s:
        print(x)
    elif math.floor((x+1)*1.08) == s:
        print(x+1)
    else:
        print(":(")



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
   ll n,m;
   cin >>n>>m;
   ll a,b;
   vector <ll> s,g;
   for(ll i=0;i<m;i++){
     cin >>a>>b;
     if(a==1) s.push_back(b);
     if(b==n) g.push_back(a);
   }
   ll ss=s.size(),bs=g.size();
   sort(g.begin(),g.end());
   if(ss==0||bs==0) cout <<"IMPOSSIBLE"<<endl;
   else{
     for(ll i=0;i<ss;i++){
       if(binary_search(g.begin(),g.end(),s[i])){
         cout <<"POSSIBLE"<<endl;
         return 0;
       }
     }
     cout <<"IMPOSSIBLE"<<endl;
   }
}


Measured memory_bytes: 2004
H,W = map(int,input().split())

lst = [str(input()) for _ in range(H)]

#print(lst)

def check(y,x):
    if x < 0 or x >= W or y < 0 or y >= H:
        return 0
    elif lst[y][x] == '#':
        return 1
    else:
        return 0


fin = [[] for _ in range(H)]
dxy = [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1)]
for j in range(H):
    for i in range(W):
    
        sol = 0
        if lst[j][i] == '#':
            sol = '#'
        else:
            for dy,dx in dxy:
                sol += check(j+dy,i+dx)
            
        fin[j].append(str(sol))    
    print(*fin[j],sep = '')

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pi  acos(-1)
const int w=5e5+5;
const ll mod=1e9+7;
int a[15];
int n;
void dfs(int pos,int x)
{
    if(pos==n+1)
    {
        for(int i=1;i<=n;i++)
        {
            char c=a[i]-1+'a';
            printf("%c",c);
        }
        printf("\n");
        return ;
    }
    for(int j=1;j<=x+1;j++)
    {
        a[pos]=j;
        dfs(pos+1,max(x,j));
    }
}
int main()
{
    int i,j;
    cin>>n;
    dfs(1,0);
    return 0;
}


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

int main(void) {
  int a, b;
	cin >> a >> b;
  string out;
  if (a == 1) { a = 14; }
  if (b == 1) { b = 14; }
  if (a > b) {
    out = "Alice";
  } else if (a == b) {
    out = "Draw";
  } else {
    out = "Bob";
  }
  cout << out << '\n';
}



Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 23.11.2019 17:41:21       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> s(2);
  for (int i = 0; i < n; i++) {
    s[i % 2] += a[i];
  }
  if (n % 2 == 0) {
    cout << max(s[0], s[1]) << " " << min(s[0], s[1]) << '\n';
    return 0;
  }
  int low = s[0], high = s[0] + s[1];
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    vector<bool> dp(n + 2, false);
    dp[0] = true;
    int take = s[1];
    for (int j = 0; j < n; j++) {
      if (dp[j]) {
        take = max(take, s[1]);
      }
      if (j % 2 == 0) take += a[j];
      else take -= a[j];
      if (j % 2 == 0 && take >= mid) {
        dp[j + 2] = true;
      }
    }
    if (dp[n + 1]) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << low << " " << s[0] + s[1] - low << '\n';
  return 0;
}


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

n, m = map(int, input().split())

ab = [list(map(int, input().split())) for i in range(m)]

ar = [0 for i in range(n)]

for i in range(m):
    a, b = ab[i]
    ar[a-1] += 1
    ar[b-1] += 1

for i in ar:
    print(i)


Measured memory_bytes: 3060
n, m = map(int, input().split())
K = []
A = []
for i in range(n):
    L = list(map(int, input().split()))
    K.append(L[0])
    A.append(L[1:])
# print(A)
Aall = []
for e in A:
    Aall += e
# print(Aall)
ans = 0
for i in range(1, m + 1):
    if Aall.count(i) == n:
        ans += 1
print(ans)


Measured memory_bytes: 3064
// 幹線道路 2018/12/27

#include <iostream>
#include <climits>
#include <cstdlib>
using namespace std;


int main() {
    int H, W;
    int A[25][25];
    int h, w, i, j;
    int mini = INT_MAX;
    int total;
    cin >> H >> W;
    for (int row = 0; row < H; row++) {
        for (int col = 0; col < W; col++) {
            cin >> A[row][col];
        }
    }

    for (h = 0; h < H; h++) {
        for (w = 0; w < W; w++) {
        // 幹線道路は北からh番目と西からw番目
            total = 0;
            for (i = 0; i < H; i++ ) {
                for (j = 0; j < W; j++ ) {
                    int dist = min(abs(i - h), abs(j - w));
                    total += dist * A[i][j];
                };
                if (total > mini) break;
            }
            mini = min(mini, total);
        }
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=200005;

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",(a-1)/b+1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

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

public class Main {
    public static void main(String[] arg) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int K = scan.nextInt();
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = scan.nextInt();
        }
        Arrays.sort(h);
        int min = (int)Math.pow(10, 9);

        for (int i = 0; i <= N - K; i++) {
            if (h[i + K - 1] - h[i] < min) {
                min = h[i + K - 1] - h[i];
            }
        }

        scan.close();
        System.out.println(min);
    }
}

Measured memory_bytes: 49844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    int x = min(a,b);
    int y = max(0, a+b-n);
    cout << x << " " << y << "\n";
}


Measured memory_bytes: 256
use proconio::marker::Chars;
use proconio::{fastout, input};
use std::collections::HashSet;
use std::iter::Iterator;

const INF: usize = 1 << 30;

#[fastout]
fn main() {
	input! {
		n: usize,
		m: usize,
		x: usize,
		ca: [(usize, [usize; m]); n], // CとAをタプルに入れる
	}

	let mut ans = INF;

	// bit全探索
	for bit in 0..(1 << n) {
		let mut cost = 0;
		let mut skill = vec![0_usize; m]; // スキルの合計値を入れる
		for i in 0..n {
			if bit >> i & 1 == 1 {
				// ------------------
				// ビットロジックが用意した任意のインデックスに対する値を合計していく
				// ------------------
				// コストを加算する
				cost += ca[i].0;
				for j in 0..m {
					// 理解度を加算して箱に入れる
					skill[j] += ca[i].1[j];
				}
			}
		}
		// 値が入れ終わったら、各skillの合計値の全てがが目標の満足値を超えているか？
		// そして、超えてていた場合、今回のコストが、暫定の最小コストよりも小さければ最小コストとする
		if skill.iter().fold(true, |ans, &s| ans && s >= x) {
			ans = std::cmp::min(cost, ans);
		}
	}

	if ans >= INF {
		println!("-1");
	} else {
		println!("{}", ans);
	}
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  string a,b,c; cin>>a>>b>>c;
  if (a.back()==b[0]&&b.back()==c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a,b,c;
 
int main(){
	cin >> a >> b >> c;
	
	if(c >= a && c <= a+b) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b;cin>>a>>b;
  if(a<=0&&b>=0)cout<<"Zero"<<endl;
  else if(b<0&&(b-a)%2==0)cout<<"Negative"<<endl;
  else cout<<"Positive"<<endl;
}

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

typedef long long LL;

const int MaxN=1e5+5;

int N,M;
LL K;
int X[MaxN],A[MaxN],D[MaxN];
int Base[MaxN],Ans[MaxN],Tmp[MaxN];

void Mul(int *a,int *b){
	int i;
	for(i=1;i<N;i++)
		Tmp[i]=b[a[i]];
	memmove(a,Tmp,sizeof(a));
}

int main(){
	int i,j;
	LL now;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		scanf("%d",&X[i]);
		Base[i]=Ans[i]=Tmp[i]=i;
	}
	for(i=1;i<N;i++)
		D[i]=X[i+1]-X[i];
	scanf("%d%lld",&M,&K);
	for(i=1;i<=M;i++)
		scanf("%d",&A[i]);
	for(i=1;i<=M;i++)
		swap(Tmp[A[i]-1],Tmp[A[i]]);
	for(i=1;i<N;i++)
		Base[Tmp[i]]=i;
	for(;K;K>>=1){
		if(K&1){
			for(j=1;j<N;j++)
				Tmp[j]=Base[Ans[j]];
			memmove(Ans,Tmp,sizeof(Ans));
		}
		for(j=1;j<N;j++)
			Tmp[j]=Base[Base[j]];
		memmove(Base,Tmp,sizeof(Base));
	}
	for(i=1;i<N;i++)
		Tmp[Ans[i]]=i;
	for(now=X[i=1];i<=N;i++){
		printf("%lld\n",now);
		now+=D[Tmp[i]];
	}
	return 0;
}

Measured memory_bytes: 3584
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;


int main(void) {
   ll N;
   cin>>N;
   vector<string> vs(N);
   ll ans = 0;
   rep(i,0,N) {
      cin>>vs[i];
   }
   ll tmp[3] = {0,0,0};
   for (auto s: vs){
      rep(j,0,s.size()-1) {
         if (s[j]=='A' && s[j+1]=='B') ans++;
      }
      bool f1 = (s[0]=='B');
      bool f2 = (s[s.size()-1]=='A');
      if (f1&&!f2) tmp[1]++;
      if (f2&&!f1) tmp[0]++;
      if (f1&&f2) tmp[2]++;
   }
   // cout<<ans<<endl;
   // ans += min(tmp[0],tmp[1]);
   // if (flag) ans--;
   if (tmp[2]==0) {
      ans += min(tmp[0],tmp[1]);
   } else {
      ans += tmp[2]-1;
      if (tmp[0]>0) {
         ans++;
         tmp[0]--;
      }
      if (tmp[1]>0) {
         ans++;
         tmp[1]--;
      }
      ans += min(tmp[0],tmp[1]);
   }
   // cout<<tmp[0]<<" "<<tmp[1]<<" "<<tmp[2]<<endl;
   cout<<ans<<endl;


   return 0;
}

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

int main(){
    int N,X,Y; cin >> N >> X >> Y;
    map<int,int> d;
    for(int i = 1;i < N;++i){
        for(int j = i+1;j <= N;++j){
            if(X<=i && j<=Y){
                int dd = min(j-i,Y-X+1-j+i);
                d[dd]++;
            }else if(i<X&&X<=j&&j<=Y){
                int dd =X-i+min(j-X,Y-X+1-j+X);
                d[dd]++;
            }else if(X<=i&&i<=Y&&Y<j){
                int dd =j-Y+min(Y-i,Y-X+1-Y+i);
                d[dd]++;
            }else if(i<X&&Y<j){
                int dd = X-i+j-Y+1;
                d[dd]++;
            }else{
                int dd = j-i;
                d[dd]++;
            }
        }
    }
    for(int i = 1;i<N;++i){
        cout << d[i] << endl;
    }
}

Measured memory_bytes: 384
#ifdef loc
    #include "../codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define sz(a) int(a.size())
const int N = 100005;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    cout<<(n-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a == b && b == c){
            System.out.println("1");
        }else if(a == b || a == c || b == c){
            System.out.println("2");
        }else{
            System.out.println("3");
        }
    }
}

Measured memory_bytes: 21332
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#define int long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int A = 0;
	int B = 0;
	for(int i = 0;i < N;i++) {
		B += vec.at(i);
	}
	int count = 1e18;
	for(int i = 0;i < N - 1;i++) {
		A += vec.at(i);
		B -= vec.at(i);
		count = min(count,abs(A - B));
	}
	cout << count << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


vector<pair<ll,ll>> prime(ll n){
	vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;++p){
    	if(n%p!=0) continue;
    	int num=0;
    	while(n%p==0){ ++num; n/=p;}
    	res.push_back(make_pair(p,num));
    }
    if(n!=1) res.push_back(make_pair(n,1));
    return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  ll a,b; cin >> a >> b;
  ll g = __gcd(a,b);
  auto p = prime(g);
  cout << p.size()+1 << endl;
  
}

Measured memory_bytes: 256
import heapq
from collections import defaultdict

N, K = map(int, input().split())

sushi = []
for _ in range(N):
    kind, value = map(int, input().split())
    sushi.append((value,kind))
sushi.sort()


choice = []
heapq.heapify(choice)

current_sum = 0
kinds = set()
count_nitems_bykind = defaultdict(int)

# pick K items with highest value
for _ in range(K):
    item = sushi.pop()
    count_nitems_bykind[item[1]] += 1
    kinds.add(item[1])
    current_sum += item[0]
    heapq.heappush(choice, item)

# initialize a dict to store max value that can be achieved by selecting x kinds of sushi
# key: x, value: max value
max_value = {len(kinds):current_sum}


def replace():
    '''
    Returns a next sushi that is new in kind and has maximum value
    '''

    while sushi:
        candidate = sushi.pop()
        if candidate[1] not in kinds:
            kinds.add(candidate[1])
            return candidate

    return None

while sushi and choice:
    # pick a sushi that has min value
    sushi_min = heapq.heappop(choice)

    # check if that sushi is a duplicate then if yes replace with a new sushi whose kind is new and value is max among such
    if count_nitems_bykind[sushi_min[1]] > 1:

        # pick a candidate to replace
        sushi_new = replace()
        if sushi_new is None:
            break

        count_nitems_bykind[sushi_min[1]] -= 1
        heapq.heappush(choice, sushi_new)


        # add a new result to dict
        current_sum = current_sum - sushi_min[0] + sushi_new[0]
        max_value[len(kinds)] = current_sum

    if len(kinds) == K: # already iterated enough to find answer
        break

ans = -1

for key in max_value:
    ans = max(ans, max_value[key] + key**2)

print(ans)

Measured memory_bytes: 24100
def CNT(A):
    tmp, Min = 0, 0
    for a in A:
        if a == '(': tmp += 1
        else: tmp -= 1
        Min = min(Min, tmp)
    return (-Min, tmp-Min)

N = int(input())
S = [input() for _ in range(N)]
T = [CNT(s) for s in S]

pls = []
mis = []
for l, r in T:
    if l <= r: pls.append((l, r))
    else: mis.append((l, r))

pls.sort(key=lambda a: a[0])
mis.sort(key=lambda a: a[1], reverse=True)
totl= pls + mis

levl = 0
for l, r in totl:
    levl -= l
    if levl < 0:
        print('No')
        exit()
    levl += r

print('Yes' if levl==0 else 'No')

Measured memory_bytes: 171008
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N;
		cin >> N;

		int x = (N+999) / 1000 * 1000;
		cout << x-N << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3632
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    
    count=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k==m:
                    count+=1
                    
    print(count)


Measured memory_bytes: 5596
#include<iostream>
using namespace std;
void printHelloWorld()
{
cout<<"Hello World";
}
void sum(int a,int b)
{
cout<<a+b;
}
int main()
{
int n,a,b;
cin>>n;
if(n==1)
printHelloWorld();
else if(n==2)
{
cin>>a;
cin>>b;
sum(a,b);
}
return 0;
}

Measured memory_bytes: 256