akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/

struct zahyou{
	int xma,xmi,yma,ymi,num;
}z;
 
signed main(){
	IOS();
	int H,W;
	vector<int>ans;
	int N;
	cin>>N;
	while(N--){
		cin>>H>>W;
		string s[H];
		rep(i,0,H)cin>>s[i];
		map<char,zahyou>mp;
		vector<char>c;
		rep(i,0,H){
			rep(j,0,W){
				if(s[i][j]=='.')continue;
				if(mp.count(s[i][j])){
					chmin(mp[s[i][j]].xmi,j);
					chmax(mp[s[i][j]].xma,j);
					chmin(mp[s[i][j]].ymi,i);
					chmax(mp[s[i][j]].yma,i);
				}else{
					mp[s[i][j]].xma=mp[s[i][j]].xmi=j;
					mp[s[i][j]].yma=mp[s[i][j]].ymi=i;
					c.push_back(s[i][j]);
				}
			}
		}
		vector<int>rank(mp.size());
		map<char,int>inv;
		int cnt=0;
		for(auto e:c){
			inv[e]=cnt;
			cnt++;
		}
		iota(all(rank),0);
		int end = 0;
		rep(i,0,c.size()){
			//cout<<mp[c[i]].xmi<<" "<<mp[c[i]].xma<<endl;
		}
		
		do{
			int ok=1;
			rep(i,0,rank.size()){
				int sx = mp[c[i]].xmi;
				int gx = mp[c[i]].xma;
				int sy = mp[c[i]].ymi;
				int gy = mp[c[i]].yma;
				int flg = 1;
				rep(j,sy,gy+1){
					rep(k,sx,gx+1){
						if(s[j][k]=='.')flg=0;
						else if(rank[inv[s[j][k]]]>=rank[inv[c[i]]])continue;
						else flg=0;
						if(flg==0)break;
					}
					if(flg==0)break;
				}
				if(flg==0)ok=0;
			}
			if(ok){
				ans.push_back(1);
				end = 1;
				break;
			}
			if(end)break;
		}while(next_permutation(all(rank)));
		if(end==0)ans.push_back(0);
		
	}
	for(auto e:ans){
		if(e)cout<<"SAFE"<<endl;
		else cout<<"SUSPICIOUS"<<endl;
	}
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n;
	ll x;
	ll cnt = 0LL;
	ll ans = 0LL;
	cin >> n >> x;
	int at;
	V a(n);
	rep(i, n) { cin >> a[i]; }
	rep(i, n) {
		at = i;
		cnt += a[i];
		if (i >= 2) {
			cnt -= a[i - 2];
		}
		//	clog << cnt <<" " <<max(0LL,cnt-x)<<endl;
		ans += max(0LL, cnt - x);
		while (cnt > x) {
			if (a[at] >= cnt - x) {
				a[at] -= cnt - x;
				cnt = x;
			} else {
				cnt -= a[at];
				a[at] = 0;
			}
			at--;
		}
	}
	// repi(itr, a) { clog << (*itr) << " "; }
	clog << endl;
	cout << ans << endl;
}

Measured memory_bytes: 4052
#include<iostream>
using namespace std;
int main() {
	int K, S;
	cin >> K >> S;
	int count = 0;
	for (int i = 0; i <= K; ++i) {
		for (int j = 0; j <= K; ++j) {
			if (S - i - j <= K&&S-i-j>=0)
				count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 N, M, R;
  cin >> N >> M >> R;
  vector<i64> r(R);
  vector<vector<i64>> dist(N, vector<i64>(N, 1e18));
  for(int i = 0;i < R;i++) {
    dist[i][i] = 0;
    cin >> r[i];
    r[i]--;
  }
  for(int i = 0;i < M;i++) {
    i64 a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    dist[a][b] = dist[b][a] = c;
  }
  for(int k = 0;k < N;k++) for(int i = 0;i < N;i++) for(int j = 0;j < N;j++)
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  vector<vector<i64>> dp(N, vector<i64>(1 << R, 1e18));
  for(int i = 0;i < R;i++) dp[i][(1 << i)] = 0;
  for(int s = 1;s < (1 << R);s++) {
    for(int i = 0;i < R;i++) {
      if(!(s & (1 << i))) continue;
      for(int j = 0;j < R;j++) {
        if(s & (1 << j)) continue;
        int t = (s | (1 << j));
        dp[j][t] = min(dp[j][t], dp[i][s] + dist[r[i]][r[j]]);
      }
    }
  }
  i64 ans = dp[0][(1 << R) - 1];
  for(int i = 0;i < R;i++) ans = min(ans, dp[i][(1 << R) - 1]);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>

using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;

int main()
{
	ll h;
	cin>>h;
	ll i;
	for( i = 1;;i*=2){
		if(i > h) break;
	}i--;
	cout<<i<<endl;

	return 0;
	
}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, V, U = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]

V -= 1
U -= 1
graph = [[] for _ in range(N)]
for a, b in AB:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

# 深い方に逃げるべき
# 子どものうち一番深い場所の深さ
children_depths = [0] * N
parents = [None] * N

stack = [(U, None)]
vs = []
while stack:
    v, parent = stack.pop()
    parents[v] = parent
    vs.append(v)
    for u in graph[v]:
        if u == parent:
            continue
        stack.append((u, v))
vs.reverse()
for v in vs:
    if parents[v] is not None:
        children_depths[parents[v]] = max(children_depths[parents[v]], children_depths[v] + 1)

v = V
dist = 1
while parents[v] != U:
    v = parents[v]
    dist += 1

# 何回親側に上がるか
p_cnt = 0
v = V
ans = 0
while dist > 0:
    ans = max(ans, dist - 1 + children_depths[v] + p_cnt)
    v = parents[v]
    p_cnt += 1
    dist -= 2
print(ans)


Measured memory_bytes: 76380
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {

var inputs = chunk.toString().trim().split('\n').map(Number);
for (var i = 0; i < inputs .length; i++) {
        if (inputs [i] === 0) {
            break;
        }
        console.log('Case ' + (i + 1) + ': ' + inputs[i]);
}


});

Measured memory_bytes: 20680
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

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

        String S = sc.next();
        long K = sc.nextLong();
        int l = S.length();

        for(int i=0; i<l; i++){
            if(!S.substring(i,i+1).equals("1")){
                if(i<K){
                    System.out.println(S.substring(i, i+1));
                    break;
                }
            }
            if(i==l-1){
                System.out.println(1);
            }
        }
    } 
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    string S;
    cin >>S;
    int n=S.size();
    vi abc(3);
    rep(i,n) abc[S[i]-'a']++;
    sort(all(abc));
    if(abc[2]-abc[0]<2) cout << "YES"<<endl;
    else cout <<"NO"<<endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	private int[][] mass = new int[8][8];

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		String[] alp = {"A", "B", "C", "D", "E", "F", "G", "error"};
		while (scan.hasNext()) {
			String str = "error";
			for (int i = 0; i < 8; i++) {
				str = scan.nextLine();
				if (str.isEmpty()) break;
				for (int j = 0; j < 8; j++) {
					mass[i][j] = Integer.parseInt(str.substring(j, j + 1));
				}
			}
			if (str.isEmpty()) continue;
			System.out.println(alp[seek()]);
		}
	}
	
	private int seek() {
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				if (mass[i][j] == 1) {
					if (j + 1 < 8 && mass[i][j + 1] == 1) {
						if (i + 1 < 8) {
							if (mass[i + 1][j] == 1 && mass[i + 1][j + 1] == 1) {
								return 0;
							}else if (j + 2 < 8 && mass[i + 1][j + 1] == 1 && mass[i + 1][j + 2] == 1) {
								return 4;
							}else if (j - 1 > -1 && mass[i + 1][j - 1] == 1 && mass[i + 1][j] == 1) {
								return 6;
							}else if (j + 3 < 8 && mass[i][j + 2] == 1 && mass[i][j + 3] == 1) {
								return 2;
							}else {
								return 7;
							}
						}else {
							return 2;
						}
					}else {
						if (j + 1 < 8 && mass[i + 1][j + 1] == 1) {
							return 5;
						}else if (j - 1 > -1 && mass[i + 1][j - 1] == 1) {
							return 3;
						}else {
							return 1;
						}
					}
				}
			}
		}
		return 7;
	}
	
	private void debug() {
		System.out.println();
	}

}

Measured memory_bytes: 22028
#include<bits/stdc++.h>
using namespace std;
int h,w;
string s[2200];
int up[2200][2200];
int dn[2200][2200];
int le[2200][2200];
int ri[2200][2200];
inline bool invalid(int x,int y){
	if(x<0)
		return true;
	if(y<0)
		return true;
	if(x>=h)
		return true;
	if(y>=w)
		return true;
	if(s[x][y]=='#')
		return true;
	return false;
}
int main(){
	//freopen("output.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w;
	int res=0;
	for(int i=0;i<h;i++){
		cin>>s[i];
		for(int j=0;j<w;j++){
			if(j>0&&s[i][j-1]=='.')
				le[i][j]=le[i][j-1]+1;
			else
				le[i][j]=0;
			if(i>0&&s[i-1][j]=='.')
				up[i][j]=up[i-1][j]+1;
			else
				up[i][j]=0;
		}
	}
	for(int i=h-1;i>=0;i--){
		for(int j=w-1;j>=0;j--){
			if(j<w-1&&s[i][j+1]=='.')
				ri[i][j]=ri[i][j+1]+1;
			else
				ri[i][j]=0;
			if(i<h-1&&s[i+1][j]=='.')
				dn[i][j]=dn[i+1][j]+1;
			else
				dn[i][j]=0;
			if(s[i][j]=='.')
				res=max(res,dn[i][j]+up[i][j]+le[i][j]+ri[i][j]+1);
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 78464
N = int(input())

A = []

for i in range(N):
  a = int(input())
  A.append(a-1)
  
seen = set()

pos = 0
seen.add(0)
count = 0
while pos != 1:
  pos = A[pos]
  if pos in seen:
    count = -1
    break
  else:
    seen.add(pos)
  count += 1
  
print(count)

Measured memory_bytes: 18940
import math
a = input()
b = input().split(" ")
c = []
for i in b:
  c.append(i)
money = 1000
senet = 0
chk = 0
c.sort(reverse=True)
for i in range(int(a)):
  for j in range(int(a)):
    if j != int(a)-1:
      if b[j] >= b[j+1]:
        pass;
      else:
        chk = 1 
  if chk == 0:
    break;
  elif i == int(a)-1:
    money = money + (senet * int(b[i]))
  elif i == 0:
    if int(b[i]) < int(b[i+1]):
      senet += math.floor(money / int(b[i]))
      money = money-(math.floor(money / int(b[i]))*int(b[i]))
  elif int(b[i]) < int(b[i+1]):
      senet += math.floor(money / int(b[i]))
      money = money-(math.floor(money / int(b[i]))*int(b[i]))
  elif int(b[i]) > int(b[i+1]):
    money += senet * int(b[i])
    senet = 0 
  elif int(b[i]) == int(b[i+1]):
    pass;
print(money)

Measured memory_bytes: 9296
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    cout << n*800 - 200*(n/15) << endl;
}


Measured memory_bytes: 256
S = input()
s1 = int(S[:2])
s2 = int(S[2:])

if (s1 > 12):
    if (s2 > 12 or s2==0):
        print("NA")
    else:
        print("YYMM")
elif (s1 <= 12 and s1 > 0):
    if s2 > 12 or s2 == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")
elif s1 == 0:
    if s2 > 12 or s2 == 0:
        print("NA")
    else:
        print("YYMM")


Measured memory_bytes: 3060
import sys
from collections import deque
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
U = 10 ** 5
edge = [[] for _ in range(2 * U + 1)]
for _ in range(N):
    x, y = map(int, input().split())
    y += U
    edge[x].append(y)
    edge[y].append(x)

ans = 0
seen = [False] * (2 * U + 1)
for i in range(1, 2 * U + 1):
    if not edge[i] or seen[i]:
        continue
    seen[i] = True
    node = deque([i])
    x = 0
    y = 0
    while node:
        s = node.popleft()
        if s <= U:
            x += 1
        else:
            y += 1
        for t in edge[s]:
            if seen[t]:
                continue
            seen[t] = True
            node.append(t)
    ans += x * y

ans = ans - N
print(ans)

Measured memory_bytes: 30168
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
dp=[0]*(10**5+1)
bp=[0]*(10**5+1)
for i in primes(10**5):
  dp[i]=1
for i in range(1,10**5+1):
  bp[i]+=bp[i-1]
  if i%2==0:
    continue
  if dp[(i+1)//2]==1 and dp[i]==1:
    bp[i]+=1
Q=int(input())
for _ in range(Q):
  l,r=map(int,input().split())
  print(bp[r]-bp[l-1])

Measured memory_bytes: 12920
/**
 *    author:  Atrues
 *    created: 27.01.2019 23:50
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;

vector<int> out[maxn], in[maxn], topol;
bool visited[maxn];
int pos[maxn];

void dfs(int v){
	visited[v] = 1;
	for (auto u : out[v])
		if (!visited[u])
			dfs(u);
	pos[v] = topol.size();
	topol.push_back(v);
}

int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n + m - 1; i++){
		int v, u;
		cin >> v >> u;
		out[v].push_back(u);
		in[u].push_back(v);
	}
	for (int v = 1; v <= n; v++)
		if (!visited[v])
			dfs(v);
	for (int v = 1; v <= n; v++){
		int par = 0;
		for (auto u : in[v])
			if (par == 0 or pos[u] < pos[par])
				par = u;
		cout << par << '\n';
	}
}


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

int64_t solve();

int main()
{
	printf("%lld\n", solve());

	return 0;
}

int64_t solve()
{
	int N;
	int64_t K;
	scanf("%d%lld", &N, &K);
	std::vector<int64_t> A[2];
	A[0].resize(N);
	for (auto& e: A[0]) scanf("%lld", &e);
	A[1] = A[0];
	std::sort(A[0].begin(), A[0].end());
	std::sort(A[1].rbegin(), A[1].rend());

	constexpr int64_t max{1'000'000'000};
	constexpr int64_t shift{max * max + 5};
	int64_t ng{-shift}, ok{shift};
	while (ok - ng > 1)
	{
		int64_t mid{((ok + shift + ng + shift) / 2) - shift};
		int64_t sum{};
		for (int i{}; i < N; i++)
		{
			int neg{A[0][i] < 0};
			int le{-1}, greater{N};
			while (greater - le > 1)
			{
				int mid2{(le + greater) / 2};
				if (A[neg][mid2] * A[0][i] <= mid) le = mid2;
				else greater = mid2;
			}
			if (neg)
				sum += std::min(greater, std::max(N - 1 - i, 0));
			else
				sum += std::max(le - i, 0);
		}
		if (K <= sum) ok = mid;
		else ng = mid;
	}
	return ok;
}

Measured memory_bytes: 3328
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    ans = 1000-N%1000
    if ans ==1000:
        print(0)
    else:
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
vector<int> v[10];
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int n,ans=0;
	string s;
	cin>>n>>s;
	f(i,n){
		v[s[i]-'0'].push_back(i);
	}
	f(i,10){
		f(j,10){
			f(k,10){
				if(!v[i].size()||!v[j].size()||!v[k].size())continue;
				int z=v[i][0],z2=v[k][v[k].size()-1];
				if(lower_bound(all(v[j]),z2)-upper_bound(all(v[j]),z)>0){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 768
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())
X, Y = ints()

start = (0, 0)
end = (X, Y)
memo = {}
MOD = 10**9+7
N = 10**6+1
fact = [None]*N
fact[0] = 1
for i in range(1, N):
  fact[i] = fact[i-1]*i % MOD

def no():
  print(0)
  exit()

def inv(x):
  res = 1
  k = MOD-2
  y = x
  while k>0:
    if k%2==1:
      res = (res * y) % MOD
    y = (y * y) % MOD
    k //= 2
  return res

def C(n, k):
  a = fact[n]
  b = fact[k]
  c = fact[n-k]
  bc = (b*c) % MOD

  return (a * inv(bc)) % MOD

x = X+Y
y = -X+Y

if x%3>0:
  no()

xn = x//3
yn= (y+xn)//2
if yn<0 or yn>xn:
  no()
print(C(xn, yn))


Measured memory_bytes: 60380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Abc160B
    {
        public static void Main()
        {
            long x = long.Parse(Console.ReadLine());
            long happiness = x / 500 * 1000;
            x = x % 500;
            happiness += x / 5 * 5;
            Console.WriteLine(happiness);
        }
    }
}


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

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


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sumA=0, sumB = 0;
  for(int i = 0; i < N; i +=2){
    sumA += vec.at(i);
  }
  for(int i = 1; i < N; i +=2){
    sumB += vec.at(i);
  }
  cout << sumA - sumB << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n + 1];
		for (int i = 0; i < n; i++) {
			a[i + 1] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] b = new int[n + 1];
		for (int i = n; i > 0; i--) {
			int sum = 0;
			for (int j = i; j <= n; j+=i) {
				sum += b[j];
			}
			sum %= 2;
			b[i] = (a[i] + 2 - sum) % 2;
		}

		int m = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (b[i] == 1) {
				m++;
				sb.append(i).append(' ');
			}
		}
		System.out.println(m);
		if (m != 0) {
			sb.deleteCharAt(sb.length() - 1);
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 52892
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, last, cnt,a;
struct Edge { LL to,cost; };
vector<Edge>vec;
bool f=0;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n >> m;
	if (m == 1 || m == n*2 - 1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	sum = 1;
	rep(i, n - 2) {
		sum++;
		if (sum == m)sum++;
		cout << sum << endl;
	}
	cout << 1 << endl;
	cout << m << endl;
	cout << n * 2 - 1 << endl;
	rep(i, n - 2) {
		sum++;
		if (sum == m)sum++;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
def main():
    N, Y = map(int, input().split())

    # 10000, 5000, 1000

    a = -1
    b = -1
    c = -1

    for i in range(N + 1):
        for j in range(N + 1):
            # for k in range(N + 1):
            #     cnt = i + j + k
            #     cst = 10000 * i + 5000 * j + 1000 * k
            #     if cnt == N and cst == Y:
            #         a, b, c = i, j, k
            k = N - i - j
            if k >= 0:
                cst = 10000 * i + 5000 * j + 1000 * k
                if cst == Y:
                    a, b, c = i, j, k

    print(a,b,c)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(void) {
	int p,q,i,j,k;
	int syosu[100],amari[100];
	
	while(~scanf("%d %d",&p,&q)){
		memset(syosu,0,sizeof(syosu));
		for(i = 0;i < 100;i++){
			amari[i] = p%q;
			syosu[i] = p/q;
			for(j = 0;j < i;j++){
				if(amari[j] == amari[i]){
					goto zyunkan;
				}
			}
			p = amari[i]*10;
			if(!p) goto yuri;
		}
	yuri:
		for(k = 1;k <= i;k++){
			putchar(syosu[k]+'0');
		}
		printf("\n");
		continue;
	zyunkan:
		for(k = 1;k <= i;k++){
			putchar(syosu[k]+'0');
		}
		printf("\n");
		for(k = 0;k < i;k++){
			putchar(k < j ? ' ' : '^');
		}
		printf("\n");
	}
	return 0;
}

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

int main()
{
    long long N;
    long long sum = 0;
    cin >> N;
    for(long long i = 1; i <= N; i++)
    {
        if(i % 3 == 0 || i % 5 == 0)
        {
            continue;
        }
        sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-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; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    
    ll ans=0;
    rep(d,61) {
        ll k=0;
        rep(i,n) {
            if(!(a[i]&(1LL<<d))) {
                k++;
            }
        }
        ll add=((k*(n-k)%MOD)*((1LL<<d)%MOD))%MOD;
        ans+=add;
        ans%=MOD;
        //cout<<k<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

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

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int MEM_SIZE = 5e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int bpow(int a, int b, int mod) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
    }
    return res;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

int n;
vector<vector<int>> g;

int ans = 0;

int calc(int v, int p) {
    if (v < p) {
        v = n - 1 - v;
        p = n - 1 - p;
    }
    return (v - p) * (n - v);
}

void dfs(int v, int p = -1) {
    ans += calc(v, p);
    for (auto &x : g[v]) {
        if (x == p) continue;
        dfs(x, v);
    }
}

void run() {
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(0);
    cout << ans << endl;
}

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

int a,b;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b;
	if(a * b % 2 == 0){
		cout<<"Even"<<endl;
	}else{
		cout<<"Odd"<<endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

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();
		int d=sc.nextInt();
		int ab=a*b,cd=c*d,ans=0;

		if(ab>=cd) ans=ab;
		else ans=cd;
		
		System.out.println(ans);	
	}
	
} 

Measured memory_bytes: 22608
def main():
    n = int(input())
    a = list(map(int, input().split()))

    dp = [[0 for i in range(n+2)]for i in range(n+2)]
    # dp [start][end] is the diffence between X and Y
    # such for range start to end
    for start in range(n, 0, -1):
        for end in range(start, n+1):
            if start == end:
                dp[start][end] = a[start-1]
            else:
                dp[start][end] = max(a[start-1]-dp[start+1]
                                     [end], a[end-1]-dp[start][end-1])
    print(dp[1][n])


if __name__ == "__main__":
    main()

    

Measured memory_bytes: 120540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;cin >> x >> y;
	if(x <= 1 && y <= 1) cout << "Brown" << endl;
	else if(x + y == 3) cout << "Brown" << endl;
	else if(abs(x - y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int N, M;
	cin >> N >> M;

	vector<int> A;
	int temp = 0;
	for(int i=0; i<M; i++){
			cin >> temp;
			A.emplace_back(temp);
	}

	int hw = 0;
	rep(i,M){
		hw += A[i];
	}

	if(hw > N){
		cout << "-1" << endl;
	}
	else{
		cout << N - hw << endl;
	}

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3716
l=gets.chomp.split("").map(&:to_i)
MOD=10**9+7
dp=[1,2]
1.upto(l.size-1) do |i|
  if l[i] == 0
    dp[0] = (dp[0] * 3) % MOD
  else
    dp[0] = (dp[0] * 3 + dp[1]) % MOD
    dp[1] = (dp[1] * 2) % MOD
  end
end
puts (dp[0]+dp[1])%MOD

Measured memory_bytes: 7676
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer 
    int n, m;
    cin >> n >> m;
    cout << (n * (n-1) / 2) + (m * (m-1)/2) << endl;
}

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

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

    int len = s.length();
    int len_0 = len;
    int cou = 0;

    int cen = 0;
    if(len % 2 != 0){
        s.erase(len - 1, 1);
        cen = (len - 1) / 2;
    }else{
        cen = len / 2;
    }

    while(1){
        if(s.substr(0, cen) == s.substr(cen, cen) && cou != 0){
            break;
        }else{
            len -= 2;
            cou += 2;
            cen = len / 2;
        }
    }

    cout << len_0 - cou << endl;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n+x-1)/x*t << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    long long int c1 = 0, c2 = 0, c3 = 0, c4 = 0, n, i;
    //vector<string> s;
    string q;
    cin>>n;
    for (i = 0; i < n; i++)
    {
        cin>>q;
        if (q == "AC")
            c1++;
        else if (q == "WA")
            c2++;
        else if (q == "TLE")
            c3++;
        else
            c4++;
    }
    cout<<"AC x "<<c1<<endl<<"WA x "<<c2<<endl<<"TLE x "<<c3<<endl<<"RE x "<<c4;
    return 0;
}

Measured memory_bytes: 3544
def actual(n, S, P):
    restaurant_dict_list = []

    for idx, (s, p) in enumerate(zip(S, P), start=1):
        d = dict(id=idx, name=s, point=p)
        restaurant_dict_list.append(d)

    ids = []

    for key in sorted(set(S)):
        # 市名昇順でループ → 市名ごとに抽出 → ポイント降順でソート
        s = [d for d in restaurant_dict_list if d['name'] == key]
        t = sorted(s, key=lambda x: x['point'], reverse=True)

        for u in t:
            ids.append(str(u['id']))

    return '\n'.join(ids)

n = int(input())

S, P = [], []
for _ in range(n):
  s, p = input().split()
  S.append(s)
  P.append(int(p))
  
print(actual(n, S, P))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    int ans=1;
    for(int i=2;i*i<=x;i++){
        int tmp=i;
        while(tmp*i<=x)tmp*=i;
        ans=max(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k, a, b int
	fmt.Scan(&k, &a, &b)

	for i := k; i <= 1000; i++ {
		if i <= b && a <= i {
			if i % k == 0 {
				fmt.Println("OK")
				return
			}
		}

	}
	fmt.Println("NG")
}

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

int main() {
  long long n, m;
  cin >> n >> m;
  
  if(n > m) swap(n, m);
  
  long long ans;
  if(n == 1 && m == 1) ans = 1;
  else if(n == 1) ans = m - 2;
  else if(n == 2) ans = 0;
  else ans = (n - 2) * (m - 2);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import queue

k=int(input())

q=queue.Queue()

for i in range(9):
    q.put(i+1)

c=1

for i in range(k):
    c=q.get()
    b=c%10
    if b!=0:
        q.put(10*c+b-1)
    q.put(10*c+b)
    if b!=9:
        q.put(10*c+b+1)

print(c)

Measured memory_bytes: 12480
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c,d,e,f,g,h,i,j;
    cin >>a>>b>>c>>d>>e>>f>>g>>h;
    i = a * e + b * f;
    if(a >= 10){
        i = i + g * (a/10);
        
    }
    if(b >= 20){
        i = i + h * (b/20);
    }
    
    j = c * e + d * f;
    if(c >= 10){
        j = j + g * (c/10);
        
    }
    if(d >= 20){
        j = j + h*(d/20);
    }
    
    
    
    if(i > j){
        cout<<"hiroshi"<<endl;
    }else if(i < j){
        cout <<"kenjiro"<<endl;
    }else{
        cout<<"even"<<endl;
    }
}



Measured memory_bytes: 3096
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define REP(i,n) for(int i=0; i<n; i++)
int dp[301][301];
int main(void){
    int n,w[300];
    int x;
    int dp[301][301];
    while(scanf("%d",&n),n){
        memset(dp,0,sizeof dp);
        if(n==0) break;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            w[i]=x;
        }
        for (int i=n-1; i>=0; i--) {
            dp[i][i] = 0;
            //dp[i][i+1] = 0;
            for (int j=i+1; j<n; j++) {
                if(j==i+1 && (abs(w[i] - w[j]) <= 1)) dp[i][j]=2;
                else if (/*i + 1 < j && */(abs(w[i] - w[j]) <= 1) && dp[i+1][j-1] == j-i-1)
                    dp[i][j] = j - i + 1;
                
                for (int k=j; k<n; k++)
                    if(dp[i][k]<dp[i][j-1] + dp[j][k])
                        dp[i][k]=dp[i][j-1] + dp[j][k];
            }
        }
        
        printf("%d\n", dp[0][n-1]);
        /*REP(i,n+1) {
            REP(j,n+1){
                printf("%d ",dp[i][j]);
            }
            printf("\n");
        }*/
    }
    return 0;
}



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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

string a;

int main() {
 //   freopen("test.txt","r",stdin);
    cin >> a;
    while ( a.size() >= 2) {
        a.erase(a.begin() + a.size() -1, a.begin() + a.size());
        if ( a.size() % 2 == 0 ) {
            int check = 1;
            for (int i = 0 ; i <= (a.size() /2) - 1 ;  i++) {
                if ( a[i] != a[(a.size() /2) + i]) {
                    check = 0;
                    break;
                }
            }
            if ( check ) {
                cout << a.size() ;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100005];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    sort(a+1,a+n+1,cmp);
    int min1=0,min2=2147483647;
    for(int i=2;i<=n;i++)
        if(fabs((a[1]/2)-a[i])<min2)
        {
            min1=i;
            min2=fabs((a[1]/2)-a[i]);
        }
    cout<<a[1]<<" "<<a[min1];
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m, (n || m)) {
        int rest = n;
        int pos = n-1;
        vector<int> v(n, 0);
        while (1 < rest) {
            int cnt = 0;
            while (1) {
                pos = (pos + 1) % n;
                if (v[pos] == 0) cnt ++;
                if (cnt == m) break;
            }
            v[pos] = 1;
            rest --;
        }
        int ans = 0;
        for (int i=0; i<(int)v.size(); ++i) {
            if (v[i] == 0) {
                ans = i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
n = int(input())
s = input()
ans = ''
for i in range(len(s)):
    if ord(s[i])+n >= 91:
        ord_c = ord(s[i])+n - 26
    else:
        ord_c = ord(s[i])+n
    chr_c = chr(ord_c)
    ans += chr_c

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)
int a[100010];
int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    rep(i,0,n){
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i,0,m){
        auto top = q.top();
        q.pop();
        top /= 2;
        q.push(top);
    }
    long long sum = 0;
    rep(i,0,n){
        sum += q.top();
        q.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[]) {
    int N;
    vector<int> A;
    cin  >> N;
    for (size_t i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    int max_diff = 0;
    for (size_t i = 0; i < N; i++) {
        for (size_t j = i+1; j < N; j++) {
            max_diff = max(max_diff, abs(A[i] - A[j]));
        }
    }

    cout << max_diff << endl;

    return 0;
}


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        vector<int> sticks(n); cin >> sticks;
        sort(all(sticks));
        //a, b, c [a <= b <= c]
        //a + b > c


        //a + b
        int ans = 0;
        for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                        int a = sticks[i];
                        int b = sticks[j];
                        //c < a + b
                        //j ...
                        int l = j + 1, r = n - 1, where = j;
                        while (l <= r) {
                                int mid = (l + r) / 2;
                                int c = sticks[mid];
                                if (c < a + b)  {
                                        where = mid;
                                        l = mid + 1;
                                } else {
                                        r = mid - 1;
                                }
                        }
                        ans += where - j;
                }
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3660
#include<iostream>
using namespace std;
#define MAX 500000
#define SETINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++) L[i] = A[left + i];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SETINEL;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        cnt++;
        if(L[i] <= R[j]){
            A[k] = L[i++];
        }else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right){
    if((left + 1) < right){
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main(){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];

    mergeSort(A, n, 0, n);

    for(i = 0; i < n; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  int ans;
  for(int k=1;k*k<=N;k++) {
    ans = k*k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

int main() {
  int N;
  cin >> N;
  vector<int> l(3);

  for (int i = 0; i < (int)N; ++i) {
    for (int i = 0; i < (int)3; ++i) cin >> l[i];
    sort((l).begin(), (l).end());
    cout << (l[0] * l[0] + l[1] * l[1] == l[2] * l[2] ? "YES" : "NO") << endl;
  }

  return 0;
}



Measured memory_bytes: 3120
// In The Name of Almighty Allah
#include<bits/stdc++.h>
using namespace std;
#define             fastio              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define             ff                  first
#define             ss                  second
#define             int                 long long
#define             pb                  push_back
#define             pf                  push_front
#define             pii                 pair<int,int>
#define             print(x)            for(auto it : x) cout<<it<<' '; cout<<'\n';
#define             debug(x)            cout << #x << " --->> " << x << endl;
#define             mod                 1000000007
#define             inf                 1e18
#define             PI                  (acos(-1))
#define             eps                 (1e-8)
#define             clear(x)            memset(x,0,sizeof(x));


main()
{
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	string s;

	cin >> n;
	cin >> s;

	pair<int, pii>cum[n];

	int ans = 0, r = 0, g = 0, b = 0;

	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R') r++;
		else if (s[i] == 'B') b++;
		else g++;
		cum[i].ff = r, cum[i].ss.ff = g, cum[i].ss.ss = b;
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n - 1; j++)
		{
			if (s[j] == s[i]) continue;

			int k = 2 * j - i;
			// debug(k);
			if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
			{
				ans += (cum[n - 1].ss.ss - cum[j].ss.ss);

				if (k < n && s[k] == 'B')
					ans--;
			}
			else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
			{
				ans += (cum[n - 1].ss.ff - cum[j].ss.ff);

				if (k < n && s[k] == 'G')
					ans--;
			}
			else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G'))
			{
				ans += (cum[n - 1].ff - cum[j].ff);

				if (k < n && s[k] == 'R')
					ans--;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int hebi = 0;
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l[i];
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  for (int i = 0; i < k; i++) hebi += l[i];
  cout << hebi;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include "atcoder/dsu.hpp"

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

template <typename T> void read(T& x) { x.read(); }
template <typename T> void read(vector<T>& v) { for (T& x: v) read(x); }
template <typename X, typename Y> void read(pair<X, Y>& p) { read(p.first); read(p.second); }
template <> void read(int& x) { scanf("%d", &x); }
template <> void read(unsigned int& x) { scanf("%u", &x); }
template <> void read(long long& x) { scanf("%lld", &x); }
template <> void read(unsigned long long& x) { scanf("%llu", &x); }
template <typename T> void readv(vector<T>& v) { int N; read(N); v.resize(N); read(v); }
template <typename T, typename ...Ts> void read(T& x, Ts&... args) { read(x); read(args...); }

int main(int argc, const char* argv[]) {
    int N, Q;
    read(N, Q);
    atcoder::dsu dsu(N);
    while (Q --> 0) {
        int t, u, v;
        read(t, u, v);
        if (t == 0) {
            dsu.merge(u, v);
        } else {
            if (dsu.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4016