akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

void push(vector<pair<char, long long int>>&ans, pair<char , long long int>c) {
	if (ans.empty() || ans.back().first!= c.first) {
		ans.push_back(c);
	}
	else ans.back().second += c.second;
}

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

	vector<pair<char, long long int>>v;
	vector<pair<char, long long int>>w;
	vector<pair<char, long long int>>u;
	char c;
	while (cin >> c, c != '$') {
		cin >> N;
		v.push_back({ c,N });
	}
	while (cin >> c, c != '$') {
		cin >> N;
		w.push_back({ c,N });
	}
	while (cin >> c, c != '$') {
		cin >> N;
		u.push_back({ c,N });
	}
	vector<pair<char, long long int>>ans;
	if (w.size() == 1) {
		bool can = true;
		for (auto i : v) {
			if (can&&i.first == w.front().first&&i.second >= w.front().second) {
				can = false;
				for (auto j : u)push(ans, j);
				if (i.second - w.front().second) {
					push(ans, { i.first,i.second - w.front().second });
				}
			}
			else {
				push(ans, i);
			}
		}
	}
	else{
		bool can = true;
		for (int i = 0; i < v.size(); i++) {
			if (i + w.size() > v.size()) {
				push(ans, v[i]);
			}
			else if (v[i].first != w[0].first) {
				push(ans, v[i]);
			}
			else if (v[i].second < w[0].second) {
				push(ans, v[i]);
			}
			else if(can){
				bool flag = true;
				for (int j = 1; j + 1 < w.size(); j++) {
					if (v[i + j] != w[j])flag = false;
				}
				if (v[i + w.size() - 1].first != w.back().first)flag = false;
				else if (v[i + w.size() - 1].second < w.back().second)flag = false;
				if (!flag) {
					push(ans, v[i]);
				}
				else {
					if (v[i].second > w.front().second) {
						push(ans, { v[i].first, v[i].second - w.front().second });
					}
					for (auto j : u) {
						push(ans, j);
					}
					i += w.size();
					i--;
					v[i].second -= w.back().second;
					if (v[i].second)i--;
					can = false;
				}
			}
			else {
				push(ans, v[i]);
			}
		}
	}
	//cout << ans.size() << endl;
	for (auto i : ans) {
		cout << i.first << " " << i.second << " ";
	}
	cout << "$\n";
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> M;
vector<int> dp;
//dp[mask] -> quantos pareamentos eu posso fazer com aquela mask dali pra frente
int mod = 1e9+7;
int biggestMask;
int solve(int i, int mask){
    if(i == n){
        //cout << n << "????????????" << endl;
        if(mask == biggestMask)return 1;
        return 0;
        //cout << "whatthefuckinghell" << endl;
    }
    //cout << "oooooooooof" << endl;
    if(dp[mask] != -1) return dp[mask];
    int ret = 0;
    bool check = true;
    for(int j = 0 ; j < n ; j++){
       // cout << "oof" << endl;
        if(M[i][j] && !(mask & (1 << j))){
            //cout << mask << endl;
            check = false;
            mask = mask | (1<<j);
            ret += solve(i+1,mask);
            ret %= mod;
            mask = mask - (1<<j);
        } 
    }
    if(check) return 0;
    dp[mask] = ret;
    return ret;
}

int main(){
    cin >> n;
    M.resize(n);
    biggestMask = (1<<n) - 1;
    dp.resize((1<<n),-1);
    for(int i = 0 ; i < n ; i++){
        M[i].resize(n);
        for(int j = 0 ; j < n ; j++){
            cin >> M[i][j];
        }
    }
    cout << solve(0,0);
    return 0;
}

Measured memory_bytes: 8448
from math import factorial
from collections import deque
mod=10**9+7
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]
b=[int(raw_input()) for _ in xrange(n)]
d={}
a.sort()
b.sort()
ab=sorted(a+b)
for i in xrange(n):
    d[a[i]]="a"
    d[b[i]]="b"

stack=deque()
ans=1
for i in xrange(2*n):
    if len(stack)==0:
        stack.append(d[ab[i]])
        continue
    if d[ab[i]]=="a":
        if stack[-1]=="a":
            stack.append("a")
        else:
            ans=ans*len(stack)%mod
            stack.popleft()
    if d[ab[i]]=="b":
        if stack[-1]=="b":
            stack.append("b")
        else:
            ans=ans*len(stack)%mod
            stack.popleft()
print ans

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

int main(){
    int n;
    cin >> n;
    vector<int> a(n-1);
    vector<int> ans(n, 0);
    REP(i, n-1) {
        cin >> a[i];
        a[i]--;
        ans[a[i]]++;
    }

    REP(i, n) {
        cout << ans[i] << endl;
    }



    return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int N, x, l, count, limit;
  cin >> N;
  vector<pair<int, int>> vp(N);
  for(int i = 0; i < N; i++){
    cin >> x >> l;
    vp.at(i).first = x+l;
    vp.at(i).second = x-l;
  }
  sort(vp.begin(), vp.end());
  
  count=0;
  limit = vp.at(0).first;
  for(int i = 1; i < N; i++){
    if(vp.at(i).second < limit){
      count++;
    }else{
      limit = vp.at(i).first;
    }
  }
  cout << N-count << endl;
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first<<"\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<int> topologicalSort(vector<vector<int>>& path){
    int n = (int)path.size();
    vector<int> res;
    vector<int> entry(n,0);
    queue<int> q;
    for(int i=0;i<n;++i){
        for(int j=0;j<path[i].size();++j){
            entry[path[i][j]]++;
        }
    }
    for(int i=0;i<n;++i){
        if(!entry[i]){
            q.push(i);
        }
    }
    while(!q.empty()){
        int p = q.front();
        q.pop();
        res.push_back(p);
        for(int i=0;i<path[p].size();++i){
            if(--entry[path[p][i]]==0){
                q.push(path[p][i]);
            }
        }
    }
    return res;
}


int main(){
    IOS;
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m);
    vector<vector<int>> path(n);
    REP(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        path[x[i]].push_back(y[i]);
    }
    vector<int> ts = topologicalSort(path);
    vector<int> dp(n,0);
    REP(i,ts.size()){
        int from = ts[i];
        REP(j,path[from].size()){
            chmax(dp[path[from][j]],dp[from]+1);
        }
    }
    int res = 0;
    REP(i,n){
        chmax(res,dp[i]);
    }
    put(res);
    return 0;
}



Measured memory_bytes: 7548
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  sort(ALL(a));
  int ans = 0;
  REP(i,n-1){
    ans += a[i+1] - a[i];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;


int main(){
  string s;
  int k;
  cin >> s >> k;

  int n=s.length();
  vector<string> t(n*k);
 
    for(int i=0;i<n;i++){
      for(int j=1;j<=k&&i+j-1<n;j++){
     t.push_back(s.substr(i,j));
      }
    }
  
  sort(t.begin(),t.end());
  t.erase(unique(t.begin(),t.end()),t.end());
  
  cout << t[k] << endl;
}

Measured memory_bytes: 1852
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

struct T {int v, w;};

int main() {
	for (int w, n, i = 1; (w = in()) && (n = in()); i++) {
		out("Case ", i, ":\n");
		vector<T> ts(n);
		vector<vector<T>> m(n + 1, vector<T>(w + 1, {0, 0}));
		for (auto &t: ts) {
			int v = in();
			t = {v, in()};
		}
		for (int i = n - 1; i >= 0; i--)
			for (int j = 0; j <= w; j++)
				if (j < ts[i].w)
					m[i][j] = m[i + 1][j];
				else {
					T a = m[i + 1][j], b = m[i + 1][j - ts[i].w];
					b = {b.v + ts[i].v, b.w + ts[i].w};
					m[i][j] = (a.v >= b.v) ? a : b;
				}
		T r = m[0][w];
		out(r.v, '\n', r.w, '\n');
	}
}



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

typedef long long ll;
typedef pair<int, int> pii;

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

	double r;
	cin >> r;

	cout.precision(10);
	cout << fixed << 2 * acos(-1) * r;

	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> div(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n)
				res.push_back(n / i);
		}
	}
	return res;
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 1;
	for (int j = 0; j < 2; j++) {
		vector<ll> p = div(a[j]);
		for (auto v : p) {
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] % v != 0) {
					cnt++;
				}
			}
			if (cnt <= 1 && ans < v) {
				ans = v;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <stdio.h>
#include <string>
#include <map>

using namespace std;

int main()
{
    map<int, int> mp;
    int N,tmp;
    cin>>N;
    for(int i=0;i<N;i++){
      cin>>tmp;
      mp[tmp]++;
    }
    int ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 2e5 + 7;
int n;
__int128 x, p[N], s[N], d[N], ans = 1e36;

int main() {
	rd(n), rd(x), rda(p, n);
	for (int i = 1; i <= n; i++) s[i] = s[i-1] + p[i];
	d[1] = d[2] = 5;
	for (int i = 3; i <= n; i++) d[i] = d[i-1] + 2;
	for (int k = 1; k <= n; k++) {
		__int128 now = (k + n) * x;
		for (int i = n, t = 1; i > 0; i -= k, t++)
			now += d[t] * (s[i] - (i - k > 0 ? s[i-k] : 0));
		ans = min(ans, now);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 14776
#include <stdio.h>
int main(void) {
    long h, n, i, sum;
    int a[100001];
    scanf("%ld %ld", &h, &n);
    sum=0;
    for (i=0; i<n; i++) {
        scanf("%d", &a[i]);
        sum+=a[i];
    }
    if (sum >= h) {
        printf("Yes");
        return 0;
    } else {
        printf("No");
        return 0;
    }
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            int count = 0;
            int i, j, k;
            for(i = 1; i <= n; i++){
                for(j = 1; j < i; j++){
                    for(k = 1; k < j; k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}


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

int main() {
  int x;
  cin >> x;

  if (x >= 400 && x < 600) cout << 8;
  if (x >= 600 && x < 800) cout << 7;
  if (x >= 800 && x < 1000) cout << 6;
  if (x >= 1000 && x < 1200) cout << 5;
  if (x >= 1200 && x < 1400) cout << 4;
  if (x >= 1400 && x < 1600) cout << 3;
  if (x >= 1600 && x < 1800) cout << 2;
  if (x >= 1800 && x < 2000) cout << 1;

  return 0;
}


Measured memory_bytes: 3620
n = int(input())
plan = [tuple(map(int, input().split())) for _ in range(n)]
plan.insert(0, (0, 0, 0))
for i in range(1, n + 1):
    time_limit = plan[i][0] - plan[i - 1][0]
    distance = abs(plan[i][1] - plan[i - 1][1]) + \
        abs(plan[i][2] - plan[i - 1][2])
    if time_limit < distance or (time_limit % 2 != distance % 2):
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 17324
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt();
			System.out.println((a > b) ? a + Math.max(a - 1, b) : b + Math.max(a, b - 1));
		}
	}
}


Measured memory_bytes: 35456
package main

import "fmt"

func main() {
	var ttl int
	var n int
	fmt.Scan(&n)
  for i := n; i > 0; i-- {
		var st, ed int
		fmt.Scan(&st, &ed)

		ttl += ed - st + 1
	}

	fmt.Println(ttl)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int div = 1000000007;
			long ans = pow(2, n, div);
			int A = nCk(n, a, div);
			int B = nCk(n, b, div);
			ans -= A;
			ans -= B;
			ans -= 1;
			if (ans < 0) {
				while (true) {
					ans += div;
					if (ans >= 0) {
						break;
					}
				}
				System.out.print(ans);
			} else {
				System.out.print(ans);
			}
		}
	}

	public static int nCk(int n, int k, int M) {
		long ret = 1;
		int min = Math.min(k, n - k);
		for (int i = 1; i <= min; i++) {
			ret = (ret * pow(i, M - 2, M)) % M;
		}
		for (int i = n - min + 1; i <= n; i++) {
			ret = (ret * i) % M;
		}
		return (int) ret;
	}

	//return a^b mod M O(logB)
	public static long pow(long a, long b, int M) {
		long ret = 1;
		long tmp = a;
		while (b > 0) {
			if ((b & 1) == 1)
				ret = (ret * tmp) % M;
			tmp = (tmp * tmp) % M;
			b = b >> 1;
		}
		return ret;
	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

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

    int n = sc.nextInt();

    long max = sc.nextInt();
    long sum = 0;
    for (int i = 1; i < n; i++) {
      long p = sc.nextInt();
      long step;
      if (max > p) {
        step = max - p;
        sum += step;
      } else {
        max = p;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 58172
#include <bits/stdc++.h>
#define NMAX 300001
using namespace std;
long long fr[NMAX],v[NMAX];
int main()
{
    long long n,i,nr=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>v[i];
        fr[v[i]]++;
    }
    for(i=0;i<NMAX;i++){
        nr+=fr[i]*(fr[i]-1)/2ll;
    }
    for(i=0;i<n;i++){
        cout<<nr-fr[v[i]]+1<<'\n';
    }
    return 0;
}


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

int main() {
  int N, a, b;
  cin >> N >> a >> b;
  
  int ans = 0;
  for(int i = 1; i <= N; i++){
    int c = 0;
    int t = i;
    for(int j = 0; j < 5; j++){
      c += t%10;
      t /= 10;
    }
    if( a <= c && c <= b){
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> P;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
vector<P> directions = {
    P(0, 1),
    P(1, 0),
    P(0, -1),
    P(-1, 0),
};

int main(void) {
  int ROW, COLUMN;
  cin >> ROW >> COLUMN;
  string grid[51];
  int wallCount = 0;
  int d[51][51];

  rep(i, ROW) {
    cin >> grid[i];
    rep(j, COLUMN) {
      if (grid[i][j] == '#') wallCount++;
      d[i][j] = INF;
    }
  }
  d[0][0] = 0;
  queue<P> keep;
  keep.push(P(0, 0));
  while (keep.size() > 0) {
    P cur = keep.front();
    keep.pop();
    int row = cur.first;
    int column = cur.second;

    if (row == ROW - 1 && column == COLUMN - 1) break;

    for (P direction : directions) {
      int nR = row + direction.first;
      int nC = column + direction.second;

      if (nR < 0 || nR >= ROW || nC < 0 || nC >= COLUMN ||
          grid[nR][nC] == '#' || d[nR][nC] != INF)
        continue;

      d[nR][nC] = d[row][column] + 1;
      keep.push(P(nR, nC));
    }
  }

  if (d[ROW - 1][COLUMN - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }

  cout << (((ROW * COLUMN) - d[ROW - 1][COLUMN - 1]) - wallCount - 1) << endl;

  return 0;
}

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

const int N = 1e6L + 11;
int p[N];
int sum[N];

int main() {
	iota(p, p + N, 0);
	for(int i = 2; i < N; i ++) if(p[i] == i)
		for(int j = i; j < N; j += i) p[j] = i;
	for(int i = 2; i < N; i ++)
		sum[i] = sum[i - 1] + (p[i] == i);
	ios :: sync_with_stdio(false);
	int n;
	while(cin >> n)
		cout << sum[n] << '\n';
	return 0;
}

Measured memory_bytes: 10888
//Author: Kudo_kun
//AtCoder_132
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "-O3"
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
typedef int64_t ll;
typedef long double ld;

const int N = (1e5 + 5);
const long MOD = (1e9 + 9);
const long INF = (1e18 + 18);
string s;
map<char, int> mp;


int main()
{
	FastIO;
	cin >> s;
	for(auto it : s)
		mp[it]++;
	if(mp.size() != 2)
	{
		cout << "No\n";
		return 0;
	}
	
	cout << "Yes\n";
	return 0;
}

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

using namespace std;

const int INF = 0x3f3f3f3f;
int arr[105];

int main()
{
    int n, now, p, ans;
    while(cin >> n) {
        ans = INF;
        for(int i = 0; i < n; i++)
            cin >> arr[i];
        for(int i = 0; i < 100; i++) {
            now = 0;
            for(int j = 0; j < n; j++) {
                now += (i-arr[j])*(i-arr[j]);
            }
            ans = min(ans, now);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int card[4][13];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            card[i][j] = 0;
        }
    }
    int n;
    cin >> n;
    string suite;
    int number;
    for (int i = 0; i < n; i++) {
        cin >> suite >> number;
        if (suite == "S") {
            card[0][number - 1] = 1;
        }
        if (suite == "H") {
            card[1][number - 1] = 1;
        }
        if (suite == "C") {
            card[2][number - 1] = 1;
        }
        if (suite == "D") {
            card[3][number - 1] = 1;
        }
    }
    for (int i = 0; i < 4; i++) {
        if (i == 0) suite = "S";
        if (i == 1) suite = "H";
        if (i == 2) suite = "C";
        if (i == 3) suite = "D";
        for (int j = 0; j < 13; j++) {
            if (card[i][j] == 0) {
                cout << suite << " " << j + 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <string>

typedef long long ll;

using namespace std;

int main() {
    int A;
    double ans = 0.0, ans2;
    cin >> A;

    int num[A];

    for (int i = 0; i < A; i++) {
        cin >> num[i];
    }

    for (int i = 0; i < A; i++) {
        ans +=  1.0 / num[i];
    }

    ans2 = 1.0 / ans;

    cout << ans2 << endl;


    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng (chrono::steady_clock::now().time_since_epoch().count() );

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200001; //check the limits, dummy


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

    ll H, W;
    cin >> H >> W;
    ll h, w;
    cin >> h >> w;

    H -= h;
    W -= w;

    cout << H*W << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using lint = long long;
using vi = vector<int>;

int main() {
	int n, r;
	cin >> n >> r;
	if (n < 10) {
		r += 100 * (10 - n);
	}
	cou(r);
}

Measured memory_bytes: 256
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

type Pairs [][]int
func (P Pairs) Len() int { return len(P) }
func (P Pairs) Less(i, j int) bool { return P[i][1] < P[j][1] }
func (P Pairs) Swap(i, j int) { P[i], P[j] = P[j], P[i] }

func Solve() {
  var N int
  NextInt(&N)
  P := make([][][]int, 4)
  for i := range P { P[i] = make([][]int, 0) }
  pm := 0
  var cnt, min int
  var S string
  for i := 0; i < N; i++ {
    cnt, min = 0, 0
    S = NextLine()
    for _, s := range S {
      if s == '(' {
        cnt++
      } else {
        cnt--
        min = MinInt(cnt, min)
      }
    }
    pm += cnt
    if 0 <= min {
      P[0] = append(P[0], []int{cnt, min})
    } else if 0 < cnt {
      P[1] = append(P[1], []int{cnt, min})
    } else if min < cnt {
      P[2] = append(P[2], []int{cnt, min})
    } else {
      P[3] = append(P[3], []int{cnt, min})
    }
  }
  sort.Sort(sort.Reverse(Pairs(P[1])))
  sort.Sort(Pairs(P[2]))
  cnt, min = 0, 0
  able := pm == 0
  for i := range P {
    for _, p := range P[i] {
      min = cnt + p[1]
      cnt += p[0]
      able = able && min >= 0
    }
  }
  ans := "No"
  if able { ans = "Yes" }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a < b){
        int tmp=a;
        a = b;
        b = tmp;
    }
    int c;
    while((a%b)!=0){
        c = a;
        a = b;
        b = c%b;
    }
    cout << b << endl;
    return 0;
}


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

vector<int> s, t;
void solve(){
    int x;
    cin >> x;

    int ans = 1e18;
    int sitr = lower_bound(s.begin(),s.end(),x) - s.begin();
    int titr = lower_bound(t.begin(),t.end(),x) - t.begin();

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            ans = min(ans, abs(x - s[sitr - i]) + abs(t[titr - j] - s[sitr - i]));
            ans = min(ans, abs(x - t[titr - j]) + abs(t[titr - j] - s[sitr - i]));
        }
    }
    cout << ans << endl;
}

signed main(){
    int a,b,q;
    cin >> a >> b >> q;

    s.resize(a);
    t.resize(b);
    for (int i = 0; i < a; i++) cin >> s[i];
    for (int i = 0; i < b; i++) cin >> t[i];

    s.push_back(-1e18);
    t.push_back(-1e18);
    s.push_back(1e18);
    t.push_back(1e18);
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());

    while(q--){
        solve();
    }
}

Measured memory_bytes: 2912
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll h, w;
string s[600], a[600], b[600];

int main() {
	cin >> h >> w;
	REP(i, h)cin >> s[i];
	REP(i, h) {
		REP(j, w) {
			a[i].push_back('.');
			b[i].push_back('.');
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (j == 0 or (j < w - 1 and i % 2 == 0)) {
				a[i][j] = '#';
			}
			else if(s[i][j] == '#') a[i][j] = '#';
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (j == w - 1 or (j > 0 and i % 2 == 1)) {
				b[i][j] = '#';
			}
			else if (s[i][j] == '#') b[i][j] = '#';
		}
	}
	REP(i, h)cout << a[i] << endl;
	cout << endl;
	REP(i, h)cout << b[i] << endl;
}


Measured memory_bytes: 1536
program name
    implicit none
    integer(4):: n,q
    character(:),allocatable:: s
    integer(4),allocatable:: acnum(:), lr(:,:)
    integer(4):: i,j

    read*, n,q
    allocate(character(n):: s)
    read*, s
    allocate(acnum(n), lr(2,q))

    do i=1,q
        read*, lr(:,i)
    end do

    acnum(1)=0

    do i=2,n
        if (s(i-1:i) == 'AC')then
            acnum(i) = acnum(i-1)+1
        else
            acnum(i) = acnum(i-1)
        end if
    end do

    do i=1,q
        print*, acnum(lr(2,i)) - acnum(lr(1,i))
    end do

end program name

Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    if(n==2){
        int a,b; cin >> a >> b;
        if(a!=b) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }
    map<int,int> mp1;
    map<int,int> mp2;
    rep(i,n){
        int v; cin >> v;
        if(i%2==0) mp1[v]++;
        else mp2[v]++;
    }
    P ma1={0,0},ma2={0,0};
    for(auto itr=mp1.begin();itr!=mp1.end();++itr){
        int x=itr->se,y=itr->fi;
        if(ma2.fi<=x) ma2={x,y};
        if(ma1.fi<ma2.fi) swap(ma1,ma2);
    }
    P ma3={0,0},ma4={0,0};
    for(auto itr=mp2.begin();itr!=mp2.end();++itr){
        int x=itr->se,y=itr->fi;
        if(ma4.fi<=x) ma4={x,y};
        if(ma3.fi<ma4.fi) swap(ma3,ma4);
    }
    if(ma1.se!=ma3.se){
        cout << n-ma1.fi-ma3.fi << endl;
    }else{
        cout << min(n-ma1.fi-ma4.fi,n-ma2.fi-ma3.fi) << endl;
    }
    
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include  <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long lint;
#define SZ(x) ((int)(x).size())

const int cake=4,donut=7;
bool flg=false;

int main()
{
	int n;
	int sum = 0;
	bool end_flg = false;
	bool ans = false;
	cin >> n;

	for(int i=0;i<=101&&end_flg==false;i++) {
		for (int j = 0; j <= 101 && end_flg == false; j++){
			if (n == cake * i + donut * j) {
				end_flg = true;
				ans = true;
			}
		}
	}
	if (end_flg) cout << "Yes" << endl;
	else cout << "No" << endl;
	

	return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;
    scanf("%d",&N);
    int d[10][10]={};
    for(int i=1;i<=N;i++){
        char s[24];
        sprintf(s,"%d",i);
        int x=s[0]-'0';
        int y=-1;
        for(int j=0;s[j];j++){
            y=s[j]-'0';
        }
        d[x][y]++;
    }
    LL an=0;
    for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)an+=d[i][j]*d[j][i];
    W(an);
    return 0;
}


Measured memory_bytes: 384
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  if(one[0] + one[1] + one[2] >= 22){
  	myout("bust");
  }else{
  	myout("win");
  }
}

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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, string> P;

const int MX = 2005;
vector<string> s;
bool dp[3][3][MX];

int main() {
    s.resize(3);

    rep(i, 3) {
        cin >> s[i];
    }

    sort(s.begin(), s.end());
    int ans = MX * 3;
    do {
        // 前処理
        rep(i, 3)rep(j, 3)rep(k, MX) {
            bool ok = true;
            for (int ni = k; ni < s[i].size(); ni++) {
                int nj = ni - k;
                if (nj >= s[j].size()) break;
                if (s[i][ni] == '?' || s[j][nj] == '?') continue;
                if (s[i][ni] != s[j][nj]) ok = false;;
            }
            dp[i][j][k] = ok;
        }

        auto f = [&](int i, int j, int k) {
            if (k >= s[i].size()) return true;
            return dp[i][j][k];
        };
        rep(x, MX)rep(y, MX) {
            if (!f(0, 1, x)) continue; 
            if (!f(1, 2, y)) continue; 
            if (!f(0, 2, x + y)) continue; 

            int now = 0;
            now = max<int>(now, s[0].size());
            now = max<int>(now, x + s[1].size());
            now = max<int>(now, x + y + s[2].size());

            ans = min(ans, now);
        }
    } while (next_permutation(s.begin(), s.end()));

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
   // output
   int i;
   int k;
   cin >> i >> k;
   while (i != 0 || k !=0) {
     if (i > k) {
       cout << k << " " << i << endl;
     }else {
       cout << i << " " << k << endl;
     }
     cin >> i >> k;
   }    
}


Measured memory_bytes: 3088
def main():
  import numpy as np
  import itertools
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import floyd_warshall
  import sys
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines

  N, M, R= map(int, readline().split())
  r = list(map(int,input().split()))
  lines = readlines()
  edge = np.array([line.split() for line in lines], dtype = np.int64).T
  graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
  distance_mat = floyd_warshall(graph,directed = False)
  #print(distance_mat)
  ans = float("inf")
  for town in itertools.permutations(r,R):
    #print(town)
    tmp = 0
    for i in range(R-1):
      tmp += distance_mat[town[i]-1][town[i+1]-1]
    ans = min(ans,tmp)
  print(int(ans))
main()

Measured memory_bytes: 23732
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int K = sc.nextInt();
			final int X = sc.nextInt();
			
			boolean first = true;
			for(int i = -1000000; i <= 1000000; i++) {
				if(X - K < i && i < X + K) {
					System.out.print((first ? "" : " ") + i);
					first = false;
				}
			}
			System.out.println();
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main()
{
	int N;
	cin >> N;
	int A[3];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[j];
		}
		sort(A, A + 3);
		if ((A[0] * A[0] + A[1] * A[1]) == (A[2] * A[2])) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main() {
    int N, K;
    cin >> N >> K;
    int h[N];
    rep(i, N) cin >> h[i];
    int dp[N+K+100];
    rep(i, N+K+100) dp[i] = INF;
    dp[0] = 0;
    rep(i, N){
        for(int j = 1; j <= K; j++){
            if (i+j < N) chmin(dp[i+j], dp[i]+abs(h[i]-h[i+j])); 
        }
    }
    cout << dp[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int[] abc = new int[26];
		String input = "";

		while (scanner.hasNext()) {

			input = input().toLowerCase();

			for (int i = 0; i < input.length(); i++) {

				char charNumber = input.charAt(i);

				if ('a' <= charNumber && charNumber <= 'z') {

					abc[charNumber - 'a']++;

				}
			}
		}

			for (int j = 0; j < 26; j++) {

			System.out.println((char)('a' + j) + " : " + abc[j]);

		}

		close();

	}

	public static String input() {

		return scanner.nextLine();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26204
## coding: UTF-8
#memo:重なっている位置に爆弾があるかないかで、1こ増減することが考えられる
#import numpy as np

H, W, M = map(int,input().split())

tate = [0] * H
yoko = [0] * W


bomb = set()
for i in range(M):
    hi, wi = map(int,input().split())
    tate[hi-1] += 1
    yoko[wi-1] += 1
    bomb.add((hi,wi))
    

#print(tate)
#print(yoko)
#print(bomb)
'''
tate_max = max(tate)
yoko_max = max(yoko)
index_tate = [i for i, v in enumerate(tate) if v == tate_max]
index_yoko = [i for i, v in enumerate(yoko) if v == yoko_max]
'''
tate_max = 0
index_tate = []
for i, v in enumerate(tate):
    if(tate_max < v):
        tate_max = v
        index_tate = [i]
    elif(tate_max == v):
        index_tate.append(i)
#print(tate_max, index_tate)

yoko_max = 0
index_yoko = []
for i, v in enumerate(yoko):
    if(yoko_max < v):
        yoko_max = v
        index_yoko = [i]
    elif(yoko_max == v):
        index_yoko.append(i)
#print(yoko_max, index_yoko)


#print(index_tate, index_yoko)

dammy = True
#1子でも「そこにない」ものがあれば、そのまま加算、そうでなければ、1こ引く
there_is = True
flg = False
for i in index_tate:
    for j in index_yoko:
        #print(i+1, j+1)
        if((i+1, j+1) in bomb):
            dammy = True
        else:
            there_is = False
            flg = True
            break
    if flg:
        break

if(there_is):
    print(tate_max + yoko_max - 1)
else:
    print(tate_max + yoko_max)


        




'''
#tate_max = [i for i, v in enumerate(tate) if v == max(tate)]
np_list_tate = np.array(tate)
np_list_yoko = np.array(yoko)
tate_max = np_list_tate.argmax()
yoko_max = np_list_yoko.argmax()
print(tate_max, yoko_max)
'''

Measured memory_bytes: 167380