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

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

  ll X; cin >> X;
  ll Y; cin >> Y;
  ll A; cin >> A;
  ll B; cin >> B;
  ll C; cin >> C;

  vector<ll> P(A); for (ll i = 0; i < A; i++) cin >> P[i];
  vector<ll> Q(B); for (ll i = 0; i < B; i++) cin >> Q[i];
  vector<ll> R(C); for (ll i = 0; i < C; i++) cin >> R[i];
  sort(P.rbegin(), P.rend());
  sort(Q.rbegin(), Q.rend());
  sort(R.rbegin(), R.rend());

  priority_queue<ll, vector<ll>, greater<ll>> qa;
  priority_queue<ll, vector<ll>, greater<ll>> qb;
  for (ll i = 0; i < X; i++) qa.emplace(P[i]);
  for (ll i = 0; i < Y; i++) qb.emplace(Q[i]);
  for (ll i = 0; i < C; i++) {
    ll p = qa.top();
    ll q = qb.top();
    ll r = R[i];
    if (r <= p && r <= q) break;
    if (p < q) {
      qa.pop();
      qa.emplace(r);
    } else {
      qb.pop();
      qb.emplace(r);
    }
  }
  ll ans = 0;
  for (ll i = 0; i < X; i++) {
    ans += qa.top(); qa.pop();
  }
  for (ll i = 0; i < Y; i++) {
    ans += qb.top(); qb.pop();
  }
  cout << ans << '\n';
  return 0;
}

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

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
*/

int checkpoint_num=0;
void pcheck(){
    cout << "----------------" << endl << checkpoint_num << endl << "----------------" << endl;
    checkpoint_num +=1;
}

template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
}

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
}

class UnionFind {
    public:
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N+1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N+1; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(void){
    int n,a;
    scanf("%lld",&n);
    vector<long long> arr(n,0);
    vector<long long> buf(n,-1);
    long long col = 0;
    for (int i = 0; i < n; ++i){
        cin >> a;
        arr[i] = a;
    }

    for (int i = 0; i < n; ++i){
        long long temp = arr[i];
        if (buf[n-1] < temp){
            buf[n-1] = temp;
        }else{
            auto key = lower_bound(buf.begin(),buf.end(),temp);
            --key;
            *key = temp;
        }
    }
    int c = 0;
    for (int i =0; i < n; ++ i){
        if (buf[i] != -1){
            c += 1;
        }
    }
    cout << c << endl;
};


Measured memory_bytes: 1792
n = int(input())
v = list(map(int,input().split()))
v_odd,v_eve = v[0::2],v[1::2]
lvo,lve = len(v_odd),len(v_eve)

v_odd_s = {}
for c in v_odd:v_odd_s[c] = v_odd_s.get(c,0) + 1
v_odd_l = []
for c in v_odd_s.keys():v_odd_l.append([c,v_odd_s[c]])
sorted_v_odd_l = sorted(v_odd_l, key=lambda x: x[1],reverse = True)

v_eve_s = {}
for c in v_eve:v_eve_s[c] = v_eve_s.get(c,0) + 1
v_eve_l = []
for c in v_eve_s.keys():v_eve_l.append([c,v_eve_s[c]])
sorted_v_eve_l = sorted(v_eve_l, key=lambda x: x[1],reverse = True)

if (len(sorted_v_odd_l) == 1) or (len(sorted_v_eve_l) == 1):
    if (len(sorted_v_odd_l) == 1) and (len(sorted_v_eve_l) == 1):
        if sorted_v_odd_l[0][0] != sorted_v_eve_l[0][0]:print(0)
        else:print(n//2)
    else:
        if len(sorted_v_odd_l) == 1:
            if sorted_v_odd_l[0][0] != sorted_v_eve_l[0][0]:print(n//2-sorted_v_eve_l[0][1])
            else:print(0 + n//2-sorted_v_eve_l[1][1])
        else:
            if sorted_v_odd_l[0][0] != sorted_v_eve_l[0][0]:print(n//2-sorted_v_odd_l[0][1]) 
            else:print(0 + n//2-sorted_v_odd_l[1][1])
else:
    if sorted_v_odd_l[0] == sorted_v_eve_l[0]:
        p1 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[1][1]
        p2 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[0][1]
        p3 = p4 = -1
    else:
        p1 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[0][1]
        p2 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[0][1]
        p3 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[1][1]
        p4 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[1][1]
    for i in sorted([p1,p2,p3,p4]):
        if i>=0:
            print(i)
            break

Measured memory_bytes: 25696
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 N, i, j;
  cin >> N;
  vvi x(N), y(N);
  REP(0, N, i) {
    i64 k;
    cin >> k;
    x[i].resize(k);
    y[i].resize(k);
    REP(0, k, j) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  unsigned long long b=0;
  i64 ans = 0;
  while(b < (unsigned long long)(1<<N)) {
    bool valid = true;
    REP(0, N, i) {
      i64 k = sz(x[i]);
      if((b & (1 << i)) != 0) {
	REP(0, k, j) {
	  bool f = ((b & (1 << x[i][j])) != 0);
	  if((y[i][j] == 0 && f) || (y[i][j] == 1 && (!f))) {
	    valid = false;
	    break;
	  }
	}
	if(!valid)
	  break;
      }
    }
    if(valid) {
      i64 candidate = 0;
      REP(0, N, i) {
	if((b & (1 << i)) != 0)
	  ++candidate;
      }
      ans = max(ans, candidate);

      //cout << "valid " << b << endl;
    }
    
    ++b;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] > score_i:
                break
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if i >= N - P:
        r = i
    elif M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)

Measured memory_bytes: 22052
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    while(n!=0)
    {
    	int m=n%10;
    	if(m==9)
    	{
    		cout<<"Yes";
    		return 0;
		}
		else n/=10;
	}
	cout<<"No";
	return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a[n];
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += a[i];
    }
    sort(a, a+n);
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            if (i < n-1 && a[i] + a[i+1] < 0) ans -= (a[i] + a[i+1]) * 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    A = list(mi())

    m = 0
    ans = 0
    for i in range(N):
        m = max(m, A[i])
        ans += m-A[i]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 33820
k = gets.to_i
s = 7
counter = 0
loop do
  if counter >= k
    puts '-1'
    break
  end
  if s % k == 0
    puts counter + 1
    break
  end

  counter += 1
  s *= 10 % k
  s %= k
  s += 7 % k
  s %= k
end

Measured memory_bytes: 14368
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;

  vector<int> a(n,1);
  map<int,bool> hold_red;

  hold_red[0] = true; 
  for(int i = 0;i < m;i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    if(hold_red[x] == true){
      hold_red[y] = true;    
    }
    a[x]--;
    a[y]++;
    if(a[x] == 0)hold_red[x] = false;
  }


  int ans = 0;
  for(auto p:hold_red)
    if(p.second)ans++;

  cout << ans << endl;

} 

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

    count = 0

    for i in range(1,n-1):
        if max(num_list[i-1],num_list[i],num_list[i+1]) != num_list[i]:
            if min(num_list[i-1],num_list[i],num_list[i+1]) != num_list[i]:
                count += 1

    print(count)

 
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<stdio.h>

int main(){
	int n,x,i,tmp=0;
	int l[100];
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
	}
	int ans=1;
	for(i=0;i<n;i++){
		tmp+=l[i];
		if(tmp<=x)ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
//B
/*==========================================================*/
/*    Template ver 2017-0401    |   Created by AVM.Martin   */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<algorithm>
#include<cmath>

#include<cstring>
#include<string>
#include<cctype>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>

typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::vector<int> vi;

const int OO=(int)2e9;
const ll INF=(ll)4e18;
const double EPS=(double)1e-12;

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define INL(i,a,b) ((a<=i)&&(i<=b))
#define EXL(i,a,b) ((a< i)&&(i< b))
#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
using namespace std;

int n,k,res;
int dat[55];

int main(){
	scanf("%d %d",&n,&k);
	REP(i,1,n)scanf("%d",dat+i);
	sort(dat+1,dat+1+n);
	res=0;
	REP(i,1,k)res+=dat[n-i+1];
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

#define EMP 0
#define OBS 1
#define WAL 4
#define STT 2
#define GOA 3

#define SUPmaxY 22
#define SUPmaxX 22

int maxY,maxX;
int field[SUPmaxX][SUPmaxY];
int startX,startY;
int result;


int dfs(int x, int y, int depth){
	//DEBUG(x);DEBUG(y);DEBUG(depth);
	if(depth>=result) return 0;
	
	FOR(di,0,4){
		int nx=x; int ny=y;
		int dx=DX[di]; int dy=DY[di];
		if(field[x+dx][y+dy]==OBS) continue;
		while(field[nx][ny]==EMP){
			nx+=dx;ny+=dy;
		}
		if(field[nx][ny]==WAL){continue;}
		if(field[nx][ny]==GOA){result=depth+1; return 0;}
		if(field[nx][ny]==OBS){
			field[nx][ny]=EMP;
			dfs(nx-dx,ny-dy,depth+1);
			field[nx][ny]=OBS;
		}
	}
	

}



int main(){
	while(true){
		cin>>maxY>>maxX;			if(!maxY) return 0;
		maxX+=2;maxY+=2;
		FOR(x,0,maxX) FOR(y,0,maxY) field[x][y]=WAL;
		FOR(x,1,maxX-1) FOR(y,1,maxY-1) cin>>field[x][y];
		FOR(x,1,maxX-1) FOR(y,1,maxY-1) if(field[x][y]==STT){startX=x;startY=y;field[x][y]=EMP;}

		result=11;
		dfs(startX,startY,0);
		cout<< ((result==11)?-1:result) <<endl;
	}
}

Measured memory_bytes: 1160
module Main where

import           Data.List
import           Control.Monad

main :: IO ()
main = do
    n    <- readLn
    list <- replicateM n getLine
    putStr
        $ if (length . nub) list
             == length list
             && (siritori ((head . head) list) list)
          then
              "Yes"
          else
              "No"
    return ()

siritori :: Char -> [String] -> Bool
siritori _    []       = True
siritori next (x : xs) = head x == next && siritori (last x) xs


Measured memory_bytes: 636
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

count = 0
for i in range(N):
    for j in range(i + 1, N):
        #2つ目の条件であるj - i ≠ k - jを満たさない数を求める
        #j - i = k - j の場合を調べる必要があるので、k = j + j - iとなる
        k = j + j - i
        if k >= N:
            break
        #2つ目の条件に合致しないことがi, j, k より明らかなので、1目の条件に合致しなければダメ
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            count += 1
#1つ目の条件に合致する総数はr * g * bなので、2つ目の条件に合致しない数を引けば答えとなる    
print((r * g * b) - count)

Measured memory_bytes: 9204
s = list(str(input()))
s.sort()
a = [chr(ord('a') + i) for i in range(26)]
b = {}
for i in a:
    b[i] = 0
for i in s:
    b[i] += 1

alf = ''
for i in a:
    if b[i] == 0:
        alf = i
        break
if alf:
    print(i)
else:
    print('None')

Measured memory_bytes: 10044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if(a > b)
    cout << 0 << endl;
  else if(n == 1 && a != b)
    cout << 0 << endl;
  else
    cout << a + b * (n - 1) - a * (n - 1) - b + 1 << endl;
}

Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
    int n, flag=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a%2==0){
            if(!(a%3==0||a%5==0)) flag =1;
        }
    }
    if(flag==1)cout << "DENIED\n";
    else cout << "APPROVED\n";
    return 0;
} 

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
L = sorted(X[::])

# 偶数この時のlen(L) // 2のとlen(L)-1のどちらかのみ中央値になる
len_X_first = len(X) // 2 - 1
len_X_second = len(X) // 2

for i in X:
    if (L[len_X_first] >= i):
        print(L[len_X_second])
    elif (L[len_X_second] <= i):
        print(L[len_X_first])


Measured memory_bytes: 30828
#include <iostream>
#include <vector>
#include <typeinfo>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin >> n;
    int k;
    k = 0;
    for(int i=0; i<1000; i++){
        if(i*(i+1)/2==n){
            k = i;
            break;
        }
    }
    if(k==0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        vector<vector<int>> d(k, vector<int>(k,0));
        cout << k+1 << endl;
        int count = 1;
        for(int i=0; i<k; i++){
            for(int j=0; j<i+1; j++){
                d[i][j] = count;
                count += 1;
            }
        }
        cout << k;
        for(int i=0; i<k; i++){
            cout << " " <<  d[i][0];
        }
        cout << endl;
        for(int i=0; i<k-1; i++){
            cout << k;
            for(int j=0; j<k; j++){
                if(i>=j){
                    cout << " " << d[i][j];
                }else{
                    cout << " " << d[j][i+1];
                }
            }
            cout << endl;
        }
        cout << k;
        for(int i=0; i<k; i++){
            cout << " " << d[k-1][i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer num = sc.nextInt();
      	Integer ItemA = sc.nextInt();
      	int sum = 0;
      	int out = ItemA;
      	for(int i = 1; i < num; i++){
       	Integer ItemB = sc.nextInt(); 
          if(out < ItemB){
            sum = sum + out;
            out = ItemB;
          } else{
            sum = sum + ItemB;
          }
        }
      	sum = sum + out / 2;
      	System.out.println(sum);
	}
}

Measured memory_bytes: 23252
main(i,j){
	char s[256];
	for(;~scanf("%s",s);){
		for(i=0;s[i];i++){
			if(s[i]=='@'){
				for(j=0;j<s[i+1]-'0';j++)putchar(s[i+2]);
				i+=2;
			}
			else	putchar(s[i]);
		}
		puts("");
	}
	exit(0);
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		StringBuilder sb = new StringBuilder(S);
		if(S.length() == 2) {
			System.out.println(S);
		}else {
			System.out.println(sb.reverse());
		}
	}
}

Measured memory_bytes: 23764
import std.stdio, std.string, std.conv;

void main() {
	readln;
	int[10][3][4] d;
	foreach (string l; lines(stdin)) {
		auto r = l.chomp.split.to!(int[]);
		d[r[0]-1][r[1]-1][r[2]-1] += r[3];
	}
	foreach (j; 0..4) {
		foreach (i; d[j]) {
			" %s".writefln(i.to!(string[]).join(" "));
		}
		if (j != 3) "####################".writeln;
	}
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

struct Line {
    int k, m;
    mutable int p;
    bool operator<(const Line& o) const {
        return k < o.k;
    }
    bool operator<(const int&x) const {
        return p < x;
    }
};
 
struct LineContainer : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const int inf = numeric_limits<int>::max();
    int div(int a, int b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(int k, int m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    int query(int x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,c;
    cin>>n>>c;
    int arr[n];
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }

    LineContainer lc;

    lc.add(2*arr[0], -arr[0]*arr[0]);
    for(int i=1;i<n;i++) {
        int hc = arr[i];
        int q = lc.query(arr[i]);
        int newcost = -q + hc*hc + c;
        lc.add(2*hc, -hc*hc-newcost);
    }

    cout<<-lc.query(arr[n-1])+arr[n-1]*arr[n-1]+c;

    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int64_t X, Y;
    cin >> X >> Y;
    if (X % Y == 0){
        cout << -1 << endl;
    }
    else {
        cout << X << endl;
    }
}




Measured memory_bytes: 256
N = int( input())
s = list()

for i in range(N):
  S = input()
  s.append(S)
  
M = int( input())
t = list()

for j in range(M):
  T = input()
  t.append(T)

  judge = 0
for l in range(N):
  money = s.count(s[l]) - t.count(s[l])
  
  if( judge < money):
    judge = money
  else:
    continue
    
print(judge)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B,M;
cin>>A>>B>>M;
vector<int> a(A),b(B),x(M),y(M),c(M);
rep(i,A)cin>>a[i];
rep(i,B)cin>>b[i];
rep(i,M){
    cin>>x[i]>>y[i]>>c[i];
    x[i]--,y[i]--;
}
vector<ll> cost;
rep(i,M){
    cost.pb(a[x[i]]+b[y[i]]-c[i]);
}

sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(cost.begin(),cost.end());
if(a[0]+b[0]<cost[0]){
    cout<<a[0]+b[0]<<endl;
}
else{
    cout<<cost[0]<<endl;
}

return 0;
}

Measured memory_bytes: 3448
/*

            Question ID-> 
                                       */
#include<bits/stdc++.h>
#include<cmath>
#include<cstring>
#include<climits>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define asc(a,n) sort(a,a+n);
#define dsc(a,n) sort(a,a+n,comp);
#define fo(i,x,y) for(int i=x;i<y;i++)
#define inarr(x) int n; cin>>n; int x[n]; fo(i,0,n){cin>>x[i];}
#define test int t; cin>>t; while(t--)
using namespace std;

int basic(){freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);return 0;}
bool comp(int a,int b){return a>b;}



int32_t main()
{// basic(); 
  fast; 
  int n; cin>>n; 
  string s; cin>>s;
  if(n>=s.length()){cout<<s;}
  else{fo(i,0,n){cout<<s[i];}cout<<"...";}

  return 0;
}










Measured memory_bytes: 3644
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=1e5+5;
ll dp[N],h[N],n,k;

int main(){FIN;
	cin>>n>>k;
	fore(x,0,n)cin>>h[x];
	for(int x=n-2; x>=0; x--){
		dp[x] = 1LL<<60;
		for(int i=1; i<=k && i+x<n; i++)
			dp[x]=min(dp[x],dp[x+i]+abs(h[x]-h[x+i]));	
	}
	cout<<dp[0]<<"\n";
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ( (A+B) > (C+D) ) {
    cout << "Left" << endl;
  }
  if ( (A+B) == (C+D) ) {
    cout << "Balanced" << endl;
  }
  else if ( (A+B) < (C+D) ) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

bool palin(string s) {
  string t(s.rbegin(), s.rend());
  return s == t;
}

void solve(std::string s) {
  int n = s.size();
  if (palin(s) and palin(s.substr(0, (n - 1) / 2)) and
      palin(s.substr(((n + 3) / 2) - 1))) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) scanf("%lld", &a[i]);
    ll mi = 2, ma = 2;
    FORR(i,n-1,0){
        ll x = (mi + a[i] - 1) / a[i];
        ll y = ma / a[i];
        if (x > y){
            cout << -1 << endl;
            return 0;
        }
        mi = x * a[i];
        ma = y * a[i] + a[i] - 1;
    }
    cout << mi << " " << ma << endl;
    return 0;
}


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

typedef long long int ll;

int main(void) {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    for(int i=0; i<100; i++){
        A -= D;
        C -= B;
        if(C<=0){
            cout << "Yes";
            break;
        }else if(A<=0){
            cout << "No";
            break;
        }
    }
}


Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll X; cin >> X;
    ll now = 100;
    ll ans = 0;
    while(true){
        if(now >= X){
            break;
        }
        now = (ll)(now * 1.01);
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
int N,ans,fans,i,j;
string s;
//main
signed main(){
  cin>>N>>s;
  for(int k=1;k<N;k++){
    ans=i=0;j=k;
    while(j<N){
      if(s[i++]==s[j++])ans++;
      else ans=0;
      if(ans>k)ans=0;
      fans=max(ans,fans);
    }
  }
  fin(fans);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n>>m;
    vint x(m);
    rep(i, m){
        cin>>x[i];
    }
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    sort(all(x));
    vint aid;
    ll sum = 0;
    rep(i, m-1){
        aid.push_back(x[i+1]-x[i]);
        sum += x[i+1]-x[i];
    }
    sort(all(aid), greater<int>());
    ll rem = 0;
    rep(i, n-1){
        rem += aid[i];
    }
    cout << sum - rem << endl;
    return 0;
}


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll n,i,j;
	string s;
	ump<string , ll>mp;
	cin >> n;
	rep(i,0,n){
		cin >> s;
		mp[s]++;
	}
	ll ma = 1;
	for(auto x : mp)ma = max(ma,x.ss);
	set<string>se;
	for(auto x : mp){
		if(x.ss == ma)se.insert(x.ff);
	}    
	for(auto x : se)cout << x << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 33276
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[110];
    int N,A,ans;
    cin >> N >> A;
    ans=0;
    for(int i=0;i<N;i++)
    {
        cin >> arr[i];
        if(arr[i]>A/2)
        {
            ans+=A-arr[i];
        }
        else ans+=arr[i];
    }
    cout << ans*2 << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

// #define OJ
#define pb push_back
#define F first
#define S second

#define WLL(t) while(t--)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define STF(i, a, b) for(size_t i = a; i < b; i++)
#define RFOR(i, a, b) for(int i = a; i >= b; i--)
#define SRF(i, a, b) for(size_t i = a;i >= b;i--)

#define ALL(v) v.begin(),v.end()
#define PRECISION(x) cout<<fixed<<setprecision(x)
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define MOD 1000000007

#define TO(v, type) static_cast<type>(v)

void solve(int row[], int n);
int main()
{
#ifdef OJ
	READ;
	WRITE;
#endif

	FASTIO;
	int n{};
	cin >> n;
	int row[n];
	FOR(i, 0, n) {
		cin >> row[i];
	}
	solve(row, n);
	return 0;
}
void solve(int row[], int n)
{
	int mx = row[0];
	ll count{};
	FOR(i, 0, n) {
		mx = max(row[i], mx);
		count += mx - row[i];
	}
	cout << count << "\n";
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n;cin >> n;
    string s;cin >> s;
    for (int i = 0; i < s.length(); i++) {
        s[i] = (s[i] - 'A' + n)%26 + 'A';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
#define BIT(S,i) ((S&(1ll<<i))>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;}
constexpr long long INF = 1e18;

// ローリングハッシュ
// 二分探索で LCP を求める機能つき
struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<long long> hash1, hash2, power1, power2;

	// construct
	RollingHash(const string &S) {
		int n = (int)S.size();
		hash1.assign(n+1, 0);
		hash2.assign(n+1, 0);
		power1.assign(n+1, 1);
		power2.assign(n+1, 1);
		for (int i = 0; i < n; ++i) {
			hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
			power1[i+1] = (power1[i] * base1) % mod1;
			power2[i+1] = (power2[i] * base2) % mod2;
		}
	}
	
	// get hash of S[left:right]
	inline pair<long long, long long> get(int l, int r) const {
		long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
		if (res1 < 0) res1 += mod1;
		long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
		if (res2 < 0) res2 += mod2;
		return {res1, res2};
	}

	// get lcp of S[a:] and T[b:]
	inline int getLCP(int a, int b) const {
		int len = min((int)hash1.size()-a, (int)hash1.size()-b);
		int low = 0, high = len;
		while (high - low > 1) {
			int mid = (low + high) >> 1;
			if (get(a, a+mid) != get(b, b+mid)) high = mid;
			else low = mid;
		}
		return low;
	}
};
struct UF{
	vector<int>par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		sz[x]+=sz[y];
		par[y]=x;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

signed main(){
	string s,t;
	cin>>s>>t;
	int N = s.size();
	s+=s;
	while(s.size()<t.size()*2)s+=s;
	RollingHash rhs(s),rht(t);
	UF uf;
	uf.init(N);
	REP(i,N){
		if(rhs.get(i,i+t.size())==rht.get(0,t.size())){
			if(uf.same(i,(i+t.size())%N)){
				cout<<-1<<endl;
				return 0;
			}else{
				uf.unite(i,(i+t.size())%N);
			}
		}
	}
	int ans = 0;
	REP(i,N){
		CHMAX(ans,uf.size(i));
	}
	cout<<ans-1<<endl;
}

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

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

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            List<Integer> b = new LinkedList<>();
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0)
                    b.add(a[i]);
                else
                    b.add(0, a[i]);
            }
            Integer[] s = new Integer[n];
            b.toArray(s);
            if (n % 2 != 0) {
                for (int i = n - 1; i >= 0; i--) {
                    out.print(s[i] + " ");
                }
                return;
            }
            for (int i : b) {
                out.print(i + " ");
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream i) {
            br = new BufferedReader(new
                    InputStreamReader(i));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n;
pair<int,int> pt[maxn];

int sim(pair<int,int> p) {
    int res = 0;
    set<pair<int,int>> act;
    for (int i=0; i<n; i++) {
	act.insert(pt[i]);
    }

    while (act.size()) {
	res++;
	auto cur = *act.begin();
	act.erase(act.begin());
	while (1) {
	    cur.first += p.first;
	    cur.second += p.second;
	    if (act.count(cur)) {
		act.erase(cur);
	    } else {
		break;
	    }
	}
    }

    return res;
}

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

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

    set<pair<int,int>> st;
    
    for (int i=0; i<n; i++) {
	for (int j=0; j<n; j++) {
	    if (i==j) continue;
	    int dx=pt[j].first-pt[i].first;
	    int dy=pt[j].second-pt[i].second;
	    st.insert({dx,dy});
	}
    }

    int ans = n;
    for (auto p: st) {
	ans = min(ans, sim(p));
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3704
N=int(input())
s=[]
t=[]
ans=0
for j in range(N):
    a=list(input())
    s+=a[0]
for k in "MARCH":
    t.append(s.count(k))
for ii in range(32):
    u=[]
    for jj in range(5):
        if ii&(1<<jj):
            u.append(t[jj])
    if len(u)==3:
        ans+=u[0]*u[1]*u[2]
print(ans)        

Measured memory_bytes: 3864
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_H = 85;
const ll MAX_W = 85;
const ll MAX_M = (MAX_H + MAX_W)*80;

bool dp[MAX_H][MAX_W][MAX_M];  // dp[i][j][k] : (i,j)(i,jは0-index)での偏りがkになるならtrue

int main() {
    ll h, w;
    cin >> h >> w;

    vvl a(MAX_H, vl(MAX_W));
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }
    }
    vvl b(MAX_H, vl(MAX_W));
    rep(i, h) {
        rep(j, w) {
            cin >> b[i][j];
        }
    }

    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    rep(i, h) {
        rep(j, w) {
            ll x = abs(a[i+1][j] - b[i+1][j]);
            ll y = abs(a[i][j+1] - b[i][j+1]);
            rep(k, MAX_M) {
                if(i < h-1 && dp[i][j][k]) {
                    dp[i+1][j][k + x] = true;
                    dp[i+1][j][abs(k - x)] = true;
                }
                if(j < w-1 && dp[i][j][k]) {
                    dp[i][j+1][k + y] = true;
                    dp[i][j+1][abs(k - y)] = true;
                }
            }
        }
    }

    rep(k, MAX_M) {
        if(dp[h-1][w-1][k]) {
            out(k);
            re0;
        }
    }
    
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N, T;
    cin >> N >> T;
    int in;
    vector<int> t;
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        t.emplace_back(in);
    }
    
    long long sum = 0;
    for (int i = 1; i < N; i++)
    {
        if (t[i] - t[i - 1] > T)
        {
            sum += T;
        }else
        {
            sum += t[i] - t[i - 1];
        }
        
    }
    sum += T;

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd_ll(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
ll fiv(ll n){
  if(n==0){
    return 1;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  string s;
  cin>>s;
  bool ok =true;
  rep(i,s.size()){
    if(i%2 ==0 && s[i] !='h' ) ok=false;
    else if(i%2 ==1 && s[i] != 'i') ok =false;
  }
  if(ok && s.size() %2 ==0) cout<< "Yes"<<endl;
  else cout<<"No"<<endl;
}





Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  string c;
  cin >> c;
  if(c =="a"){
      cout  << "vowel" << endl; 
  }
  else if(c =="i"){
      cout << "vowel" << endl;
  }
  else if(c =="u"){
      cout << "vowel" << endl;
  }
  else if(c =="e"){
      cout << "vowel" << endl;
  }
  else if(c =="o"){
      cout << "vowel" << endl;
  }
  else{
      cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	ll N, M;
	cin >> N >> M;

	ll A[MAX] = {};

	repn(i, N) {
		ll a;
		cin >> a;
		A[i] = A[i - 1] + a;
	}

	map<ll, ll> mp;

	rep(i, N+1) {
		mp[A[i]%M]++;
	}

	ll ans = 0;

	for (auto x : mp) {
		ll y = x.second;
		ans += y * (y - 1) / 2;
	}

	cout << ans;
	system("PAUSE");
}

Measured memory_bytes: 12280
MOD = 1000000007

N = int(input())
C = [int(input()) for _ in range(N)]

prev = [None for _ in range(max(C)+1)]
dp = [0 for _ in range(N+1)]
dp[0] = 1

for i in range(N):
    if prev[C[i]] is None or prev[C[i]]==i:
        dp[i+1] = dp[i]
    else:
        dp[i+1] = dp[i] + dp[prev[C[i]]]
    dp[i+1] %= MOD
    prev[C[i]] = i+1
    
print(dp[N])

Measured memory_bytes: 20524
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
string s,p,x;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    long long t,i,j,n,m,l,r,k,c,ans=0;
    cin>>s>>p>>n>>m>>x;
    if(s==x)
    {
        n--;
    }
    if(p==x)
    {
        m--;
    }
    cout<<n<<" "<<m<<"\n";
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	long long v[n+10];
	for(int i=0;i<n;i++)
	cin>>v[i];
	sort(v,v+n);
	multiset<long long> ssi;
	for(int i=0;i<n;i++)
	{
	    ssi.insert(v[i]);
	}
	int res=0;
	while(!ssi.empty())
	{
	    long long x=*ssi.rbegin();
	   
	   while (!ssi.empty()) {
		long long x = *ssi.rbegin();
		ssi.erase(ssi.find(x));
		long long now = 1;
		while (now <= x)
			now *= 2;
		auto it = ssi.find(now - x);
		if (it == ssi.end())
			continue;
		ssi.erase(it);
		++res;
	}
	}
	cout<<res<<'\n';
	return 0;
}


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

int table[ 8 ][ 8 ] = {
	{ 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 300, 500, 600, 700, 1350, 1650 },
	{ 0, 6, 0, 350, 450, 600, 1150, 1500 },
	{ 0, 13, 7, 0, 250, 400, 1000, 1350 },
	{ 0, 18, 12, 5, 0, 250, 850, 1300 },
	{ 0, 23, 17, 10, 5, 0, 600, 1150 },
	{ 0, 43, 37, 30, 25, 20, 0, 500 },
	{ 0, 58, 52, 45, 40, 35, 15, 0 }
};

int main()
{
	int s, e;
	int sh, sm, eh, em;
	while( cin >> s && s ){
		cin >> sh >> sm;
		cin >> e;
		cin >> eh >> em;

		int st = sh * 100 + sm;
		int et = eh * 100 + em;
		if( s > e ){
			int t = s;
			s = e;
			e = t;
		}
		int cost = table[ s ][ e ];
		if( ( ( st >= 1730 && st <= 1930 ) || ( et >= 1730 && et <= 1930 ) )
			&& ( table[ e ][ s ] <= 40 ) ){
			cost = static_cast<int>( ( ( cost / 100.0 ) + 0.9 ) ) * 50;
		}

		cout << cost << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
//author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int N = 1e5 + 10;
const int M = 1e9 + 7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}




void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	swap(a,b); swap(a,c);
	cout << a << " " << b << " " << c << endl;
}

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

	int t = 1;
    //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void) {
	char moji;
	
	while(1){
		scanf("%c",&moji);
		if(moji >=65 && moji <=90)
		{
			printf("%c",moji+32);
		}
		else if(moji>=97 && moji <=122)
		{
			printf("%c",moji-32);
		}
		else printf("%c",moji);
		
		if(moji == '\n') break;
	}
	
	
	return 0;
}

Measured memory_bytes: 1852
import scala.io.StdIn.readInt

object Main {

  def scan(sum:Int,i:Int):Int = {
    if(i==0) sum
    else {
      val n = readInt
      scan(sum+n,i-1)
    }
  }

  def main(args:Array[String]) = {
    val buf = Iterator.continually(readInt).takeWhile(_ != 0).map { n=>
      scan(0,n/4)
    }
    println(buf.mkString("\n"))
  }
}

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

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

    string s;
    cin >> s;

    int i=0, ans=0;

    while (i<n-2) {
        if (s.at(i) == 'A') {
            if (s.at(i+1) == 'B') {
                if (s.at(i+2) == 'C') ans++;
            }
        }

        i++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10**9+7
# dp[i][j] := Sの後ろからi桁を13で割った余りがjとなるようなものの個数
S = input()
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
mul = 1  
for i in range(len(S)):
    x = S[-(i+1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= MOD
    else:
        k = int(x) # これしか選ぶ余地なし
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= MOD
    mul = mul * 10 % 13
print(dp[len(S)][5])


Measured memory_bytes: 62300