akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
    int H,W;
    cin >> H >> W;
    if(H%3==0 || W%3==0){
        cout << 0 << endl;
    }else{
        long long slashH = H/3+((H%3==1&&W%2==0) ? 0:1);
        long long SmaxH = W*slashH;
        long long HH = (H-slashH)/2*W;
        long long HW = (W/2)*(H-slashH);
        long long slashW = W/3+((W%3==1&&H%2==0) ? 0:1);
        long long SmaxW = H*slashW;
        long long WH = (W-slashW)*(H/2);
        long long WW = (W-slashW)/2*H;
        cout << min(abs(SmaxH-max(HW,HH)),abs(SmaxW-max(WH,WW))) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,X,Y = map(int,input().split())

from collections import deque

INF = 1000000000
ans = [0]*(N-1)


def rep(sv,dist):
    que = deque()

    def push(v,d):
        if (dist[v] != INF): return
        dist[v] = d
        que.append(v)

    push(sv,0)

    while(que):
        v = que.popleft()
        d = dist[v]

        if v-1 >= 0:
            push(v-1, d+1)
        if v+1 < N:
            push(v+1, d+1)
        if v == X-1:
            push(Y-1, d+1)
        #逆に気を付ける
        if v == Y-1:
            push(X-1, d+1)

for i in range(N):
    dist = [INF]*N
    rep(i,dist)
    # print(dist)
    for d in dist:
        if d-1 == -1:continue
        ans[d-1] += 1


for an in ans:
    print(an//2)
# print(ans)








Measured memory_bytes: 76056
s = int(input())

v = [False] * 1000001
v[s] = True

i = 1
while True:
    i += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    
    if v[s]:
        break
    else:
        v[s] = True

print(i)

Measured memory_bytes: 69724
#include <cstdio>
#include <istream>
using namespace std;
int main(){
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long A,B,C,D;
	A=a*c;
	B=b*d;
	C=a*d;
	D=b*c;
	printf("%lld\n",max(max(A,B),max(C,D)));
	return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<cmath>
using namespace std;
int min_cost(int arr[],int n){
    int cost[n];
    cost[0] = 0;
    cost[1] = abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
        cost[i] = min(abs(arr[i]-arr[i-1])+cost[i-1],abs(arr[i]-arr[i-2])+cost[i-2]);
    return cost[n-1];
}
int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    cout<<min_cost(arr,n)<<endl;
}

Measured memory_bytes: 4408
#include<iostream>
using namespace std;
int main(){
	int H, W;
	int i, j;
	while (true){
		cin >> H >> W;
		if (W == 0 && H == 0){ break; }
		for (j = 0; j < H; j++){
			for (i = 0; i < W; i++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
using namespace std;
 
int main() {
	char a, b;
cin>>a>>b;
if((a=='H')&&(b=='H')) {
cout<<"H" ;
} else if((a=='H')&&(b=='D')) {
cout<<"D" ;
} 
 if((a=='D')&&(b=='H')) {
cout<<"D" ;
}  else if((a=='D')&&(b=='D')) {
cout<<"H" ;
} 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  int count=0;
  for(int i=N;i<=2*N;i++){
    int d=2*N-i;
  
  if(d>0&&s.substr(N-d)==t.substr(0,2*N-i)){cout<<i<<endl;return 0;}
  else if(d==0){cout<<2*N<<endl;}
  }
  
  return 0;}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
//ll b[SZ];



int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin2(n, s);
//    n = s.size();

    stack <ll> st;

    for0(i, n) {
        if(s[i] == 'R') st.push(i);
    }

    for0(i, n) {
        if(s[i] == 'W') {
            if(st.empty()) break;

            p = st.top();
            st.pop();
            n = p;
            if(p < i) break;
            c++;
        }
    }

    cot1(c);

    return 0;
}



Measured memory_bytes: 5236
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/*-------------ここまで---------------------------------------------*/
int main(){
    int a, b;
    cin >> a >> b;
    int sum = b / a;
    if (sum * a == b) cout << a + b << endl;
    else cout << b - a << endl;
    return 0;
}

Measured memory_bytes: 3600
class Bit
  def initialize(b)
    @b = b
  end
  attr_reader :b
  def -@
    @b == 0 ? I : O
  end
  def *(other)
    self.b * other.b == 0 ? O : I
  end
  def ^(other)
    self.b ^ other.b == 0 ? O : I
  end
  def to_s
    @b.to_s
  end
end

O = Bit.new(0)
I = Bit.new(1)

class String
  def output
    ((0b0000..0b1111).map {|b|
      (eval tr('abcd', sprintf("%04b", b)).tr('10', 'IO')).to_s
    } * "").to_i(2)
  end

  def terminated?
    self !~ /e/
  end
end

queue = ['e']
min = Array.new(2**16, 16)
min[0x0000] = 1
min[0xffff] = 1

until queue.empty?
  e = queue.shift
  if e.terminated?
    out = e.output
    min[out] = e.size if e.size < min[out]
  else
    replaced = [
      e.sub(?e, ?a),
      e.sub(?e, ?b),
      e.sub(?e, ?c),
      e.sub(?e, ?d),
      e.sub(?e, "-e"),
      e.sub(?e, "(e*e)"),
      e.sub(?e, "(e^e)"),
    ]
    replaced.reject! {|r|
       r =~ /--/ or
       r =~ /a[*^]-?a/ or
       r =~ /b[*^]-?[ab]/ or
       r =~ /c[*^]-?[abc]/ or
       r =~ /d[*^]-?[abcd]/ or
       r =~ /\)[*^]-?[abcd]/
    }
    replaced.each do |r|
      if r.size < 16
        queue << r
      end
    end
  end
end

loop do
  s = gets.chomp
  break if s == ?.
  puts min[s.output]
end



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

#define ll long long

string convert(int decimal, int base){
    if(decimal == 0) return "0";
    char NUMS[] = "0123456789"; 
    string result = ""; 
    do{
        result.push_back(NUMS[decimal%base]);
    
        decimal /= base; 
    }while(decimal != 0); 
    
    return string(result.rbegin(), result.rend());
    
}

 int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     
     int n,k;
     cin>>n>>k;
     string s=convert(n,k);
     cout<<s.length();
     return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    ll N, M;
    cin >> N >> M;
    vector<ll> sum;
    sum.push_back(0);
    unordered_map<ll, ll> mp;
    mp[0]++;
    for(int i = 0; i < N; i++){
        ll in;
        cin >> in;
        sum.push_back((sum.back() + in) % M);
        mp[sum.back()]++;
    }
    ll ans = 0;
    ll val;
    for(int i = 0; i < sum.size(); i++){
        val = sum[i];
        ans += mp[val] * (mp[val] - 1) / 2;
        mp[val] = 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n=  int(sys.stdin.readline())
if n ==1:
    print(0)
elif n == 2:#なぜ？
    print(1)
else:
    print(n*(n-1)//2)

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

int gae[100001];
vector< pair<long long, int> > p;
vector< pair<int, int> > ans;
map<long long, int> mp;
long long ll[100001];
long long su[100001];

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        long long x;
        scanf("%lld", &x);
        p.push_back({x, i});
        gae[i] = 1;
        mp[x] = i;
        su[i] = x;
    }
    sort(p.begin(), p.end());
    for(int i=n-1;i>=1;i--){
        int target = p[i].second;
        long long cal = p[i].first - n + gae[target] + gae[target];
        int nxt = mp[cal];
        //printf("%d %lld\n", nxt, cal);
        if(nxt == 0 || cal >= p[i].first){
            printf("-1\n");
            return 0;
        }
        gae[nxt] += gae[target];
        ll[nxt] += ll[target]; ll[nxt] += gae[target];
        ans.push_back({nxt, target});
    }
    if(ll[p[0].second] == su[p[0].second]){
        for(auto &anss: ans){
            printf("%d %d\n", anss.first, anss.second);
        }
    }else{
        printf("-1\n");
    }
}


Measured memory_bytes: 13040
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long N = sc.nextLong();
        long ans = Long.MAX_VALUE;
        for (long i = 1; i * i <= N; i++) {
            if (N % i == 0) {
                ans = Math.min(ans, i + N / i - 2);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(int i = 1; i <= n; ++i)

int main(void) {
  int n;
  scanf("%d", &n);
  int a[n + 1];
  repi(i, n) scanf("%d", &a[i]);
  repi(i, n) {
    printf("node %d: key = %d, ", i, a[i]);
    if(i / 2) printf("parent key = %d, ", a[i / 2]);
    if(2 * i <= n) printf("left key = %d, ", a[2 * i]);
    if(2 * i < n) printf("right key = %d, ", a[2 * i + 1]);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2620
////////////////////////////////////
////////////////////////////////////
////                            ////
////                            ////
////     Please give me AC!     ////
////     Please give me AC!     ////
////                            ////
////                            ////
////////////////////////////////////
////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す//計算量は0(log(max(a,b))
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す//計算量は0(log(max(a,b))
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す//計算量は0(log(y))
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す//計算量は0(sqrt(a))
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
vector<int> Z;
void z_algorithm(string str){//計算量はO(str.size())
  Z.resize(str.size());
  Z.at(0)=str.size();
  int m=1,n=0;
  while(m<(int)str.size()){
    while(m+n<(int)str.size()&&str.at(n)==str.at(m+n)){n++;}
    Z.at(m)=n;
    if(n==0){
      m++;
      continue;
    }
    int k=1;
    while(k+Z.at(k)<n){
      Z.at(m+k)=Z.at(k);
      k++;
    }
    m+=k;
    n-=k;
  }
}
int main(){ll ans=0;
  string s,t;
  cin>>s>>t;
  for(int i=0;i<(int)s.size();i++){
    if(s.at(i)!=t.at(i)){ans++;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3812
#include<stdio.h>
int main(){
  int n,a,b,c,d,cnt;
  while(scanf("%d",&n)!=EOF){
    cnt=0;
    for(a=0;a<=9;a++){
      for(b=0;b<=9;b++){
	for(c=0;c<=9;c++){
	  for(d=0;d<=9;d++){
	    if(a+b+c+d==n)cnt++;
	  }
	}
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 596
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
N = int(readline())

NUMBERS = defaultdict(bool)

for _ in range(N):
  n = int(readline())
  NUMBERS[n] = not NUMBERS[n]

ans = 0
for k,v in NUMBERS.items():
  if v:
    ans += 1

print(ans)


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

int main() 
{
	int a,b,ans;
	cin >> a >> b;

	if( ( a >= 0 && a <= 100 ) && ( a >= 0 && a <= 100 ) )
	{
		if( a > 2*b )
			ans = a - 2*b;
		else
			ans = 0;
	}
	else
		ans = 0;
	cout << ans << endl;
}

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

using namespace std;

int main()
{
    vector<int> a({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
    int k;
    cin >> k;
    cout << a[k - 1];
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
class Bar:
  def __init__(self,num,length):
    self.num = num
    self.length = length
    
N = int(input())
T = list(map(int, input().split()))
bars = []
for n in range(N):
  bars.append(Bar(n,T[n]))

bars.sort(key = lambda x: x.length)
combi = list(combinations(bars,3))

ans = 0
for com in combi:
  if com[0].length == com[1].length or com[1].length == com[2].length:
    continue
  elif com[0].length + com[1].length <= com[2].length:
    continue
  else:
    ans += 1

print(ans)

Measured memory_bytes: 20636
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL Pow[40]={1};
LL calc(LL x1,LL y1,LL x2,LL y2,int d){
	if(d==-1)return abs(y2-y1);
	LL a=x1/Pow[d],b=y1/Pow[d],c=x2/Pow[d],d1=y2/Pow[d];
	if(a!=c)return abs(x2-x1)+abs(y2-y1);
	else if(a==1&&b!=d1){
		x1-=Pow[d],x2-=Pow[d];
		return abs(y2-y1)+min(x1+x2+2,Pow[d]*2-x1-x2);
	}
	x1-=Pow[d]*a,x2-=Pow[d]*a;
	return calc(x1,y1,x2,y2,d-1);
}

LL cal(LL x1,LL y1,LL x2,LL y2,int level) {
    if(level==0) return abs(y1-y2);
    LL w=Pow[level-1];
    if(x1/w!=x2/w) return abs(x1-x2)+abs(y1-y2);//不同层
    if(x1/w==1&&abs(y1/w-y2/w)>=2) {//同层且在456这层
        return min(x1%w+x2%w+2,w*2-x1%w-x2%w)+abs(y1-y2);
    }
    return cal(x1%w,y1,x2%w,y2,level-1);
}
LL work(){
	LL a,b,c,d;scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	a--,b--,c--,d--;if(abs(a-c)>abs(b-d))swap(a,b),swap(c,d);
	return cal(a,b,c,d,30);
}
int main(){
	for(int i=1;i<30;i++)Pow[i]=Pow[i-1]*3;
	int t;scanf("%d",&t);
	while(t--)printf("%lld\n",work());
	return 0;
}

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

int main(){
    int n,m,*a,*sum;
    cin >> n >> m;
    int **A = new int *[n];
    for (int i = 0; i < n; i++){
        A[i] = new int [m];
    }

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

    a = new int[m];
    for (int i = 0; i < m; i++){
        cin >> a[i];
    }

    sum = new int[n];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            sum[i] += A[i][j]*a[j];
        }
    }

    
    for (int i = 0; i < n; i++){
    cout << sum[i] << endl;
    }
    delete [] A;
    delete [] a;
    delete [] sum;
}


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


int main() {
    int N;
    cin>>N;
    
    vector<int>h(N+1);
    rep(i,N) cin>>h[i];
    int cnt =0;

    rep(i,100){
        rep(j,N){
            if(h[j]>0){
                h[j]--;
                if(h[j+1]==0) cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}

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

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

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    bool flg = true;
    int min;
    while(flg){
        std::sort(a.begin(), a.end());
        a.erase(std::unique(a.begin(), a.end()), a.end());
        
        auto itr = std::find_if(a.begin(), a.end(), [](int i){
            return 0 < i;
        });

        min = *itr;

        for(auto jtr = itr + 1; a.end() != jtr; ++jtr){
            *jtr %= min;
        }

        flg = !(1 == a.size() || 2 == a.size() && 0 == a.at(0));
    }

    std::cout << min << std::endl;

    return 0;
}

Measured memory_bytes: 640
import sys
import itertools

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
MOD = 10 ** 9 + 7
AGCT3 = ["".join(x) for x in itertools.product("AGCT", repeat=3)]
A, G, C, T = 0, 1, 2, 3
M = 64

blacklist3 = {"AGC", "ACG", "GAC"}


def solve():
    dp = [[0] * M for _ in range(N + 1)]
    for i in range(M):
        if AGCT3[i] not in blacklist3:
            dp[3][i] = 1
    for i in range(4, N + 1):
        for j in range(M):
            p3 = AGCT3[j]
            if p3 in blacklist3:
                dp[i][j] = 0
                continue

            if p3[1] == "G" and p3[2] == "C":
                for k in range(M):
                    q3 = AGCT3[k]
                    q2 = q3[1:]
                    if p3.startswith(q2) and q3[0] != "A":
                        dp[i][j] += dp[i - 1][k]
                        dp[i][j] %= MOD
                continue

            if p3[0] == "G" and p3[2] == "C":
                for k in range(M):
                    q3 = AGCT3[k]
                    q2 = q3[1:]
                    if p3.startswith(q2) and q3[0] != "A":
                        dp[i][j] += dp[i - 1][k]
                        dp[i][j] %= MOD
                continue

            for k in range(M):
                q3 = AGCT3[k]
                q2 = q3[1:]
                if p3.startswith(q2):
                    dp[i][j] += dp[i - 1][k]
                    dp[i][j] %= MOD
    ans = 0
    for x in dp[N]:
        ans = (ans + x) % MOD
    return ans


print(solve())


Measured memory_bytes: 3312
N, K = map(int, input().split())
A = map(int, input().split())
counter = 0
dic = {}

for a in A:
  if a in dic.keys():
    dic[a] += 1
  else:
    dic[a] = 1

k = len(dic)
v = sorted(dic.values())
if k > K:
  change_n = k -K
  for i in range(change_n):
    min_k = v[i]
    counter += min_k

print(counter)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
  int n;cin >>n;
  vector<int>b(n);
    for (int i = 0; i < n; ++i) {
        cin >>b[i];
    }
  vector<int>nx;
  vector<int>ans;
    while(1) {
        bool flg=true;
        for (int i = n - 1; i >=0; --i) {
            if(b[i]==i+1&&flg){
                ans.push_back(i+1);
                flg=false;
            }
            else {
                nx.push_back(b[i]);
            }
        }
        reverse(all(nx));
//        for(auto e:nx){
//            cout <<e<<" ";
//        }
//        cout <<endl;
        if(nx.empty())break;
        if(nx.size()==n){
            cout <<-1<<endl;
            return 0;
        }
        b=nx;
        nx.clear();
        n=b.size();
    }
    reverse(all(ans));
    for (int i = 0; i < ans.size(); ++i) {
        cout <<ans[i]<<endl;
    }
}


Measured memory_bytes: 3620
import itertools

x, y, z, k = map(int, input().split())
a = list( map(int, input().split()))
b = list( map(int, input().split()))
c = list( map(int, input().split()))

mix_ab= [a_+b_ for a_,b_ in itertools.product(a, b)]
mix_ab.sort(reverse=True)
c.sort(reverse=True)

mix_abc= [ab_+c_ for ab_,c_ in itertools.product(mix_ab[:k], c[:k])]
mix_abc.sort(reverse=True)

print(*mix_abc[:k], sep='\n')

Measured memory_bytes: 148020
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int A, B, C;
  cin >> A >> B >> C;
  for (int i = 0; i < 31; i++){
    if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1){
      cout << i << endl;
      return 0;
    }
    int a = B / 2 + C / 2;
    int b = A / 2 + C / 2;
    int c = A / 2 + B / 2;
    A = a;
    B = b;
    C = c;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

ll a[1001],dp[101][100002];

int main(){
	int n,i,j,k;
	ll m = 1000000007;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(i=0;i<=k;i++)
		dp[0][i]=0;
	for(i=0;i<=n;i++)
		dp[i][0]=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=k;j++){
			dp[i][j]=dp[i-1][j] + dp[i][j-1];
			dp[i][j]=dp[i][j]%m;
			if(j>a[i]){
				dp[i][j] -= dp[i-1][j-a[i]-1];
				while(dp[i][j]<m)
					dp[i][j]+=m;
			}
			dp[i][j]=dp[i][j]%m;
		}
	}

	printf("%lld\n",dp[n][k] );
	return 0;
}


Measured memory_bytes: 79104
s = input()
a = list(s)
#print(a)
b = 0
for i in range(len(s)):
  #print('i=',i,'s=',s[i])
  if ((i+1)%2==0 and s[i] =='R'):
    b +=1
  if ((i+1)%2==1 and s[i] =='L'):
    b +=1
if b > 0:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	bool a[h+5][k+5];
	char c;
	for(int ii=1;ii<=h;ii++)
		for(int jj=1;jj<=w;jj++)
		{
			cin>>c;
			if(c=='.')
				a[ii][jj]=0;
			else
				a[ii][jj]=1;
		}
	int ans=0;
	for(int i=0;i<(1<<h);i++)
		for(int j=0;j<(1<<w);j++)
		{
			int num=0;
			for(int ii=1;ii<=h;ii++)
				for(int jj=1;jj<=w;jj++)
				{
					if(a[ii][jj])
						if((i&(int)(1<<(ii-1)))&&(j&(int)(1<<(jj-1))))
							num++;
				}
			if(num==k)
				ans++;
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
struct Card{char suit,value;};

void bubble(struct Card A[],int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i+1;j--){
      if(A[j].value < A[j-1].value){
	Card t = A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}

void selection(struct Card A[],int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(A[j].value < A[minj].value)minj=j;
    }
    Card t = A[i];
    A[i]=A[minj];
    A[minj]=t;
  }
}

void print(struct Card A[],int N){
  for(int i=0;i<N;i++){
    if(i>0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit!=C2[i].suit)return false;
  }
  return true;
}

int main() {
  Card C1[100],C2[100];
  int N;
  char ch;
  
  cin >> N;
  for(int i=0;i<N;i++){
   cin >> C1[i].suit >> C1[i].value;
  }
  for(int i=0;i<N;i++)C2[i]=C1[i];
  bubble(C1,N);
  selection(C2,N);
  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }
  return 0;
}



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

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
typedef pair<LL, LL> P;
#define x first
#define y second
const int MAX_N = 1e5+100;
P A[MAX_N], B[MAX_N];
LL orA[MAX_N], orB[MAX_N];
int N;

bool cmp(P a, P b){
    return a.x > b.x;
}


int main(){
   // freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> orA[i] >> orB[i];
        A[i].x = orB[i] + orA[i];
        A[i].y = i;
    }
    sort(A, A+N, cmp);
    LL ans = 0;
    for(int i = 0; i < N; ++i){
        int idx = A[i].y;
        if(i&1) {
            ans -= orB[idx];
        } else {
            ans += orA[idx];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        a[i] += ans;
        ans += (b[i] - a[i] % b[i]) % b[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += min(B[i], A[i])
    B[i] -= min(B[i], A[i])
    ans += min(B[i], A[i + 1])
    A[i + 1] -= min(B[i], A[i + 1])

print(ans)


Measured memory_bytes: 18624
#include <cstring>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    string S; cin >> S;
    long long ans = 0;
    for (int s = 0; s < 1<<n; s++) {
        string r, b;
        for (int i = 0; i < n; i++)
            if ((s >> i) & 1) b.push_back(S[i]);
            else r.push_back(S[i]);
        const int rl = r.size(), bl = b.size();
        long long dp[rl+1][bl+1];
        memset(dp, 0, sizeof dp);
        for (int i = 0; i <= rl; i++) {
            for (int j = 0; j <= bl; j++) {
                if (i == 0 && j == 0) { dp[0][0] = 1; continue; }
                const char c = S[2*n-i-j];
                long long tmp = 0;
                if (i > 0 && r[i-1] == c) tmp += dp[i-1][j];
                if (j > 0 && b[j-1] == c) tmp += dp[i][j-1];
                dp[i][j] = tmp;
            }
        }
        ans += dp[rl][bl];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var n = readLine()!!.toLong()
    var a = when((n % 11).toInt()){
        0 -> (n / 11) * 2
        1, 2, 3, 4, 5, 6 -> (n / 11) * 2 + 1
        else -> (n / 11) * 2 + 2
    }
    println(a)
}

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

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

	int n, a, b, o;

	cin >> n >> a >> b;

	o = n * a;

	if (o > b) {
		o = b;
	}

	cout << o << endl;

	return 0;
}



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

const int N=55,Mod=1e9+7;

int n,a[N<<1],f[N][N<<1][N<<1];

void Init() {
	scanf("%d",&n);
	for (int i=1;i<=(n<<1)-1;++i) scanf("%d",&a[i]);
	std::sort(a+1,a+(n<<1));
}

void Solve() {
	a[0]=a[1]; a[n<<1]=a[(n<<1)-1];
	f[n][a[n-1]!=a[n]][a[n+1]!=a[n]]=1;
	for (int i=n,d=0;i>=1;--i) {
		++d; int pl=(a[n-d]!=a[n-d-1]),pr=(a[n+d]!=a[n+d+1]);
		for (int l=0;l<(n<<1);++l) 
			for (int r=0;r<(n<<1);++r) if (f[i][l][r]) {
				int v=f[i][l][r];
				for (int a=0;a<l;++a) f[i-1][a+pl][r+pr+1]=(f[i-1][a+pl][r+pr+1]+v)%Mod;
				f[i-1][l+pl][r+pr]=(f[i-1][l+pl][r+pr]+v)%Mod;
				for (int a=0;a<r;++a) f[i-1][l+pl+1][a+pr]=(f[i-1][l+pl+1][a+pr]+v)%Mod;
			}
	}
	int ans=0;
	for (int l=0;l<(n<<1);++l) 
		for (int r=0;r<(n<<1);++r) 
			ans=(ans+f[1][l][r])%Mod;
	printf("%d\n",ans);
}

int main() {
	Init();
	Solve();
	return 0;
}

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

bool compute(string str1, string str2){
  bool V1[MAX][MAX], V2[MAX][MAX];
  int ldy1, ldx1, rty1, rtx1;
  int dy[6] = {1, 1, 0, -1, -1, 0};
  int dx[6] = {0, -1, -1, 0, 1, 1};
  if ( str1.size() != str2.size() ) return false;
  int n = (int)str1.size()*2+2;
  rep(y, n) rep(x, n) V1[y][x] = false;

  int py = n/2;
  int px = n/2;
  V1[py][px] = true;
  ldy1 = rty1 = py;
  ldx1 = rtx1 = px;
  rep(i, str1.size()){
    int r = (str1[i]-'a')%6;
    py += dy[r];
    px += dx[r];
    V1[py][px] = true;
    ldy1 = min(ldy1, py);
    ldx1 = min(ldx1, px);
    rty1 = max(rty1, py);
    rtx1 = max(rtx1, px);
  }

  rep(d, 6){
    int ldy2, ldx2, rty2, rtx2;
    py = n/2;
    px = n/2;
    ldy2 = rty2 = py;
    ldx2 = rtx2 = px;
    rep(y, n) rep(x, n) V2[y][x] = false;
    V2[py][px] = true;
    rep(i, str2.size()){
      int r = (str2[i]-'a'+d)%6;
      py += dy[r];
      px += dx[r];
      V2[py][px] = true;
      ldy2 = min(ldy2, py);
      ldx2 = min(ldx2, px);
      rty2 = max(rty2, py);
      rtx2 = max(rtx2, px);
    }
    if ( !(rty1-ldy1 == rty2-ldy2 && rtx1-ldx1 == rtx2-ldx2 ) ) continue;
    int h = rty1-ldy1+1;
    int w = rtx1-ldx1+1;
    bool same = true;
    rep(y, h) rep(x, w){
      if ( V1[y+ldy1][x+ldx1] != V2[y+ldy2][x+ldx2] ) {same = false; break;}
    }
    if ( same ) return true;
  }
  return false;
}

main(){
  int tcase; cin >> tcase;
  string str1, str2, kasu;
  getline(cin, kasu);
  rep(t, tcase) {
    getline(cin, str1);
    getline(cin, str2);
    if (compute(str1, str2) ) cout << "true" << endl;
    else cout << "false" << endl;
    getline(cin, kasu);
  }
}

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

int main(){
    int K;
    int ans;
    int digit = 0;
    int quotient;
    int seven = 0;
    int remaind = 0;
    cin >> K;
    quotient = K;

    if((K%2==0 or K%5==0) and !(K%7==0)){
        cout << "-1" << endl;
    }
    else{
        while(quotient >= 1){
            quotient = quotient/10;
            digit++;
        }
        //cout << digit << endl;
        for(int i = 0; i < digit; i++){
            seven = seven*10 + 7;
        }
        //cout << seven << endl;

        remaind = seven%K;
        //cout << remaind << endl;
        ans = digit;
        while(remaind%K != 0){
            remaind = (remaind * 10 + 7)%K;
            //cout << remaind << endl;
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String args[]) {
        FastScanner cin = new FastScanner();
        String s = cin.next();

        for (int i = 0; i < s.length() - 1; ++i) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                System.out.printf("%d %d\n", i + 1, i + 2);
                return;
            }

            if (i < s.length() - 2 && s.charAt(i) == s.charAt(i + 2)) {
                System.out.printf("%d %d\n", i + 1, i + 3);
                return;
            }
        }

        System.out.println("-1 -1");
    }

    static class FastScanner {
        StringTokenizer tokenizer;
        Scanner scanner;

        FastScanner() {
            tokenizer = null;
            scanner = new Scanner(System.in);
        }

        int nextInt() {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(scanner.nextLine());

            return Integer.parseInt(tokenizer.nextToken());
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(scanner.nextLine());

            return tokenizer.nextToken();
        }
    }
}


Measured memory_bytes: 26104
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

void solve (void)
{
  int N,K;
  cin>>N>>K;
  map<int,int> mp;
  for (int i = 0; i < N; i++)
  {
    int A,B;
    cin>>A>>B;
    mp[A] += B;
  }
  int cnt = 0;
  int cnt_p = -1;
  int ANS = 0;
  for (auto &&i : mp)
  {
    cnt += i.second;
    // DEBUG(cnt);
    if(cnt >= K && cnt_p < K)
    {
      ANS = i.first;
      break;
    }
    cnt_p = cnt;
  }
  cout<<ANS<<endl;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 4224
// D - Coloring Dominoes
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007

ll solve(int N, string &S1, string &S2){

	ll ans = 6;//ドミノが横のとき
	int start = 2;
	bool isPreVertical = false;//前回の状態: 縦: true, 横: false
	if(S1[0] == S2[0]){// 縦
		isPreVertical = true;
		ans = 3;
		start = 1;
	}

	rp(i, start, N){
		ll mulnum;
		if(S1[i] == S2[i]){// 縦
			mulnum = isPreVertical? 2:1;
			isPreVertical = true;
		}
		else{//横
			mulnum = isPreVertical? 2:3;
			isPreVertical = false;
			i++;
		}
		ans = ans * mulnum % MOD;
	}

	return ans;
}

int main(){
	int N; string S1,S2;
	cin>>N>>S1>>S2;
	cout<< solve(N, S1, S2) <<endl;
}

Measured memory_bytes: 256
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}

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 all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9+7;

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

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> vec(n+1);
	vector<int> s(n+1);
	reps(i,n){
		char c;
		cin >> c;
		s[i] = (c == 'E');
		vec[i] = vec[i-1] + s[i];
	}
	int minv = LINF;
	reps(i,n){
		minv = min(minv,vec[n] - vec[i] + ((i-1) - vec[i-1]));
	}
	cout << minv << '\n';
	return 0;
}


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


int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<int> vec(N);
	
	for(int i=0;i<M;i++){
		int temp;
		cin>>temp;
		vec[temp-1]++;
		cin>>temp;
		vec[temp-1]++;
	}
	
	for(int i=0;i<N;i++){
		cout<<vec[i]<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
K = int(input())

V = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range (0, 100000):
	if V[i]%10 == 0:
		V.append(10*V[i]+0)
		V.append(10*V[i]+1)
	elif V[i]%10 == 9:
		V.append(10*V[i]+8)
		V.append(10*V[i]+9)
	else:
		V.append(10*V[i]+V[i]%10-1)
		V.append(10*V[i]+V[i]%10)
		V.append(10*V[i]+V[i]%10+1)

print(V[K-1])

Measured memory_bytes: 59440
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, W;
    std::cin >> N >> W;

    struct Material {
        int64_t w;
        int64_t v;
    };

    std::vector<Material> M;
    for (decltype(N) i = 0; i < N; ++i) {
        Material t;
        std::cin >> t.w >> t.v;
        M.push_back(t);
    }

    std::vector<std::unordered_map<int64_t, int64_t>> memo(N+1);

    auto f = [N, W, &M, &memo](auto F, int64_t n, int64_t w) -> int64_t {
        if (memo[n].count(w) == 1) {
            return memo[n][w];
        }

        if (n == N) {
            memo[n][w] = 0;
        }
        else if (w + M[n].w > W) {
            memo[n][w] = F(F, n+1, w);
        }
        else {
            memo[n][w] = std::max(F(F, n+1, w), F(F, n+1, w+M[n].w) + M[n].v);
        }
        return memo[n][w];
    };

    auto v = f(f, 0, 0);

    std::cout << v << std::endl;

    return 0;
}


Measured memory_bytes: 4480
s=str(input())
a,b=int(s[:2]),int(s[2:])
f,g= 1<=a and a<=12, 1<=b and b<=12
if f and g:
  print("AMBIGUOUS")
elif f:
  print("MMYY")
elif g:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int N,A,B,fst;
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    fst=N*A;
    if(fst<B){
        printf("%d\n",fst);
    }
    else{
        printf("%d\n",B);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,oo=1e9;
char s[N];
int n,temp_tot,o,min_a=1;
int nxt[30][N],g[N],a[N];
bool vis[30];
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%s",s+1);
	n=strlen(s+1); //s+1 !!
	for(int i=1;i<=n;i++) a[i]=s[i]-'a'+1;
	for(int i=1;i<=26;i++) nxt[i][n+1]=oo;
	for(int i=n;i>=1;i--){
		for(int j=1;j<=26;j++) nxt[j][i]=nxt[j][i+1];
		nxt[a[i]][i]=i; //!
		g[i]=min_a; 
		if(!vis[a[i]]) vis[a[i]]=1;
		while(vis[min_a]) min_a++;
		if(min_a>26){
			min_a=1;
			memset(vis,0,sizeof(vis));
		}
	}
	for(int i=1;i<=26;i++) nxt[i][0]=nxt[i][1];
	nxt[a[1]][0]=1;
	g[0]=min_a,g[n+1]=1;
	int t=0;
	while(t<=n){
		putchar(g[t]+'a'-1);
//		cout<<" "<<g[t]<<endl;
		t=nxt[g[t]][t+1];
	}
	return 0;
}

Measured memory_bytes: 24576
use proconio::input;
use proconio::marker::{Chars};
use std::iter::Iterator;
use std::collections::HashSet;

fn main() {
    input! {
    k :usize,
    mut s: String,
    }

    if s.len() <= k {
        println!("{}", s);
    }else{
        println!("{}...", &mut s[0..k]);
    }

}


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

int main(void){

  int n,i,a,b,c;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a >> b >> c;
    int num[3];
    num[0] = a;
    num[1] = b;
    num[2] = c;

    sort(num,num+3);

    if(num[2]*num[2] == num[0]*num[0] + num[1]*num[1])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;

}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
using ll = long long;
int main(void){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int N, M;
vector<pair<int,int>> X;

int main(){
    
    cin >> N >> M;
    
    int a, b;
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        X.push_back( make_pair(b,a) );
    }
    sort( X.begin(), X.end());
    
    int pre = 0, ans = 0;
    for ( int i = 0; i < M; i++) {
        if (pre<X[i].second) {
            ans++;
            pre = X[i].first-1;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
#define INF 100000000
/*
N  個の整数列 l1,l2,…,lN が与えられ、以下の操作を繰り返すことで、整数列が 3 個の整数 A,B,C を含むような状態にしたい。それを実現するのに必要な最小コストを求めよ。

整数の中から 1 つ選んで +1 する (コスト 1)
2 以上の整数の中から 1 つ選んで -1 する (コスト 1)
2 つの整数を選んで、消して、それらを合計したもので置き換える (コスト 10)

3≤N≤8
*/


void chmin(int &a,int b){if(a>b) a=b;}

int N,A,B,C;
vector<int> L;

int dfs(int i,int a,int b,int c)
{
    //final Condition
    if(i==N)
    {
        if(a==0 || b==0 || c==0) return INF;
        return abs(A-a)+abs(B-b)+abs(C-c);
    }

    //use nothing
    int ret=dfs(i+1,a,b,c);

    //use anything
    chmin(ret,dfs(i+1,a+L[i],b,c)+(a?10:0));
    chmin(ret,dfs(i+1,a,b+L[i],c)+(b?10:0));
    chmin(ret,dfs(i+1,a,b,c+L[i])+(c?10:0));
    return ret;
}

int main()
{
    cin>>N>>A>>B>>C;
    L.resize(N);
    for(int i=0;i<N;i++)
    {
        cin>>L[i];
    }
    cout<<dfs(0,0,0,0)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
int abs(int x){
    if(x<0) return -x;
    else return x;
}
int main(){
    int n;
    cin >> n;
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> l(n);
    rp(i,n) cin >> l.at(i);
    int ans=10000000;
    for(int i=0; i<(1<<(2*n)); i++){
        int fora=0; int forb=0; int forc=0;
        int ina=0,inb=0,inc=0;
        rp(j,n){
            if((i>>(2*j))%4==1){
                fora += l.at(j);
                ina++;
            }
            if((i>>(2*j))%4==2){
                forb += l.at(j);
                inb++;
            }
            if((i>>(2*j))%4==3){
                forc += l.at(j);
                inc++;
            }
        }
        if(ina*inb*inc==0) continue;
        int cand=abs(fora-a)+abs(forb-b)+abs(forc-c)+10*(ina+inb+inc-3);
        ans=min(ans,cand);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string s;
  cin >> s;
  deque<char> a;
  rep(i,s.size()) {
    if (s[i] == 'B' && !a.empty()) {
      a.pop_back();
    }
    else if (s[i] != 'B'){
      a.push_back(s[i]);
    }
  }
  while (!a.empty()) {
    std::cout << a.front();
    a.pop_front();
  }
  cout << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3660
/*
      author : nishi5451
      created: 11.08.2020 20:19:46
*/

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


int main(){
    int a,b;
    cin >> a >> b;
    if(b>=a) cout << a << endl;
    else cout << a-1 << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    vector<string>data;
    for(int i = 1; i <= 9; ++i)
        data.emplace_back(to_string(i));
    int k; cin >> k;
    rep(i,k){
        string ts = data[i];
        int val = ts.back() - '0';
        if(val - 1 >= 0)
            data.emplace_back(ts + to_string(val-1));
        data.emplace_back(ts + to_string(val));
        if(val + 1 <= 9)
            data.emplace_back(ts + to_string(val + 1));
    }
    cout << data[k-1] << endl;
}


Measured memory_bytes: 18544