akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

const int maxN = 1e5; int n;
int p[maxN], pos[maxN + 1];

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    for (int i = 0; i < n; i ++)
    {
      scanf("%d", &p[i]);
      pos[p[i]] = i;
    }

    lli ans = 0;
    multiset<int> abovePosition;
    abovePosition.insert({-1, -1, n, n});
    for (int number = n; number >= 1; number --)
    {
      abovePosition.insert(pos[number]);
      auto it = abovePosition.find(pos[number]);
      int beforeBigger1 = *prev(it, 1), beforeBigger2 = *prev(it, 2);
      int afterBigger1 = *next(it, 1), afterBigger2 = *next(it, 2);
      int beforeCombinations = (beforeBigger1 - beforeBigger2) * (afterBigger1 - pos[number]);
      int afterCombinations = (afterBigger2 - afterBigger1) * (pos[number] - beforeBigger1);
      ans += (lli) number * (beforeCombinations + afterCombinations);
    }
    printf("%lld\n", ans);
  }
  return(0);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll cnt = 0;
    rep(i,N-1){
        if(A[i] > A[i+1]){
            cnt = cnt + A[i] - A[i+1];
            A[i+1] = A[i];
        }
        else{
            continue;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4812
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > a(N);
  int sum = 0;
  for (int i=0; i<N; i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  printf("%d\n", sum-N);
  return 0;
}


Measured memory_bytes: 888
from fractions import gcd
N,X=map(int,input().split())
x=list(map(int,input().split()))
if N == 1:
  print(abs(x[0]-X))
  exit()
x.append(X)
x.sort()
y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
ans=gcd(y[0],y[1])
for i in range(2,len(y)):
  ans=gcd(ans,y[i])
print(ans)

Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll N, X;
    cin >> N >> X;
    vector<ll> M(N);
    repi(i, N, 0)
    {
        cin >> M[i];
        X -= M.at(i);
    }

    ll Donuts = N;
    sort(all(M));
    Donuts += int(X/M.at(0));
    cout << Donuts << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  int P, Q, R;
  int bigger;
  cin >> P >> Q >> R;
  bigger = P;
  if(bigger < Q)
    bigger = Q;
  if(bigger < R)
    bigger = R;
  cout << P + Q + R - bigger;
  return 0;
}

Measured memory_bytes: 256
'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]
  const k = input[0][1]

  const nums = input[1].sort((a, b) => { return b - a}).slice(0, k)
  const ans = nums.reduce((a,b)=> a+b)

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]

s = []
for i in a:
  s += i[1:]

ans = 0
for i in range(1, 31):
  if s.count(i)==n:
    ans += 1
    
print(ans)    

Measured memory_bytes: 38384
"""
UnionFind木を使う。
Ai,Aj,Zの情報が与えられたら、Ai,AjをUniteする。
同じグループにいるA同士は連鎖関係に合って、グループ内の一つでも数字がわかれば連鎖的に同グループのAの値もわかる。
この問題の問に対する答えは、グループの数となる。
"""
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents = [i for i in range(n+1)]
        self.size = [1]*(n+1)
    def find(self,x):
        if self.parents[x]==x:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        xRoot = self.find(x)
        yRoot = self.find(y)
        if xRoot == yRoot:
            return
        if self.size[xRoot]>self.size[yRoot]:
            self.parents[yRoot] = xRoot
            self.size[xRoot] += self.size[yRoot]
            self.size[yRoot] = 0
        else:
            self.parents[xRoot] = yRoot
            self.size[yRoot] += self.size[xRoot]
            self.size[xRoot] = 0

N,M = map(int,input().split())
tree = UnionFind(N)
for _ in range(M):
    x,y,z = map(int,input().split())
    tree.unite(x,y)
print(N-tree.size.count(0))

Measured memory_bytes: 75540
using System;

class Test
{
  static void Main()
  {
    int num, limit;
    string[] str = Console.ReadLine().Split(' ');
    num = int.Parse(str[0]);
    limit = int.Parse(str[1]);
    
    string[] height = Console.ReadLine().Split(' ');
    
    int cnt = 0;
    for(int i = 0; i < num; i++)
    {
      if(int.Parse(height[i]) >= limit)
      {
        cnt++;
      }
    }
    
    Console.WriteLine(cnt);
  }
}

Measured memory_bytes: 15584
#include<stdio.h>

int main()
{
	int t;
	long long int a, max=1e18,flag=0,zero=0,prod=1;
	
	scanf("%d",&t);
	
	for (int i=0;i<t;i++)
	{
		scanf("%lld",&a);
		flag=(a>max) ? 1:flag;
		prod*=a;
		a!=0 ? max=max/a : zero=1;
	}
	if (zero==1)
	{
		printf("0\n");
	}
	
	else if (flag == 1)
	{
		printf("-1\n");
	}
	else
	{
		printf("%lld\n",prod);
	}
	
	return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
long n;
void solve()
{
    vector < long > a(n),b(n);
    long i;
    long long ans1=0,ans2=0;
    for (i=0;i<n;i++)
        cin>>a[i];
    for (i=0;i<n;i++)
        cin>>b[i];
    for (i=0;i<n;i++)
    {
        if (a[i]<=b[i]) ans1+=(b[i]-a[i]+1)/2;
        ans2+=b[i]-a[i];
    }
    if (ans1<=ans2) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 384
N = int(input())
h = [int(x) for x in input().split()]
dist = [10**10]*N
for index,i in enumerate(h):
    if(index == 0):
        dist[index] = 0
    elif(index == 1):
        dist[index] = abs(i-h[0])
    else:
        dist[index] = min(abs(i-h[index-1])+dist[index-1],abs(i-h[index-2])+dist[index-2])

print(dist[N-1])

Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;
bool visd[5][5];
int a[5][5],b;
int main()
{
	scanf("%d%d%d%d%d%d%d%d%d",&a[1][1],&a[1][2],&a[1][3],&a[2][1],&a[2][2],&a[2][3],&a[3][1],&a[3][2],&a[3][3]);
	cin>>b;
	while(cin>>b)for(int i=1;i<=3;i++)for(int j=1;j<=3;j++)if(a[i][j]==b)visd[i][j]=1;
	if(visd[1][1]&&visd[1][2]&&visd[1][3])puts("Yes");
	else if(visd[2][1]&&visd[2][2]&&visd[2][3])puts("Yes");
	else if(visd[3][1]&&visd[3][2]&&visd[3][3])puts("Yes");
	else if(visd[1][1]&&visd[2][1]&&visd[3][1])puts("Yes");
	else if(visd[1][2]&&visd[2][2]&&visd[3][2])puts("Yes");
	else if(visd[1][3]&&visd[2][3]&&visd[3][3])puts("Yes");
	else if(visd[1][1]&&visd[2][2]&&visd[3][3])puts("Yes");
	else if(visd[1][3]&&visd[2][2]&&visd[3][1])puts("Yes");
	else puts("No");
	return 0;
}

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

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

  if(s=="SUN") cout<<7<<endl;
  if(s=="MON") cout<<6<<endl;
  if(s=="TUE") cout<<5<<endl;
  if(s=="WED") cout<<4<<endl;
  if(s=="THU") cout<<3<<endl;
  if(s=="FRI") cout<<2<<endl;
  if(s=="SAT") cout<<1<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

int main() {
	int v1,v2,ret;
	double sum=0;
	vector<int> l(10, 0);
	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF) {
		sum = 0;
		for (int i=0; i<10; i++) {
			sum += l[i];
		}
		sum /= (v1+v2);
		sum *= v1;
		for (int i=0; i<10; i++) {
			sum -= l[i];
			if (sum <= 0) {
				ret = i+1;
				break;
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import array
import sys
def counting_sort(A, B, n, k=10000):
    C = array.array('I', [0 for i in range(k+1)])
    for j in range(0, n):
        x = A[j]
        C[x] += 1
    for i in range(0, k+1):
        C[i] += C[i - 1]
    for j in range(n - 1, -1, -1):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1

n = int(input())
A = list(map(int , sys.stdin.readline()[:-1].split()))

B = array.array("I", [0 for i in range(n)])
counting_sort(A, B, n)

print(*B)

Measured memory_bytes: 221024
#include <iostream>

using namespace std;

static const int MAX = 100;

int main () {
  int N, A[MAX];

  cin >> N;

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

  int count = 0;

  for (int i = 0; i < N; i++) {
    int minj = i;
    int origin = A[i];
    for (int j = i; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }

    if (i != minj) {
      A[i] = A[minj];
      A[minj] = origin;
      count++;
    }

  }

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << A[i];
  }

  cout << endl;
  cout << count << endl;

}

Measured memory_bytes: 3104
#include <stdio.h>

int main() {
  int H, W;
  int h, w;
  while(1) {
    scanf("%d%d", &H, &W);
    if (H == 0 && W == 0) break;
    for (h = 0; h < H; h++) {
      for (w = 0; w < W; w++) {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2064
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 1e5 + 5;

int n, q;
int fr[N];

int main()
{
  cin >> n;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    fr[a]++;
  }
  ll ans = 0;
  for(int i = 0; i < N; i++)
    ans += 1LL * fr[i] * i;
  cin >> q;

  while(q--) {
    int b, c;
    cin >> b >> c;
    ans -= 1LL * fr[b] * b;
    ans += 1LL * fr[b] * c;
    fr[c] += fr[b];
    fr[b] = 0;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4020
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]
 
large = np.max([C, D])
small = np.min([C, D])
 
#def gcd(a, b):
#    while b:
#        a, b = b, a % b
#    return a
while small != 0:
    large, small = small, large % small
gcd = large

def lcm(a, b, gcd):
    return a * b // gcd

large = np.max([C, D])
small = np.min([C, D])
 
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // lcm(large, small, gcd)
 
num_A_1 = (A-1) // C
num_A_2 = (A-1) // D
num_A_3 = (A-1) // lcm(large, small, gcd)
 
numB = num_B_1 + num_B_2 - num_B_3
numA = num_A_1 + num_A_2 - num_A_3
 
print((B-A+1) - (numB - numA))

Measured memory_bytes: 12512
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	
	int mat[n+1][n+1];
	for(int i = 0; i < n; i++){
		int u, k;
		scanf("%d %d", &u, &k);
		
		for(int j = 0; j <= n; j++){
			mat[u][j] = 0;
		}
		while(k--){
			int v;
			scanf("%d", &v);
			mat[u][v] = 1;
		}
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			printf("%d%c", mat[i][j], j==n ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 200005;

struct Node
{
	int c0,c1,id;
	
	bool operator == (const Node &p)const
	{
		return c0 == p.c0 && c1 == p.c1 && id == p.id;
	}
	
	bool operator < (const Node &p)const
	{
		if ((ll)c0 * p.c1 == (ll)p.c0 * c1)
		{
			if (c0 == p.c0)
			{
				if (c1 == p.c1)
					return id < p.id;
				return c1 < p.c1;
			}
			return c0 < p.c0;
		}
		return (ll)c0 * p.c1 < (ll)p.c0 * c1;
	}
};

int n;
int p[MAXN];
int fa[MAXN];
int c[MAXN][2];

ll ans;

priority_queue<Node> Q,rQ;

int getroot(int u)
{
	return u == fa[u] ? u : fa[u] = getroot(fa[u]);
}

int main()
{
	scanf("%d",&n);
	for (int i = 2;i <= n;i++)
		scanf("%d",&p[i]);
	for (int x,i = 1;i <= n;i++)
	{
		fa[i] = i;
		scanf("%d",&x);
		c[i][x]++;
		if (i > 1)
			Q.push((Node){c[i][0],c[i][1],i});
	}
	while (Q.size() != rQ.size())
	{
		while (!rQ.empty() && Q.top() == rQ.top())
		{
			Q.pop();
			rQ.pop();
		}
		int u = Q.top().id,f = getroot(p[u]);
		Q.pop();
		ans += (ll)c[f][1] * c[u][0];
		if (f > 1)
			rQ.push((Node){c[f][0],c[f][1],f});
		c[f][0] += c[u][0];
		c[f][1] += c[u][1];
		fa[u] = f;
		if (f > 1)
			Q.push((Node){c[f][0],c[f][1],f});
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11760
def main(argv)
  s = gets.chomp
  if s.size == 1 then
    puts 'YES'
    return
  end

  c = [0, 0, 0]
  s.size.times{|i| c[s[i].ord - 'a'.ord] += 1}
  c.sort!{|a, b| b <=> a}

  if ((c[1] == 0) and (c[2] == 0)) then
    puts 'NO'
    return
  end

  if c[2] == 0 then
    puts (s.size == 2 ? 'YES' : 'NO')
    return
  end

  abc = c[2]
  ab  = c[1] - c[2]
  a   = c[0] - (abc + ab)

  if a > 1 then
    puts 'NO'
    return
  end

  if ((ab > 0) and (a > 0)) then
    puts 'NO'
    return
  end

  puts 'YES'
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 3836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {



        public static bool[] primes = Enumerable.Repeat(true,1000000+1).ToArray();
        public static void initTable() {
            primes[0] = false;
            primes[1] = false;
            for (int i = 2; i < 1000000 / 2; i++) {
                if (primes[i]) {
                    for (int j = 2; i * j <= 1000000; j++) {
                        primes[i * j] = false;
                    }
                }
            }
        }



        public static void Main(String[] args) {
            string line;
            initTable();
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line.Split(' ')[0]);
                int x = int.Parse(line.Split(' ')[1]);
                if (n == 0) { break; }
                int[] prices = new int[n];
                for (int i = 0; i < n; i++) {
                    prices[i] = int.Parse(Console.ReadLine());
                }
                int max = 0;
                bool[] kaeru = new bool[x + 1];
                kaeru[0] = true;
                for (int i = 0; i < n; i++) {
                    for (int j = prices[i]; j < x + 1; j++) {
                        if (kaeru[j - prices[i]]) {
                            kaeru[j] = true;
                            if (primes[j]&&j > max) { max = j; }
                        }
                    }
                }
                if(max==0){Console.WriteLine("NA");}
                else { Console.WriteLine(max); }


    
            }
        }


    }

    
}

Measured memory_bytes: 18344
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] o = scanner.nextLine().toCharArray();
			char[] e = scanner.nextLine().toCharArray();
			StringBuilder sb = new StringBuilder();
			IntStream.range(0, e.length).forEach(i -> sb.append(o[i]).append(e[i]));
			IntStream.range(0, o.length - e.length).forEach(i -> sb.append(o[o.length - 1 - i]));
			System.out.println(sb.toString());
		}
	}
}


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

cnt1=S.count('0')
cnt2=S.count('1')

print(len(S)-abs(cnt1-cnt2))


Measured memory_bytes: 5984
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    S = read().strip().decode()
    if S == 'ABC':
        print('ARC')
    else:
        print('ABC')
    return

if __name__ == '__main__':
    main()


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

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> mp(h);
  for(int i=0; i<h; ++i){
    cin >> mp[i];
  }
  bool ans = true;
  for(int i=0; i<h; ++i){
    for(int j=0; j<w; ++j){
      if(mp[i][j] == '.') continue;
      bool nans = true;
      if(i && mp[i-1][j] == '#') nans = false;
      if(i!=h-1 && mp[i+1][j] == '#') nans = false;
      if(j && mp[i][j-1] == '#') nans = false;
      if(j!=w-1 && mp[i][j+1] == '#') nans = false;
      if(nans) ans = false;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S=[None]*n
    T=[None]*n
    for i in range(n):
        s,t=input().split()
        S[i]=s
        T[i]=int(t)

    k=S.index(input())
    ans=0
    for i in range(k+1,n):
        ans+=T[i]

    print(ans)
resolve()

Measured memory_bytes: 38384
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int A, B, M;
vector<int> a, b;
vector<pair<pair<int, int>, int>>X;
priority_queue<int, vector<int>, greater<int>> P;
int main() {
	cin >> A >> B >> M;
	for (int i = 0; i < A; i++) {
		int _a;
		cin >> _a;
		a.push_back(_a);
	}
	for (int i = 0; i < B; i++) {
		int _b;
		cin >> _b;
		b.push_back(_b);
	}
	for (int i = 0; i < M; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		x--;
		y--;
		auto p1 = make_pair(x, y);
		auto p2 = make_pair(p1, c);
		X.push_back(p2);
	}
	for (int i = 0; i < X.size(); i++) {
		P.push(a[X[i].first.first] + b[X[i].first.second] - X[i].second);
	}
	sort(a.begin(), a.end(), less<int>());
	sort(b.begin(), b.end(), less<int>());
	P.push(a[0] + b[0]);

	int ANS = P.top();
	cout << ANS;
	return 0;

}

Measured memory_bytes: 3056
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

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

	if (k % 2 == 0) {
		cout << (k / 2) * (k / 2) << endl;
		return 0;
	}
	else {
		cout << (k / 2) * (k / 2 + 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		String s=in.next();
		String t="";
		for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i)=='0') {
				t=t+s.charAt(i);
			}
			if(s.charAt(i)=='1') {
				t=t+s.charAt(i);
			}
			if(s.charAt(i)=='B'&& t.length()>0) {
				t=t.substring(0,t.length()-1);
			}
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 26916
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
    i64 n;
    cin >> n;

    if (n%2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    i64 ans{0};
    for (i64 i=10; i<=n; i*=5) {
        ans += n/i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
let arr = readLine()!.characters.split{$0==" "}.map{Int(String($0))}
let h = arr[0]
let n = arr[1]

let a = readLine()!.characters.split{$0==" "}.map{Int(String($0))}
var sumA = 0
a.forEach{sumA += $0!}

print((h <= sumA) ? "Yes" : "No")

Measured memory_bytes: 7476
import sys
readline = sys.stdin.readline
n = int(input())
dp = list(list(map(int, readline().split())) for _ in range(n))
for i in range(1, n):
    dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] += max(dp[i - 1][2], dp[i - 1][0]);
    dp[i][2] += max(dp[i - 1][0], dp[i - 1][1]);
print(max(dp[n - 1]))


Measured memory_bytes: 30576
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;
 
 
class Main {
  public static void main(String[] args) {
    //input
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<MyProcess> d = new ArrayDeque<MyProcess>();
    for(int i = 0; i < n; ++i) {
        String name = sc.next();
        int time = sc.nextInt();
        d.add(new MyProcess(name, time));
    }
     
    int elapsed = 0;
    while(!d.isEmpty()){
         MyProcess p = d.removeFirst();
         if(p.time > q) {
            elapsed += q;
            d.add(new MyProcess(p.name, p.time - q));
         }else{
            elapsed += p.time;
            System.out.println(p.name + " "  + elapsed);
         }
    }
  }
}
 
class MyProcess {
    public String name;
    public int time;
    public MyProcess(String n, int t) {
        name = n;
        time = t;
    }
 }

Measured memory_bytes: 72496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

ll a,b,c,k, ma;

int main(){
    cin >> a >> b >> c >> k;
    ma = max(a, max(b,c));

    for(int i = 0; i < k; i++)  ma *= 2;
    cout << a+b+c+ma-max(a,max(b,c)) << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (a, b) = read!(usize, usize);

    if a >= 13 {
        println!("{}", b);
    } else if a >= 6 {
        println!("{}", b / 2);
    } else {
        println!("0");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin>>n;
	int a[n+1]; rep(i,n) cin>>a[i+1];
	vector<int> ans;
	int used[n+1]={};
	for(int i=n;i>=2;i--){
		int tmp=0;
		for(int j=n/i*i;j>=1;j-=i){
			tmp+=used[j];
		}
		if(a[i]!=tmp%2){
			used[i]++;
			ans.push_back(i);
		}
	}
	if(a[1]!=ans.size()%2) ans.push_back(1);
	int nn=ans.size();
	sort(ans.begin(),ans.end());
	cout<<nn<<endl;
	for(int i=0;i<nn;i++){
		cout<<ans[i]<<(i!=nn-1?" ":"\n");
	}
	return 0;
}

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

int main()
{
    int N, W;
    cin >> N >> W;
 
    int v[N],w[N];
    
    for(int i=0; i<N; i++){
        cin >> v[i] >> w[i];
    }
 
    int dp[N+1][W+1];

    for(int j=0; j<=W; j++)
        dp[N][j] = 0;
 
    for(int i=N-1; i>=0; i--){
        for(int j=0; j<=W; j++){
            if(j<w[i])
                dp[i][j] = dp[i+1][j];
            else{
                if(dp[i+1][j]>dp[i+1][j-w[i]]+v[i])
                    dp[i][j] = dp[i+1][j];
                else    
                    dp[i][j]=dp[i+1][j-w[i]]+v[i];         
             }
        }
   } 
    cout << dp[0][W] << endl;
 
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    cout << (2 * k - 1 <= n ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

vector = [-1 * (y2 - y1), x2 - x1]
x3 = x2 + vector[0]
y3 = y2 + vector[1]
x4 = x1 + vector[0]
y4 = y1 + vector[1]

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
import sys
from collections import defaultdict


def solve(line):
    split = line.split()
    count = defaultdict(int)
    for s in split:
        count[s] += 1

    for k, v in count.items():
        if v == 1:
            return k


if __name__ == '__main__':
    print(solve(sys.stdin.readline()))


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

int main() {
	ll N, A = 0, B = 0, C = 0;
	cin >> N;
	string S;
	cin >> S;
	ll gk = 0;
	for (ll i = 0;i < N;i++) {
		ll x = i, y = N - i;
		while (x) {
			if (x % 2)break;
			gk--;
			x /= 2;
		}
		while (y) {
			if (y % 2)break;
			gk++;
			y /= 2;
		}
		if (i == 0)gk = 0;

		if (gk == 0) {
			if (S[i] == '2') {
				B++;
			}
			else if (S[i] == '3') {
				C++;
			}
		}
		if (S[i] == '2')A++;
	}
	if (B & 1) {
		cout << 1 << endl;
	}
	else if (A) {
		cout << 0 << endl;
	}
	else if (C & 1) {
		cout << 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 1540
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	char str[8];
	cin >> str;

	if (str[0] == str[2])
		cout << "Yes";
	else
		cout << "No";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    bool ansb = true;
    string c;
    cin >>c;
    int s[1000] ={0};
    rep(i,c.size()){
        s[(int)c[i]]++;
    }
    rep(i,200){
        if((s[i])!=0&&s[i]!=2 ){
            ansb = false;
            break;
        }
    }
    if(ansb){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define debug1(a) cout<<#a<<" "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<" "#c<<" "<<(c)<<endl;
typedef long double ld;
void solve()
{
	ll a, b;
	cin >> a >> b;
	ll val = (a * b) / (__gcd(a, b));
	cout << val << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t = 1;
	while (t--)
	{
		solve();
	}
}

Measured memory_bytes: 3652
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
p = LIST()
p.sort()
print(sum(p[:K]))


Measured memory_bytes: 10064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <functional>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	
	vector<tuple<string, int, int>> a;
	for (int i = 1; i <= n; i++)
	{
		string s;
		int p;
		cin >> s >> p;
		p = -p;
		a.push_back(tie(s, p, i));
	}

	sort(a.begin(), a.end());
	
	for (int i = 0; i < n; i++) {
		cout << get<2>(a[i]) << endl;
	}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, m; cin >> n >> m;
    if (n < m)swap(n, m);
    if (n - m > 1)cout << "0\n";
    else {
        ll ans = (n == m ? 2 : 1);
        for (ll i = 2; i <= n; ++i)(ans *= i) %= mod;
        for (ll i = 2; i <= m; ++i)(ans *= i) %= mod;
        cout << ans << "\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  if (N % 1110 <= 9) {
    cout << "Yes" << endl;
  }
  else if ((N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c$`&I!ES>v480@q58h!atm#yy9VRsPBOM1P1R4zjN;6H{*Uu)DfG;HPJ=@O?ts4jEja1J!?~Lt0nPD28hd~cF?bD=Xf%^5=(LPV;u<v!hiYAA)(~D@S(wK4OJMGmKogksHzD*O==oaXBc{y{`Fr`W8luZIog@8c76Wq+79@~t>c^(s~w9Rs`V`us@O@LyhqyPmKoCExGHNA#n5phT&7e`qhVbc=x4zF(|NT=~DGF(lOmEsIX(ws;WNT>a`v!FJ<dX0^CY!`6vkLphstf|Ghyk}ydX1u!R@-5#rU}V$73K#^S;7N@DFW7-)le`q#WIVQ`14Bv66J?Y)d#Z|jv4v55U(V)=(H7F+#YVNjas$(d2oDv=a<|rbybt=wdP8t{s)KuoJIX!8-F$@Ra>r_}w?$<gs;x7Jk!>Cy;51zfTT$iwsPi>V!e5yk9-B{lpk>lD|KRh>h5")))
    os.system('cythonize -i -3 -b solve.pyx')
import solve

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

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

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;
// TOP
void Main()
{
	vector<int> V(3);
	rep(i, 3)
			cin >>
		V.at(i);
	sort(V.rbegin(), V.rend());
	int x = V.at(0) - V.at(1) + V.at(0) - V.at(2);
	if (x % 2 == 0)
		cout << x / 2 << endl;
	else
		cout << x / 2 + 2 << endl;
}
// END

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
x+=sum(xarr)
y+=sum(yarr)
if x%2==1 or y%2==1:
  print('No')
else:
  #DP for xarr,yarr
  xdp=[0]*8005
  xdp[0]=1
  for val in xarr:
    for i in range(8004,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*8005
  ydp[0]=1
  for val in yarr:
    for i in range(8004,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')

Measured memory_bytes: 42844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n,m,x;
    cin>>n>>m>>x;
    ll cost[n];
    ll meow[n][m];
    ll arr[m]={0};
    rep(i,0,n){
    	cin>>cost[i];
    	rep(j,0,m){
    		cin>>meow[i][j];
    		arr[j]+=meow[i][j];
    	}
    }
    rep(i,0,m){
    	if (arr[i]<x){
    		cout<<-1<<endl;
    		return;
    	}
    }
    ll ans=inf;
    ll tempcost;
    bool flag;
    rep(i,0,1<<12){
    	tempcost=0;
    	flag=1;
    	memset(arr,0,sizeof arr);
    	rep(j,0,n){
    		if (i&(1<<j)){
    			tempcost+=cost[j];
    			rep(k,0,m){
    				arr[k]+=meow[j][k];
    			}
    		}
    	}
    	rep(j,0,m){
    		if (arr[j]<x){
    			flag=0;
    		}
    	}
    	if (flag){
    		ans=min(ans,tempcost);
    	}
    }
    cout<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

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

int main() {
  string S, A;
  cin >> S;
  for(int i=0;i<S.size();i++){
    if (S.at(i)=='0'){
      A.push_back('0');
    }
    else if(S.at(i)=='1'){
      A.push_back('1');
    }
    else if(S.at(i)=='B' && A.size()!=0){
      A.erase(A.size()-1,1);
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

cost = [1001001001] * n
cost[0] = 0

for i in range(n):
    if i < n-k:
        for j in range(i+1, i+k+1):
            cost[j] = min(cost[j], cost[i] + abs(h[i] - h[j]))
    else:
        for j in range(i, n):
            cost[j] = min(cost[j], cost[i] + abs(h[i] - h[j]))

print(cost[-1])




Measured memory_bytes: 52592
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=1<<18;
int n,a[MN],lim,x[MN],y[MN];
inline void calc(int v,int pos){
	if(x[pos]==v||y[pos]==v)return;
	if(a[x[pos]]<a[v])y[pos]=x[pos],x[pos]=v;
	else if(a[y[pos]]<a[v])y[pos]=v;
}
int main(){
	scanf("%d",&n);lim=1<<n;
	for(reg int i=0;i<lim;i++)scanf("%d",a+i),x[i]=i,y[i]=lim;
	for(reg int i=0;i<lim;i++)
		for(reg int j=0;j<n;j++)
			if(i&(1<<j)){
				reg int k=i^(1<<j);
				calc(x[k],i),calc(y[k],i);
			}
	for(reg int i=1,ans=0;i<lim;i++)printf("%d\n",ans=max(ans,a[x[i]]+a[y[i]]));
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M; cin >> N >> M;
	VI mo(M, 0);
	VI A(N);
	int cnt[100010] = { 0 };
	REP(i, N) {
		int a; cin >> a;
		cnt[a]++;
		mo[a%M]++;
		A[i] = a;
	}

	int ans = 0;
	int o = 1, p = M - 1;
	while (o <= p) {
		if (o == p) {
			ans += mo[o] / 2;
			mo[o] = mo[o] % 2;
		}
		else {
			int tmp = min(mo[o], mo[p]);
			ans += tmp;
			mo[o] -= tmp;
			mo[p] -= tmp;
		}
		o++;
		p--;
	}


	REP(i, N) {
		int a = A[i];
		int tmp= min(mo[a%M] / 2, cnt[a] / 2);
		ans += tmp;
		mo[a%M] -= tmp * 2;
		cnt[a] -= tmp * 2;
	}




	cout << ans + mo[0] / 2 << endl;
	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

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

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

  int n; cin >> n;
  unordered_map<ll, ll> unmp;
  ll a;
  rep(i, n) {
    cin >> a;
    unmp[a]++;
  }

  ll ans = 0;
  for(auto elem : unmp) {
    if(elem.second&1) ans++;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4388
#include<iostream>
using namespace std;
int main()
{
	int n, m, totalDays = 0, currDay = 0;
	cin>>n>>m;
	for(int i=0; i<m;i++)
	{
		cin>>currDay;
		totalDays+=currDay;
	}
	int freeDays = n-totalDays;
	if(freeDays < 0)
	{
		cout<<"-1";
	}
	else
	{
		cout<<freeDays;
	}
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }
    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main(){
    int n;
    cin >> n;
    int a[n][n];
    REP(i,n){
        REP(j,n){
            cin >> a[i][j];
        }
    }
    Mint<> dp[1 << n];
    dp[0] = 1;
    for(int bit = 0; bit < 1 << n; bit++){
        int i = __builtin_popcount(bit);
        for(int j = 0; j < n; j++){
            if(a[i][j] == 0 || bit & 1 << j) continue;
            dp[bit | 1 << j] += dp[bit];
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if( s == u ) a--;
    if( t== u ) b--;
    cout<<a<<' '<<b<<endl;
    return 0;
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string N;
    cin >> N;
    int res = 0;
    for (int i=0;i<N.size();i++){
        res += (int)(N[i] - '0');
        res %= 9;
    }
    if (res % 9 == 0) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 3740