akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

int main() {
	ll n;
	cin >> n;
	map<ll, ll> D;
	for (ll i = 0; i < n; i++) {
		ll a;
		cin >> a;
		D[a]++;
	}
	ll res = 0;
	for (auto i : D) {
		if (i.second % 2) {
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    string s; cin >> s;
    bool odd = true, even = true;
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0 && s[i] == 'L'){
            odd = false;
        }
        if(i % 2 != 0 && s[i] == 'R'){
            even = false;
        }

        if(odd == false || even == false){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

signed main()
{
	int N;
	cin >> N;

	if (N == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	int cur = 0;
	int ans[100] = {};

	if (N > 0)
	{
		int cur = 0;
		int a = 0;
		while (true)
		{
			ans[a] = 1;
			cur += pow(-2, a);
			if (cur >= N)
			{
				break;
			}
			a += 2;
		}

		for (int i = a; i >= 0; i--)
		{
			if (cur == N) break;

			int k = pow(-2, i);
			if (k > 0)
			{
				if (cur - k >= N)
				{
					cur -= k;
					ans[i] = 0;
				}
			}
			else
			{
				if (cur + k >= N)
				{
					cur += k;
					ans[i] = 1;
				}
			}
		}
	}
	else
	{
		int cur = 0;
		int a = 1;
		while (true)
		{
			ans[a] = 1;
			cur += pow(-2, a);
			if (cur <= N)
			{
				break;
			}
			a += 2;
		}

		for (int i = a; i >= 0; i--)
		{
			if (cur == N) break;

			int k = pow(-2, i);
			if (k > 0)
			{
				if (cur + k <= N)
				{
					cur += k;
					ans[i] = 1;
				}
			}
			else
			{
				if (cur - k <= N)
				{
					cur -= k;
					ans[i] = 0;
				}
			}
		}
	}



	bool flg = false;
	for (int i = 99; i >= 0; i--)
	{
		if (ans[i] == 1)
		{
			flg = true;
		}
		if (flg)
		{
			cout << ans[i];
		}
	}
	cout << endl;
}







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

int main(){
  
  int n, q, k;
  
  cin >> n;
  vector<int> A(n);
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> k;
    cout << distance(A.begin(), lower_bound(A.begin(), A.end(), k)) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3132
import Control.Applicative

readInts :: IO [Int]
readInts = map read . words <$> getLine

f :: [Int] -> Int -> Int
f [] b = 0
f (a:ax) b = if a >= b then f ax a else f ax b + b - a


main :: IO ()
main = do
    n <- readLn :: IO Int
    a <- readInts
    print $ f a 0

Measured memory_bytes: 64232
//コピペ提出理解はした

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define ll long long

int main() {
    int d;
    cin >> d;
    vector<vector<int>> s(d+1, vector<int>(26+1, 0));
    vector<int> c(26+1);
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    /////////////////
    vector<int> t(d);
    for(int i = 0; i < d; i++) {
        t[i] = i+1;
    }
    for(int i = 0; i < d; i++) cin >> t[i];

    ///////////////
    int m;
    cin >> m;
    vector<pair<int, int>> dq(m);
    for(int i = 0; i < m; i++) {
        cin >> dq[i].first >> dq[i].second;
    }
    vector<ll> ans(d, 0);
    ll v = 0;
    ll tmp = 0;
    map<ll, int> mp;
    priority_queue<ll> que;
    int num = 0;
    for(int k = 0; k < m; k++) {
        tmp = t[dq[k].first-1];
        t[dq[k].first-1] = dq[k].second; 
        vector<ll> last(26+1, 0);
        for(int i = 0; i < d; i++) {
            v += s[i][t[i]-1];
            last[t[i]-1] = i+1;
            for(int j = 0; j < 26; j++) {
                v -= c[j]*((i+1)-last[j]);
            }    
        }
        cout << v << endl;
        que.push(v);
        mp[v] = k;
        v = 0;
    }
    return 0;
}


Measured memory_bytes: 10836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 0x1fffffffffffffff;
template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }

struct SegmentTree{
  ll size = 1;
  vector<ll> data;
  SegmentTree(ll n){
    while(size < n) size *= 2;
    data.assign(size * 2, LINF);
  }
  void update(ll at){
    while(at /= 2) data[at] = min(data[at * 2], data[at * 2 + 1]);
  }
  void set(ll at, ll val){
    at += size;
    data[at] = val;
    update(at);
  }
  ll get(ll l, ll r){
    l += size; r += size;
    ll ans = LINF;
    while(l < r){
      if(l & 1) chmin(ans, data[l++]);
      if(r & 1) chmin(ans, data[--r]);
      l /= 2; r /= 2;
    }
    return ans;
  }
  ll operator[](ll at){ return data[at + size]; }
  void _chmin(ll at, ll val){
    at += size;
    if(chmin(data[at], val)) update(at);
  }
};

int main(){
  ll n, m;
  cin >> n >> m;
  vector<array<ll, 3>> a(m);
  for(auto& i : a) for(auto& j : i) cin >> j;
  sort(a.begin(), a.end(), [](auto& a, auto& b){ return a[1] < b[1]; });
  SegmentTree seg(n);
  seg.set(0, 0);
  for(auto i : a){
    i[0]--; i[1]--;
    seg._chmin(i[1], seg.get(i[0], i[1]) + i[2]);
  }
  if(seg[n - 1] == LINF) return puts("-1") & 0;
  cout << seg[n - 1] << endl;
}


Measured memory_bytes: 4608
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

const int64_t kMod = 1000000007LL;
// const int64_t kMod = 998244353LL;
struct Mint {
  int64_t value;
  Mint(int64_t value = 0LL) : value((value % kMod + kMod) % kMod) {}
  Mint operator-() const {
    return Mint(-value);
  }
  Mint &operator+=(const Mint rhs) {
    if ((value += rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator-=(const Mint rhs) {
    if ((value += kMod - rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator*=(const Mint rhs) {
    (value *= rhs.value) %= kMod;
    return *this;
  }
  Mint operator+(const Mint rhs) const {
    return Mint(*this) += rhs;
  }
  Mint operator-(const Mint rhs) const {
    return Mint(*this) -= rhs;
  }
  Mint operator*(const Mint rhs) const {
    return Mint(*this) *= rhs;
  }
  Mint Pow(int64_t p) const {
    if (p == 0LL) {
      return 1LL;
    } else if (p < 0LL) {
      return Pow(-p).Pow(kMod - 2LL);
    }
    Mint temp = Pow(p >> 1LL);
    temp *= temp;
    if (p & 1LL) {
      temp *= (*this);
    }
    return temp;
  }
  Mint Inv() const {
    return Pow(kMod - 2LL);
  }
  Mint &operator/=(const Mint a) {
    return *this *= a.Inv();
  }
  Mint operator/(const Mint a) const {
    return Mint(*this) /= a;
  }
};

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

  int64_t N;
  cin >> N;
  Mint result = Mint(10).Pow(N) - (Mint(9).Pow(N)) * 2 + (Mint(8).Pow(N));
  cout << result.value << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main()   {
  string s, t;
  cin >> s >> t;
  int ans = 0;
for (int i = 0; i < 3; i++)  {
  if (s[i] == t[i] ) {
    ++ans;
  }
}
cout << ans <<endl;
      }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main(){
    int N; cin >> N;
    vector<ll> X(N);
    rep(i,N) cin >> X[i];
    vector<ll> X2 = X;
    sort(X.begin(), X.end());
    int mid = N/2;

    rep(i,N){
        if (X2[i] < X[mid]){
            cout << X[mid] << endl;
        }
        else{
            cout << X[mid-1] << endl;
        }
    }
}

Measured memory_bytes: 6272
#include <stdio.h>

int main() {
  int N, i, j, k;
  int data[200][3]; 
  int point[200] = {0};
  scanf( "%d", &N );
  for( i = 0; i < N; i++ ) {
    for( j = 0; j < 3; j++ ) {
      scanf( "%d", &data[i][j] );
    }
  }
  for( i = 0; i < 3; i++ ) {
    for( j = 0; j < N; j++ ) {
      for( k = 0; k < N; k++ ) {
        if( data[j][i] == data[k][i] && j != k ) {
          break;
        }
      }
      if( data[j][i] != data[k][i] && j != k) {
        point[j] += data[j][i];
      }
    }
  }
  for( i = 0; i < N; i++ ) {
    printf( "%d\n", point[i] );
  }
  return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
   
  int k,x;
  cin>>k>>x;
  int s=0;
  while(k--)
  {
  	
  	s=s+500;

  }
  
  if(s>=x){
  	
  	cout<<"Yes"<<endl;
  		
  }
  
  else{
  	
  	cout<<"No"<<endl;
  	
  }

  return 0;
}

Measured memory_bytes: 3616
import Data.List

main = do
    sn <- getLine
    ods <- getContents
    let dices = map genDice $ lines ods
    if isAllDistinct dices
        then putStrLn "Yes"
        else putStrLn "No"

type Dice = (Int, Int, Int, Int, Int, Int)

isAllDistinct :: [Dice] -> Bool
isAllDistinct [] = True
isAllDistinct [x] = True
isAllDistinct (x:xs)
  | or $ map (isIdentical x) xs = False
  | otherwise = isAllDistinct xs

genDice :: String -> Dice
genDice l = (n1,n2,n3,n4,n5,n6)
  where (n1:n2:n3:n4:n5:n6:_) = map (\x -> read x :: Int) $ words l

isIdentical :: Dice -> Dice -> Bool
isIdentical (d11,d12,d13,d14,d15,d16) (d21,d22,d23,d24,d25,d26) = isSameNums && match123 && match645 && match154 && match16 && match25 && match34
  where
    isSameNums = (sort [d11,d12,d13,d14,d15,d16]) == (sort [d21,d22,d23,d24,d25,d26])
    d2 = (d21,d22,d23,d24,d25,d26)
    match123 = getRight d2 d11 d12 == Just d13
    match645 = getRight d2 d16 d14 == Just d15
    match154 = getRight d2 d11 d15 == Just d14
    match16  = getBottom d2 d11 == Just d16
    match25  = getBottom d2 d12 == Just d15
    match34  = getBottom d2 d13 == Just d14

sides :: Dice -> Int -> [Int]
sides (n1,n2,n3,n4,n5,n6) top
  | top == n1 = [n2,n3,n5,n4,n2]
  | top == n2 = [n1,n4,n6,n3,n1]
  | top == n3 = [n1,n2,n6,n5,n1]
  | top == n4 = [n1,n5,n6,n2,n1]
  | top == n5 = [n1,n3,n6,n4,n1]
  | top == n6 = [n2,n4,n5,n3,n2]
  | otherwise = sides (n1,n2,n3,n4,n5,n6) n1 -- NOT EXPECTED CASE

getRight :: Dice -> Int -> Int -> Maybe Int
getRight dice top front = next (sides dice top) front

next :: [Int] -> Int -> Maybe Int
next [x] _ = Nothing
next (x:xs) y
  | x == y    = Just (head xs)
  | otherwise = next xs y

getBottom :: Dice -> Int -> Maybe Int
getBottom (n1,n2,n3,n4,n5,n6) top
  | n1 == top = Just n6
  | n2 == top = Just n5
  | n3 == top = Just n4
  | n4 == top = Just n3
  | n5 == top = Just n2
  | n6 == top = Just n1
  | otherwise = Nothing


Measured memory_bytes: 4172
#include<stdio.h>
#include<math.h>
int main()
{
    long long int a,ans;
    float b;
    int c;
    scanf("%lld %f",&a,&b);
    c=round(b*100.0);
    ans=(a*c)/100;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2200
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<ll, ll>
#define PLL pair<ll, ll>
#define PLI pair<ll, ll>
#define PIL pair<ll, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m;
ll p[5010];
ll val[5010];
ll res=-1e18;
bool vis[5010];
vector< pair<vector<ll>, ll> > v;
int main()
{
	cin >>n>>m;
	for (ll i=0;i<n;i++) cin >>p[i],p[i]--;
	for (ll i=0;i<n;i++) cin >>val[i];
	for (ll i=0;i<n;i++)
	{
		if (vis[i]) continue;
		ll t=i;
		ll sm=0;
		vector<ll> vt;
		while (!vis[t])
		{
			vis[t]=1;
			sm+=val[t];
			vt.push_back(t);
			t=p[t];
			//cout <<t<<" ######\n";
		}
		v.push_back(MP(vt,sm));
		//for (ll j=0;j<vt.size();j++) cout <<vt[j]<<" ";
		//cout <<"\n";
		//cout <<sm<<" ##\n";
	}
	for (ll i=0;i<v.size();i++)
	{
		vector<ll> vt=v[i].Fst;
		ll r=-1e18;
		if (v[i].Snd<=0)
		{
			for (ll j=0;j<vt.size();j++)
			{
				ll rt=0;
				for (ll k=1;k<=vt.size();k++)
				{
					rt+=val[vt[(j+k-1)%(ll)(vt.size())]];
					r=max(r,rt);
				}
			}
		}
		else
		{
			r=(m/(ll)(vt.size()))*v[i].Snd;
			ll mi=m%(ll)(vt.size());
			if (!mi) mi=(ll)(vt.size()),r-=v[i].Snd;
			ll rpl=-1e18;
			//cout <<r<<" "<<mi<<" "<<vt.size()<<" #######\n";
			for (ll j=0;j<vt.size();j++)
			{
				ll rt=0;
				if (m-mi!=0) rpl=max(rpl,rt);
				for (ll k=1;k<=min((ll)vt.size(),mi);k++)
				{
					rt+=val[vt[(j+k-1)%(ll)(vt.size())]];
					rpl=max(rpl,rt);
				}
				//cout <<j<<" "<<rpl<<" ##\n";
			}
			r+=rpl;
		}
		res=max(res,r);
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 3772
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)

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

def main():
    n = int(input())
    la = list(map(int, input().split()))

    c = Counter(la)
    for i in range(1, n+1):
        print(c[i])

if __name__ == '__main__':
    main()



Measured memory_bytes: 34856
#include<iostream>
#include<cstdio>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int D[1000][1000];
  
int main(){
  scanf("%d",&n);
  int u,k,C,V;
   for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = INF;
   
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
 
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
 
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  
  
  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MOD = 1000000007;
const int MN = 5010;

int dp[MN][MN];
int N;
string s;

inline void add(int &x, int y)
{
    x += y;
    if (x > MOD) x -= MOD;
}

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

    dp[0][0] = 1;

    rep(i, N) {
    	rep(j, MN) if (dp[i][j] != 0) {
    		if (j) {
    			add(dp[i+1][j-1], dp[i][j]);
    		} else {
    			add(dp[i+1][j], dp[i][j]);
    		}

    		add(dp[i+1][j+1], dp[i][j] * 2);
    	}
    }

    int t = dp[N][s.size()];
    rep(i, s.size()) {
    	t = (ll)(MOD + 1) / 2 * t % MOD;
    }
    cout << t << endl;
    
    return 0;
}

Measured memory_bytes: 96512
program xmas2(input,output);
var n,i,p,pm,k:integer;
begin
  readln(n); k:=0;
  for i:=1 to n do begin
    readln(p);
    if i=1 then pm:=p
    else if p>pm then pm:=p;
    k:=k+p;
  end;
  k:=k - (pm div 2);
  writeln(k)
end.


Measured memory_bytes: 128
import sys
argVec = sys.argv
if len(argVec) > 1:
    GBN_DEBUG = True
else:
    GBN_DEBUG = False

#S = input()
N = int(input())
#S, T = input().split() 
#N, M = map(int, input().split()) 
#W = [input() for _ in range(N)]
A = list(map(int, input().split()))

def dprn(s, i):
    if GBN_DEBUG:
        print(", " + s + " = " + str(i), end = "")

def dprns(s):
    if GBN_DEBUG:
        print(", " + s, end = "")

def dprni(i):
    if GBN_DEBUG:
        print(str(i), end=" ")

def puts(s):
    print(s)

def puti(i):
    print(str(i))

A.sort(reverse = 1)

if sum(A) - A[0] > A[0]:
    puts('Yes')
else:
    puts('No')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAXN=1005;
int n;
vector<int> m[MAXN*MAXN];
int d[MAXN*MAXN];
int a[MAXN][MAXN];
int v[MAXN*MAXN];
bool vis[MAXN*MAXN];
queue<int> q;
int cnt=0;
int ans=0;

int main()

{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;i++){
		int last=0;
		for (int j=1;j<n;j++){
			cin>>a[i][j];
			int tmp1=min(i,a[i][j]);
			int tmp2=max(i,a[i][j]);
			int num=tmp1*(n+1)+tmp2;
			if (!vis[num]){
				vis[num]=true;
				v[++cnt]=num;
			}
			if (j>1){
				//cout<<"qaq"<<last<<" "<<num<<endl;
				m[last].push_back(num);
				d[num]++;
			}
			last=num;
		}
	}

	queue<int> c;
	for (int i=1;i<=cnt;i++){
		if (d[v[i]]==0){
			q.push(v[i]);
			c.push(1);
		}
	}

	while (!q.empty()){
		ans=max(ans,c.front());
		cnt--;
		int now=q.front();
		q.pop();
		//cout<<"yyy"<<now<<" "<<c.front()<<endl;
		for (int i=0;i<m[now].size();i++){
			int p=m[now][i];
			d[p]--;
			if (d[p]==0){
				q.push(p);
				c.push(c.front()+1);
			}
		}
		c.pop();
	}

	if (cnt>0){
		cout<<-1<<endl;
		return 0;
	}

	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 52352
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
using namespace std;
//template

//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  set<int> pl,mi,ze;
  int pp,mm,zz;
  for(int i=0;i<N;i++)if(v[i]>0){pl.insert(i);pp=i;}
  for(int i=0;i<N;i++)if(v[i]<0){mi.insert(i);mm=i;}
  for(int i=0;i<N;i++)if(v[i]==0){ze.insert(i);zz=i;}
  bool z=ze.size(),p=pl.size(),m=mi.size();
  int ans=0;
  for(int i=0;i<N;i++)ans+=abs(v[i]);
  if(z&&p){
    cout<<ans<<endl;
    int pn=v[pp];int zn=v[zz];
    for(int i=0;i<N;i++){
      if(i==pp||i==zz)continue;
      if(v[i]<=0){cout<<pn<<" "<<v[i]<<endl;pn-=v[i];}
      else {cout<<zn<<" "<<v[i]<<endl;zn-=v[i];}
    }
    cout<<pn<<" "<<zn<<endl;
  }
  else if(z&&m){
    cout<<ans<<endl;
    int mn=v[mm];int zn=v[zz];
    for(int i=0;i<N;i++){
      if(i==mm||i==zz)continue;
      if(v[i]>=0){cout<<mn<<" "<<v[i]<<endl;mn-=v[i];}
      else {cout<<zn<<" "<<v[i]<<endl;zn-=v[i];}
    }
    cout<<zn<<" "<<mn<<endl;
  }
  else if(m&&p){
    cout<<ans<<endl;
    int pn=v[pp];int mn=v[mm];
    for(int i=0;i<N;i++){
      if(i==mm||i==pp)continue;
      if(v[i]>=0){cout<<mn<<" "<<v[i]<<endl;mn-=v[i];}
      else {cout<<pn<<" "<<v[i]<<endl;pn-=v[i];}
    }
    cout<<pn<<" "<<mn<<endl;
  }
  else if(ze.size()>=2){
    int ze2=0;
    for(int i=0;i<N;i++){if(v[i]==0){ze2=i;break;}}
    cout<<ans<<endl;
    int zn=v[zz];int zn2=v[ze2];
    for(int i=0;i<N;i++){
      if(i==zz||i==ze2)continue;
      if(v[i]>=0){cout<<zn<<" "<<v[i]<<endl;zn-=v[i];}
      else {cout<<zn2<<" "<<v[i]<<endl;zn2-=v[i];}
    }
    cout<<zn2<<" "<<zn<<endl;
  }
  else if(p){
    int kk=0;int oo=INF;
    for(int i=0;i<N;i++)if(oo>v[i]){kk=i;oo=v[i];}
    cout<<ans-2*oo<<endl;
    int aa=0;if(kk==0)aa++;
    int an=v[aa];int kn=v[kk];
    for(int i=0;i<N;i++){
      if(i==aa||i==kk)continue;
      cout<<kn<<" "<<v[i]<<endl;kn-=v[i];
    }
    cout<<an<<" "<<kn<<endl;
  }
  else{
    int kk=0;int oo=-INF;
    for(int i=0;i<N;i++)if(oo<v[i]){kk=i;oo=v[i];}
    cout<<ans+2*oo<<endl;
    int kn=v[kk];
    for(int i=0;i<N;i++){
      if(i==kk)continue;
      cout<<kn<<" "<<v[i]<<endl;kn-=v[i];
    }
  }
}


Measured memory_bytes: 7424
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{

	int i, n, x;

	i = 2;

	cin >> n;

	while (1) {
		i++;
		x = i;
		if (x > n) break; 
		if (x % 3 == 0) {
			cout << " " << i;
			continue;
		}
		while(1) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
			if (x == 0) break; 
		}
	}
	cout << endl;
	

	return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n,m,total=0;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        total+=a[i];
    }
    sort(a.begin(),a.end());
    int x=(total-1)/(4*m);
    cout << (x<a[n-m]?"Yes":"No") << endl;

    return 0;
}




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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  int m = max({a, b, c});
  int n = 3 * m - a - b - c;
  if (n % 2 == 0)
    cout << n / 2 << '\n';
  else
    cout << (n + 3) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
  
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
 
template <class X> void print(X Target){ cout << Target << '\n'; }

const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int w, h;
int xs, ys, xg, yg;
int mp[128][128];
bool field[128][128];

void dfs(int y, int x, int color)
{
  if (x < 1 || x > w || y < 1 || y > h) return;
  if (field[y][x]) return;
  field[y][x] = true;
  for (int i = 0; i < 4; i++){
    if (mp[y + dy[i]][x + dx[i]] == color){
      dfs(y + dy[i], x + dx[i], color);
    }
  }
}

signed main()
{
  ios::sync_with_stdio(false);
  int n;

  while (cin >> w >> h, w || h){
    memset(field, false, sizeof(field));
    memset(mp, 0, sizeof(mp));
    cin >> xs >> ys >> xg >> yg >> n;
    for (int i = 0; i < n; i++){
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d){
        for (int j = 0; j < 4; j++){
          for (int k = 0; k < 2; k++){
            mp[y + j][x + k] = c;
          }
        }
      }
      else {
        for (int j = 0; j < 2; j++){
          for (int k = 0; k < 4; k++){
            mp[y + j][x + k] = c;
          }
        }
      }
    }
    dfs(ys, xs, mp[ys][xs]);
    (field[yg][xg]) ? print("OK") : print("NG");
  }

  return (0);
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],ans=0;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    while(a[0]!=a[2])
    {
        if(a[2]-a[0]>=2)
        {
            ans++;
            a[0]+=2;
        }
        else
        {
            ans++;
            a[0]++;
            a[1]++;
        }
        sort(a,a+3);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

//Union-Find tree
struct UnionFind
{
	vector<ll> par;
	vector<ll> rank;
	vector<ll> siz;

	UnionFind(ll n) : par(n), rank(n), siz(n)
	{
		for (ll i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			siz[i] = 1;
		}
	}
	ll root(ll x)
	{
		if (par[x] == x) return x;
		else return par[x] = root(par[x]);
	}
	ll size(ll x)
	{
		return siz[root(x)];
	}
	void unite(ll x, ll y)
	{
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry)return;
		if (rank[rx] < rank[ry])swap(rx, ry);
		par[ry] = rx;
		siz[rx] += siz[ry];
		if (rank[rx] == rank[ry])rank[rx]++;
	}
	bool same(ll x, ll y)
	{
		return root(x) == root(y);
	}
};

void solve()
{
	int n, m, k; cin >> n >> m >> k;
	vector<int> friends(n, 0);
	vector<vector<int>> block(n);
	UnionFind uf(n);
	rep(i, m) 
	{
		int a, b; cin >> a >> b;
		a--;b--;
		friends[a]++;
		friends[b]++;
		uf.unite(a, b);
	}
	rep(i, k) 
	{
		int c, d; cin >> c >> d;
		c--;d--;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	rep(i, n)
	{
		int ans = uf.size(i)-friends[i]-1;
		for(auto e : block[i])
		{
			if(uf.same(i,e))ans--;
		}
		cout << ans << " ";
	}
	return;
}

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


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

typedef long long ll;


int main(){
  ll n,r,maxpoint,minvalue;
  cin >> n;
  maxpoint = -1000000000;
  cin >> minvalue;
  for(int i=1;i<n;i++){
    cin >> r;
    maxpoint = max(maxpoint,r-minvalue);
    if(r < minvalue) minvalue = r;
  }
  cout << maxpoint << endl;
  return 0;
}



Measured memory_bytes: 3120
#include<iostream>
using namespace std;
int main(){
  char n[5];
  cin >> n;

  if(n[1] == n[2] && (n[0] == n[1] || n[2] == n[3]))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;


 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
#define pb(a) push_back(a);
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 

signed main(){
  ll n;
    cin>>n;
  auto A=div(n);
  ll a=A.sz;
  cout<<A[a/2]+n/A[a/2]-2<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int h, w;
	cin >> h >> w;
	string s[h];
	REP(i, h) cin >> s[i];

	REP(i, w + 2) cout << "#";
	cout << endl;
	REP(i, h) cout << "#" << s[i] << "#" << endl;

	REP(i, w + 2) cout << "#";
	cout << endl;
}


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

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;
#define EPS (1e-6)
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef pair<double,double> P;

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(3);
  int INF = 1000000;

  string str;
  while(cin>>str){
    REP(i,str.length()){
      if(str[i] == '@'){
	int num = str[i+1] - '0';
	char ta = str[i+2];
	REP(j,num){
	  cout << ta;
	}
	i+=2;
      }
      else
	cout << str[i];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

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

using namespace std;

int main() {
    long long N; cin >> N;
    long long S[5];
    rep(i, 5) cin >> S[i];
    long long minS = 1LL << 60;
    rep(i, 5) minS = min(minS, S[i]);
    if (N <= minS) cout << 5 << endl;
    else {
        if(N%minS == 0) {
            cout << (N/minS+4) << endl;
        } else {
            cout << (N/minS+5) << endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int main() {
    int n;
    cin >> n;
    
    int odd = 0, even = 0;
    rep(i, n) {
        int a;
        cin >> a;
        a % 2 == 0 ? even++ : odd++;
    }
    // cout << even << " " << odd << endl;
    int cnt = 0;
    
    // 合計は1個ずつ減る
    rep(i, n) {
        if (odd <= 0 || even <= 0) break;
        
        // 操作を行えたらcnt++
        if (odd > even) { // evenを増やす
            odd -= 2; even++;
        } else if (odd < even) {
            // oddが少ない oddが2減る作戦を取らない
            even--;
        } else {
            // 2, 2のとき生き残れるよう
            even--;
        }
        cnt++;
    }
    
    cout << cnt << '\n';
}



Measured memory_bytes: 3096
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(Console.ReadLine().Split().Select(x => Abs(long.Parse(x) - nx[1])).Aggregate(0L, (x, y) => GCD(x, y)));
    }

    static long GCD(long a, long b)
    {
        while (true)
        {
            if (b == 0) return a;
            a %= b;
            if (a == 0) return b;
            b %= a;
        }
    }
}

Measured memory_bytes: 20320
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+ch-48,ch=getchar();
	return x;
}
int n,t,m=0;
LL a[N],s[N],ans[N];
int Binary(int L,int R,LL v){
	int ans=0;
	while (L<=R){
		int mid=(L+R)>>1;
		if (a[mid]>v)
			R=mid-1;
		else
			L=mid+1,ans=mid;
	}
	return ans;
}
int main(){
	n=read(),t=read();
	a[++m]=n;
	for (int i=1;i<=t;i++){
		LL x=read();
		while (m>0&&a[m]>=x)
			m--;
		a[++m]=x;
	}
	memset(s,0,sizeof s);
	memset(ans,0,sizeof ans);
	s[m]=1;
	for (int i=m;i>=1;i--){
		LL x=a[i],j=i;
		while (j=Binary(1,j-1,x))
			s[j]+=x/a[j]*s[i],x%=a[j];
		ans[x]+=s[i];
	}
	for (int i=n-1;i>=1;i--)
		ans[i]+=ans[i+1];
	for (int i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int main(void){
  int h,n;
  int a=0;
  cin>>h>>n;
  int temp = 0;
  for(int i=0;i<n;i++){
    cin>>temp;
    a+=temp;
  }
  if(h > a){
   	cout<<"No"<<endl; 
  }else{
   	cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int r,c,n,m,k,i[105][105]={0},e;
	scanf("%d %d",&r,&c);
	for(n=1;n<(r+1);n++){
		for(m=1;m<c+1;m++){
			scanf("%d",&k);
			i[n][m]=k;
		}
	}
	for(n=1;n<=r;n++){
		for(m=1;m<=(c+1);m++){
			if(m<(c+1)){
			printf("%d ",i[n][m]);
			}else if(m==(c+1)){
				for(e=1;e<c+2;e++){
					i[n][c+1]=(i[n][e]+i[n][c+1]);
				}
				i[n][c+1]=i[n][c+1]/2;
				printf("%d\n",i[n][c+1]);
			}
			
		}
	}
	for(m=1;m<=c+1;m++){
		for(n=1;n<=r+1;n++){
			i[r+1][m]=(i[n][m]+i[r+1][m]);
			
		}i[r+1][m]=i[r+1][m]/2;
		if(m==c+1){
			printf("%d\n",i[r+1][m]);
		}else{
		printf("%d ",i[r+1][m]);
	}
	}
	return 0;
}

Measured memory_bytes: 648
#import sys
N = int(input())
H = list(map(int,input().split()))
cnt = 0
max_cnt = 0
for i in range(N - 1):
    if H[i] >= H[i+1] :
        cnt += 1
    else :
        if max_cnt < cnt :
            max_cnt = cnt
        cnt = 0
if max_cnt <= cnt :
    max_cnt = cnt
print(max_cnt)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int a, b, c, d;
string s;

int main(){
  cin >> s;
  if(s == "ABC") cout << "ARC"<<endl;
  else cout << "ABC"<<endl;
}

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

int di[2] = {0, 1};
int dj[2] = {1, 0};
int mat[5010][5];

int main(){
    int n;
    while(cin >> n, n){
        memset(mat, 0, sizeof(mat));
        int ma = 1;
        for(int i = 0; i < n; i++){
            int d, p, q;
            cin >> d >> p >> q;
            d--, q--;
            int put;
            for(put = 5000; put >= 0; put--){
                bool ok = true;
                for(int j = 0; j < p; j++){
                    ok &= mat[put+j*di[d]][q+j*dj[d]] == 0;
                }
                if(!ok) break;
            }
            int h = put+1;
            for(int j = 0; j < p; j++){
                mat[h+j*di[d]][q+j*dj[d]] = 1;
            }
            int acc = 0;
            for(int hh = h; hh < 5000; hh++){
                int sum = 0;
                for(int j = 0; j < 5; j++)  sum += mat[hh][j];
                if(sum == 5){
                    for(int j = 0; j < 5; j++)  mat[hh][j] = 0;
                    acc++;
                }else{
                    for(int j = 0; j < 5; j++)  mat[hh-acc][j] = mat[hh][j];
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < 5000; i++){
            for(int j = 0; j < 5; j++){
                ans += mat[i][j];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
int main(){
    string s, p; cin >> s >> p;
    string t = s + s;
    for(int i=0; i<s.size(); i++){
        string b = t.substr(i,p.size());
        if(b==p){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
map<int, int> R;
vector<int> v;
int main()
{
    scanf("%d%d", &N,&k);
    for(int i=0; i<N; i++)


    {
        int x;
        scanf("%d", &x);
        R[x]++;
    }
    map<int, int>::iterator it= R.begin();
    while(it != R.end())
    {
        v.pb(it->S);
        it++;
    }
    sort(v.begin(), v.end());
    if(R.size() <= k)
    {
        cout<<0;
    }
    else
    {
        ll cnt=0;
        ll o=R.size();
        for(int i=0;i<v.size();i++)
        {
            if(o == k) break;
            o--;
            cnt+=v[i];
        }
        cout<<cnt;
    }
    return 0;
}


Measured memory_bytes: 10748
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  vector<int> vec(3);
  cin >> vec[0] >> vec[1] >> vec[2];
  sort(vec.begin(), vec.end());
  if (vec[0] + vec[1] == vec[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,ma=0,x=0;
	char a[1000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]=='I')x++;
		if(a[i]=='D')x--;
		if(x>ma)ma=x;
	}
	cout<<ma<<endl;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();

    std::io::stdin().read_line(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();

    let a: i16 = iter.next().unwrap().parse().unwrap();
    let b: i16 = iter.next().unwrap().parse().unwrap();

    println!("{}", a * b);
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const {
        if (!n) return 1;
        ModInt a = pow(n >> 1);
        a *= a;
        if (n & 1) a *= *this;
        return a;
    }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

template <class T>
class Combination {
   public:
    vector<T> _fact, _rfact, _inv;
    constexpr Combination(int N) : _fact(N + 1), _rfact(N + 1), _inv(N + 1) {
        _fact[0] = _rfact[N] = _inv[0] = 1;
        for (int i = 1; i < N + 1; i++) _fact[i] = _fact[i - 1] * i;
        _rfact[N] /= _fact[N];
        for (int i = N - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
        for (int i = 1; i < N + 1; i++) _inv[i] = _rfact[i] * _fact[i - 1];
    }

    constexpr T fact(int k) const { return _fact[k]; }
    constexpr T rfact(int k) const { return _rfact[k]; }
    constexpr T inv(int k) const { return _inv[k]; }

    constexpr T P (int n, int r) const {
        if (r < 0 || n < r) return 0;
        return fact(n) * rfact(n - r);
    }
    
    constexpr T C (int n, int r) const {
        if (r < 0 || n < r) return 0;
        return fact(n) * rfact(r) * rfact(n - r);
    }
    
    constexpr T H (int n, int r) const {
        if (r < 0 || n < 0) return 0;
        return r == 0 ? 1 : C(n + r - 1, r);
    }
};

int main() {
    int K; string S; cin >> K >> S;

    Combination<mint> comb(K + S.size());
    mint ans = 0;
    REP(i, 0, K + 1) {
        // cout << "###" << endl;
        // cout << "comb : " << comb.C(i + S.size() - 1, i) << endl;
        // cout << "pow  : " << mint(25).pow(i) << endl;
        // cout << "pow  : " << mint(26).pow(K - i) << endl;
        ans += comb.C(i + S.size() - 1, i) * mint(25).pow(i) * mint(26).pow(K - i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51112
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, D, A;
	cin >> N >> D >> A;
	vector<pair<int,int>>X;
	for (int n = 0;n<N;++n) {
		int x, h;
		cin >> x >> h; 
		int att = 0;
		att = h / A;
		if (0 != h%A) {
			att++;
		}
		X.push_back(make_pair(x, att));
	}
	sort(X.begin(), X.end()); 
	vector<int>Y(N);//巻き込みkill
	for (int n = 0; n < N; ++n) {
		int num = X[n].first + 2 * D;
		int tmp;
		if (0 == n) {
			tmp = 0;
		}
		else {
			tmp = Y[n - 1];
		}
		for (int m = tmp;m < N ;++m) {
			if (num < X[m].first) {
				Y[n] = m - 1;
				break;
			}
			if (m == N-1) {
				Y[n] = m;
			}
		}
	}
	vector<int>R(N + 100);//累積和
	long long sum = 0;
	//左から、貪欲に最適に殺していく
	long long ans = 0;
	for (int n = 0; n < N; ++n) {
		sum += R[n]; 
		if (X[n].second > sum) {
			R[n + 1] += X[n].second - sum; 
			R[Y[n] + 1] -= X[n].second - sum; 
			ans += (long long)(X[n].second - sum);
		}
	}
	cout << ans <<  endl;
	return 0;
}

Measured memory_bytes: 6328
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int main() {
	int N,L;cin>>N>>L;
	map<string,int>mp;
	
	for (int i = 0; i < N; ++i) {
		string st;cin>>st;
		mp[st]++;
	}
	vector<string>use;
	for (auto m : mp) {
		if (m.second) {
			string rev(m.first);
			reverse(rev.begin(),rev.end());
			if (mp.find(rev) != mp.end()) {
				if (rev != m.first) {
					while (mp[rev]&&mp[m.first]) {

						mp[m.first]--;
						mp[rev]--;
						use.push_back(m.first);
					}
				}
				else {
					while (mp[m.first] >= 2) {

						mp[m.first]-=2;
						use.push_back(m.first);
					}
				}
			
			}
		}
	}
	sort(use.begin(), use.end(), [](const string &l, const string&r) {
		return l+r<r+l;
	});
	string ans;
	for (auto u : use) {
		ans+=u;
	}
	string revans(ans);
	reverse(revans.begin(),revans.end());
	ans+=revans;
	for (auto m : mp) {
		if (m.second) {
			string rev(m.first);
			reverse(rev.begin(), rev.end());
			if (m.first == rev) {
				ans.insert(ans.begin()+ans.size()/2,m.first.begin(),m.first.end());
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int H,W;
char c[333][333];
int sc1[333][333];//0,1
int dp[303][303];
int solve( int a,int b ){
  if( dp[a][b] != -1 ) return dp[a][b];
  if( a == 0 && b == 0 ) return dp[a][b] = 0;
  int ret = INT_MAX;  
  if( a )
    ret = min( ret, solve( a-1, b ) + sc1[a][b] );
  if( b )
    ret = min( ret, solve( a, b-1 ) + sc1[a][b] );
  //cout << a << " "<< b << " "<< c << " = " << ret << endl;
  return dp[a][b] = ret;
}

int main(){
  cin >> H >> W;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      cin >> c[j][i];

  int res = 0;
  for(int x=0;x<W-1;x++){
    memset( sc1, 0, sizeof( sc1 ) );
    for(int i=1;i<=H;i++){
      for(int j=1;j<=H;j++){
        sc1[i][j] = sc1[i-1][j-1] + ( c[x][i-1] == c[x+1][j-1] ? 1 : 0 );
      }      
    }
    memset( dp, -1, sizeof( dp ) );
    res += solve( H, H );
  }

  cout << res << endl;
}


Measured memory_bytes: 1152
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();
        //最大値を格納する変数ans
        long ans = a * c;
        if(a * d > ans){
            ans = a * d;
        }
        if(b * c > ans){
            ans = b * c;
        }
        if(b * d > ans){
            ans = b * d;
        }
        //ansを出力する
        System.out.println(ans);
    }
}

Measured memory_bytes: 35824
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int y, m, d;
	char a, b;
	cin >> y >> a >> m >> b >> d;
	if (m <= 4 && d <= 30)cout << "Heisei";
	else { cout << "TBD"; }
	ed;
	return 0;
}


Measured memory_bytes: 256