akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
S = list(input())

happiness = 0
unhappiness = 0

if N == 1:
    print(0)
    exit()

if S[0] == 'R':
    if S[0] == S[1]:
        happiness += 1
    else:
        unhappiness += 1
else:
    unhappiness += 1
# print(S[0], happiness, unhappiness)

for i in range(1, N - 1):
    c = S[i]
    if c == 'R':
        nex = S[i + 1]
    elif c == 'L':
        nex = S[i - 1]

    if c == nex:
        happiness += 1
    else:
        unhappiness += 1
    # print(c, happiness, unhappiness)

if S[-1] == 'L':
    if S[-1] == S[-2]:
        happiness += 1
    else:
        unhappiness += 1
else:
    unhappiness += 1
# print(S[-1], happiness, unhappiness)

# print(happiness, unhappiness, K)

moves = min(unhappiness // 2, K)
plus_happiness = unhappiness % 2 if K - moves > 0 else 0
ans = 2 * moves + happiness + plus_happiness
# print(moves, happiness, plus_happiness)
print(min(ans, N-1))


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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define deb(x)       cout << #x << ' ' << x << endl
#define clock        cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl;

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

const int N = 1e5 + 5;

int a[N], n, k;
int cache[N];
 
int dp(int idx) {
	if (cache[idx] != -1) return cache[idx];
	int ans = (idx == n - 1 ? 0 : LLONG_MAX);
	forn(i, 1, k + 1) {
		if (idx + i < n) ans = min(ans, abs(a[idx] - a[idx + i]) + dp(idx + i));
	}
	cache[idx] = ans;
	return cache[idx];
}

int32_t main(){
    IOS //INPUT();
    cin >> n >> k;
    forn(i, 0, n) cin >> a[i];
    memset(cache, -1, sizeof(cache));
    int ans = dp(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
import sys
import random
import itertools
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n = int(input())

import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n //= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
#a = factorization(n)
#b = []
#for i,j in a:
#  b.append(i)
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
#素因数列挙
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  table = set(table)
  table = list(table)
  return table

a = divisor(n)
ans = []
a.remove(n)
for i in a:
    b = (n-i)//i
    if n//b == n %b:
        ans.append(b)
print(sum(ans))

Measured memory_bytes: 40176
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 

A=list(map(int, input().split()))  


if (A.count(A[0]) ==2 or A.count(A[1]) ==2):
        print('Yes')
else:
        print('No')

Measured memory_bytes: 22916
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<61;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
char a;cin>>a;
  int r=a-'a';
  if(r>=0)cout<<'a'<<endl;
  else cout<<'A'<<endl;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10");
            //9
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("81");
            //81
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("271828182");
            //271821169
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        int Answer = 0;
        for (int I = 1; I * I <= N; I++) {
            Answer = I * I;
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, dp[4010];

int main(){
	rep(i, 1001) rep(j, 1001) dp[i + j]++;
	
	while(cin >> n){
		
		ll ans = 0;
		rep(i, n + 1) ans += (ll)dp[i] * dp[n - i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int a[maxn]; 
int main() {
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	ll ans = 0;
	for(int i=1;i<=k;i++){
		ans+=a[i];
	} 
	cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3624
#include <algorithm>
#include <cstdio>
#include <climits>
#include <vector>
using namespace std;

int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        static pair<int,int> h[3000];
        for(int i = 0; i < n; i++) {
            scanf("%d%d", &h[i].first, &h[i].second);
        }
        sort(h, h+n);

        int max_area = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                int x0 = h[i].first;
                int y0 = h[i].second;
                int x1 = h[j].first;
                int y1 = h[j].second;
                int xplus = y1-y0;
                int yplus = x0-x1;
                int x2 = x0+xplus;
                int y2 = y0+yplus;
                int x3 = x1+xplus;
                int y3 = y1+yplus;
                if(binary_search(h, h+n, make_pair(x2,y2)) && binary_search(h, h+n, make_pair(x3,y3))) {
                    max_area = max(max_area, xplus*xplus+yplus*yplus);
                }
            }
        }
        printf("%d\n", max_area);
    }
    return 0;
}

Measured memory_bytes: 788
n, m = map(int, input().split())
sList = []
pList = []
for i in range(m):
  s, p = map(int, input().split())
  if s == 1 and p == 0 and n > 1:
    print(-1)
    exit()
  existFlag = False
  for i, sListItem in enumerate(sList):
    if sListItem == s and pList[i] != p:
      print(-1)
      exit()
    if s in sList:
      existFlag = True
  if not existFlag:
    sList.append(s)
    pList.append(p)

result = ['0'] * n
for i, s in enumerate(sList):
  result[s-1] = str(pList[i])
if result[0] == '0' and n > 1:
  result[0] = '1'
print(''.join(result))


Measured memory_bytes: 3188
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    int res = 0;
    while (n) {
        res++;
        n /= k;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
while(1){
string str;
cin>>str;
if(str=="0"){
break;
}
int sum=0;
for(int i=0;i<(int)str.size();i++){
sum+=str[i]-'0';
}
cout<<sum<<endl;
}
return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t>>x>>y;
        if(!(x+y<=t&&(t-x-y)%2==0)){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

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

unsigned euclidean_gcd(int a, int b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
    int K;
    cin >> K;
    int64_t sum = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                sum += euclidean_gcd(euclidean_gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
	int n,count=0;
	scanf("%d",&n);
	int juwel[n],cost[n];
    for(int i=0;i<n;i++){
    	scanf("%d",&juwel[i]);
    }
    for(int j=0;j<n;j++){
    	scanf("%d",&cost[j]);
    }
    for(int l=0;l<n;l++){
    	if(juwel[l]-cost[l]>=0){
    		count+=(juwel[l]-cost[l]);
    	}
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,max,min=0;
    long int sum=0;
    cin>>a;
    int b[10000];
    cin>>b[0];
    max=b[0];
    min=b[0];
    sum=b[0];
    for(int i=1;i<a;i++){
        cin>>b[i];
        sum+=b[i];
        if(b[i]>max)
            max=b[i];
        if(b[i]<min)
            min=b[i];

    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int stu[] = new int[N];
    for (int i = 0;i < N;i++) {
      A[i] = scan.nextInt();
      stu[A[i] - 1] = i + 1;
    }
    for (int i = 0;i < N;i++) {
      System.out.print(stu[i] + " ");
    }
  }
}


Measured memory_bytes: 62380
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			a=__gcd(i,j);
			for(int k=1;k<=n;++k)
			{
				sum=sum+__gcd(a,k);
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 3828
N,A,B = gets.split.map &:to_i
n = N / (A+B)
z = N % (A+B)
if N <= A
  puts N
  exit
end
if A+B >= N
  puts A
  exit
end
if z >= A
  z = A
end
if A != 0
  puts n * A + z
else
  puts 0
end

Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    int ans = b / a;
    cout << (ans <= c ? ans : c);
}

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

using namespace std;

int main() {

	long n,m;

	cin >> n >> m;

	vector<long> a(n),b(n);

	long maxx;
	maxx= 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	double total = accumulate(a.begin(), a.end(), 0);
	total = total / m / 4;

	b = a;
	for (int i = b.size()-1; i >=0; i--) {
		if (b[i] < total) {
			b.erase(b.begin() + i);
		}
	}


	cout << (b.size() >= m ? "Yes" : "No") << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
	static Scanner InData = new Scanner(System.in);
	static int qType, qVal;
	static String qKey;
	static Map<String, Integer> M = new HashMap<String, Integer>();
	public static void main(String[] args) {
		getQuery();
	}
	private static void getQuery() {
		int qNum = InData.nextInt();
		for(int indexOfQuery = 0; indexOfQuery < qNum; indexOfQuery++) {
			qType = InData.nextInt();
			qKey = InData.next();
			doQuery(qType, qKey);
		}
	}
	private static void doQuery(int type, String key) {
		switch(type) {
		case 0:
			qVal = InData.nextInt();
				M.put(key, qVal);
			break;
		case 1:
			System.out.println(M.get(key));
			break;
		}
	}
}



Measured memory_bytes: 193724
# -*- coding: utf-8 -*-
import math
Q, H, S, D = map(int, input().split())
N = int(input())

one = min([Q*4, H*2, S])
two = D

cost1 = N * one
cost2 = N//2 * two + (N %2) * one
#print(one, two, cost1, cost2)
# data = [Q*4, H*2, S, D/2]
# nums = [0.25, 0.5, 1, 2]
# price = [Q, H, S, D]
# data_index = sorted(range(len(data)), key=lambda k: data[k])
# #print(data,data_index)
# ans = 0
# for i in range(4):
#     ans += N//nums[data_index[i]] * price[data_index[i]]
#     N -= N//nums[data_index[i]] * nums[data_index[i]]
print(min(cost1, cost2))

Measured memory_bytes: 3060
def solve():
    X = input()

    if int(X) < 100:
        print('0')
        exit(0)

    twoDig = int(X[len(X)-2:])
    rest = int(X[:len(X)-2])

    ans = '1'
    for i in range(rest+1):
        if twoDig == 0:
            break
        for n in range(5, 0, -1):
            if twoDig - n >= 0:
                twoDig -= n
                break
    else:
        ans = '0'
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <functional>
#define N 262145
using namespace std;

int m, a[N];
vector<int> f;
int g[N];

inline int Lowbit(int x)
{
    return x & -x;
}

void AddFenwick(int p)
{
    for(; p <= m; p += Lowbit(p))
        g[p] ++;

    return;
}

int SumFenwick(int p)
{
    int o;

    for(o = 0; p; p -= Lowbit(p))
        o += g[p];

    return o;
}

int BSFindA(int v)
{
    int l, m, r;

    for(l = 0, r = ::m; l + 1 < r; )
    {
        m = (l + r) >> 1;
        if(a[m] < v)
            r = m;
        else
            l = m;
    }

    return r;
}

int BSFindB(int p)
{
    int l, m, r;
    int v;

    v = SumFenwick(p);
    for(l = p - 1, r = ::m; l + 1 < r; )
    {
        m = (l + r) >> 1;
        if(SumFenwick(m + 1) - v != m - p + 1)
            r = m;
        else
            l = m;
    }

    return r;
}

int main(void)
{
    int n;
    int i, j, k, p;

    scanf("%d", &n);
    m = 1 << n;
    for(i = 0; i < m; i ++)
        scanf("%d", &a[i]);
    sort(a, a + m, greater<int>());

    f.push_back(a[0]);
    AddFenwick(1);
    for(i = 0, j = 1; i < n; i ++, j = k)
    {
        sort(f.begin(), f.end());
        for(k = j; k < j + (1 << i); k ++)
        {
            // printf("%d : %d %d\n", k, f.at(k - j), a[k]);
            p = BSFindB(BSFindA(f.at(k - j)));
            // printf("%d : %d\n", f.at(k - j), p);
            if(p == m)
            {
                printf("No\n");

                return 0;
            }
            AddFenwick(p + 1);
            f.push_back(a[p]);
        }
    }
    printf("Yes\n");

    return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

bool check(string s){
    int n = s.size();
    REP(i, n-1){
        if(s[i]!=s[i+1])return false;
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    int res = 1<<30;
    int n = s.size();
    if(check(s))res = 0;
    for(char c='a'; c<='z'; c++){
        string t = s;
        REP(i, n){
            vector<char> w;
            REP(j, n-1-i){
                if(t[j]==c){
                    w.push_back(t[j]);
                }else{
                    w.push_back(t[j+1]);
                }
            }
            t = string(ALL(w));
            if(check(t)){
                res = min(res, i+1);
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

int main(void) {
    vector<int> A(3);
    for(int i = 0; i < 3; i++){
        cin >> A[i];
    }
    
    sort(A.begin(), A.end());
    
    cout << A[2]-A[0] << endl;
    return 0;
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef pair<int,int> P;
typedef long long ll;



int main() {
    string s;
    cin >> s;
    
    string s1 = {s[0],s[1]}, s2 = {s[2],s[3]};
    int x = stoi(s1), y = stoi(s2);
    
    if(x >= 1 && x <= 12) {
        if(y >= 1 && y <= 12)
            cout << "AMBIGUOUS" << endl;
        else
            cout << "MMYY" << endl;
    }
    else {
        if(y >= 1 && y <= 12)
            cout << "YYMM" << endl;
        else
            cout << "NA" << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	while (1) {
		if (N % 2 == 0) {
			cout << N << endl;
			break;
		}
		else {
			N += N;
		}
	}



}






Measured memory_bytes: 3652
// H - Grid 1

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

int H, W;
char a[1005][1005];
int DP[1005][1005];

int main(int argc, char **argv) {
	scanf("%d %d", &H, &W);
	for(int i = 0; i < H; i++) {
        scanf(" ");
	    for(int j = 0; j < W; j++) {
            scanf("%c", &a[i][j]);
	    }
	}

    memset(DP, -1, sizeof(DP));
    for(int i = 0; i <= H; i++) {
        DP[i][0] = 0;
    }
    for(int j = 0; j <= W; j++) {
        DP[0][j] = 0;
    }



	for(int i = 1; i <= H; i++) {
	    int j;
	    if(i == 1) {
            DP[1][1] = 1;
            j = 2;
	    } else {
            j = 1;
	    }
        for(; j <= W; j++) {
            if(a[i-1][j-1] == '#') continue;
            DP[i][j] = max(0, DP[i-1][j]) + max(0, DP[i][j-1]);
            DP[i][j] %= MOD;
        }
	}

	printf("%d\n", DP[H][W]);
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t=1;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[2]==s[3] && s[5]==s[4])
            cout<<"Yes";
        else
            cout<<"No";
        cout<<endl;
    }
    return 0;
}




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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 2010;

int n;
int A[N];

int dp[N][2];

int main(){
	scanf("%d%*d%d", &n, &A[0]);
	For(i, 1, n) scanf("%d", &A[i]);

	Forr(i, n, 1){
		int Max = abs(A[i - 1] - A[n]), Min = Max;
		For(j, i + 1, n) Max = max(Max, dp[j][1]), Min = min(Min, dp[j][0]);
		dp[i][0] = Max, dp[i][1] = Min;
	}

	printf("%d\n", dp[1][0]);
	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
nya = []
for i in range(n):
    nya.append((i+1,A[i]))
nya = sorted(nya,key = lambda x:x[1])
ans = []
for (idx,po) in nya:
    ans.append(idx)
print(*ans)


Measured memory_bytes: 27252
#include <stdio.h>

using namespace std;

#define MAX 100000
#define INF 1000000000

typedef struct _card {
	int number;
	char symbol;
} card_t;

card_t ary_a[MAX];
card_t ary_b[MAX];
card_t ary_bl[MAX/2];
card_t ary_br[MAX/2];

int partition( int p, int r ) {
	int i = p-1;
	int x = ary_a[r].number;
	card_t tmp;

	for ( int j = p ; j < r ; j++ ) {
		if ( ary_a[j].number <= x ) {
			i++;
			tmp = ary_a[j];
			ary_a[j] = ary_a[i];
			ary_a[i] = tmp;
		}
	}

	tmp = ary_a[r];
	ary_a[r] = ary_a[i+1];
	ary_a[i+1] = tmp;

	return i+1;
}

void quicksort( int p, int r ) {
	int q;
	if ( p < r ) {
		q = partition( p, r );
		quicksort( p, q-1 ); 
		quicksort( q, r );
	}
}

void merge( int left, int mid, int right ) {
	int n1 = mid - left;
	int n2 = right - mid;

	for ( int i = 0 ; i < n1 ; i++ ) {
		ary_bl[i] = ary_b[left+i];
	}

	for ( int i = 0 ; i < n2 ; i++ ) {
		ary_br[i] = ary_b[mid+i];
	}

	ary_bl[n1].number = INF;
	ary_br[n2].number = INF;

	int i = 0, j = 0;
	card_t tmp;
	for ( int k = left ; k < right ; k++ ) {
		if ( ary_bl[i].number <=  ary_br[j].number ) {
			ary_b[k] = ary_bl[i];
			i++;
		} else {
			ary_b[k] = ary_br[j];
			j++;
		}
	}
}

void mergesort( int left, int right ) {
	if ( left+1 < right ) {
		int mid = ( left + right ) / 2;
		mergesort( left, mid );
		mergesort( mid, right );
		merge( left, mid, right );
	}
}

int main() {
	int number;
	int stable = 1;
	scanf( "%d", &number );

	for ( int i = 0 ; i < number ; i++ ) {
		scanf( " %c %d", &ary_a[i].symbol, &ary_a[i].number );
		ary_b[i].symbol = ary_a[i].symbol;
		ary_b[i].number = ary_a[i].number;
	}

	quicksort( 0, number-1 );
	mergesort( 0, number );

	for ( int i = 0 ; i < number ; i++ ) {
		if ( ary_a[i].symbol != ary_b[i].symbol ) {
			stable = 0;
			break;
		}
	}
	if ( stable ) {
		fprintf( stdout, "Stable\n" );
	} else {
		fprintf( stdout, "Not stable\n" );
	}

	for ( int i = 0 ; i < number ; i++ ) {
		fprintf( stdout, "%c %d\n", ary_a[i].symbol, ary_a[i].number );
	}
	return 0;
}



Measured memory_bytes: 5012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

    ll res = 1;
    while(n > 0){
        if(n & 1)   res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

struct Combination{
    int sz;
    vector<ll> fact;
    vector<ll> ifact;

    Combination(int sz = 1e+5) : sz(sz) {
        fact = vector<ll>(sz + 1);
        ifact = vector<ll>(sz + 1);

        fact[0] = 1;
        for(ll i = 1; i <= sz; ++i){
            fact[i] = fact[i - 1] * i % mod;
        }

        ifact[sz] = mod_pow(fact[sz], mod - 2);
        for(ll i = sz; i > 0; --i){
            ifact[i - 1] = ifact[i] * i % mod;
        }
    }

    ll get_combination(int n, int r){
        if(n < 0 || r < 0 || n < r)     return 0;

        return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
    }
};

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

    ll x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    int num = (x + y) / 3;

    Combination c(700000);
    int n = x - num;
    cout << c.get_combination(num, n) << endl;
}


Measured memory_bytes: 11264
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
 
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO ?????????????????????????????????????????????
        int i,j,n,q,a;
        a=0;
        Scanner scan=new Scanner(System.in);
        n=scan.nextInt();
        int s[]=new int [n];
        for(i=0;i<n;i++)
        {
            s[i]=scan.nextInt();
        }
        q=scan.nextInt();
        int t[]=new int [q];
        for(j=0;j<q;j++)
        {
            t[j]=scan.nextInt();
        }
        for(j=0;j<q;j++)
        {
            for(i=0;i<n;i++)
            {
                if(t[j]==s[i])
                {
                    a++;
                    break;
                }
            }
        }
        System.out.println(a);
    }
 
}

Measured memory_bytes: 76860
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int x,y;
    cin>>x>>y;
    rep(i,0,100){
        rep(j,0,100){
            if((i+j)==x and 2*(i+2*j)==y) return cout<<"Yes",0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int a,b,t;
  cin>>a>>b>>t;
  cout<<(t/a*b)<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int minZ = Integer.MIN_VALUE;
		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			if (x > minZ)
				minZ = x;
		}
		minZ++;

		int maxZ = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int y = sc.nextInt();
			if (y < maxZ)
				maxZ = y;
		}
		sc.close();

		for (int i = minZ; i <= maxZ; i++) {
			if (X < i && i <= Y) {
				System.out.println("No War");
				return;
			}
		}

		System.out.println("War");
	}
}

Measured memory_bytes: 23764
// BIT Binary Indexed Tree フェニック木 区間限定の和 1-indexed
#include <bits/stdc++.h>
using namespace std;

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 10000000000000 //10^13:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

// indexは1から始まる！
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0) {init(n);}
  void init(int nn) {n=nn;d.resize(nn+1);}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) { // [1,x]
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) { // [l,r)
    return sum(r-1) - sum(l-1);
  }
};
// BIT配列の宣言 N:配列数, n:各要素数+1;
// BIT<int> bit[N];
// rep(i,N) bit[i].init(n);

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

int n;
BIT<ll> bit;
ll memo[405][405]={};

ll dp(int l,int r){
    if(memo[l][r]!=0) return memo[l][r];
    if(r-l==1){ 
        memo[l][r]=0;
        return 0;
        }
    ll ret=INF;
    for(int m=l+1;m<r;m++){ 
        ret=min(ret,dp(l,m)+dp(m,r));
    }
    ret+=bit.sum(l,r);
    memo[l][r] = ret;
    return ret;
}

int main(){
    
    cin>>n;
    bit.init(n+1);
    int a;
    for(int i=1;i<=n;i++) {
        cin>>a;
        bit.add(i,a);
        }
    cout<<dp(1,n+1)<<endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
char in[30],in2[30];
bool chk[30];
int main()
{
	cin>>in;
	int N=strlen(in),i,j;
	for(i=0;i<N;i++)
	{
		chk[in[i]-'a']=true;
	}
	if(N!=26)
	{
		cout<<in;
		for(int i=0;i<26;i++)
		{
			if(chk[i])
				continue;
			cout<<char(i+'a')<<"\n";
			break;
		}
		return 0;
	} 
	for(int i=0;i<N;i++)
	{
		in2[i]=in[i];
	}
	if(!next_permutation(in2,in2+N))
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=0;i<N;i++)
	{
		cout<<in2[i];
		if(in2[i]!=in[i])
			break;
	}
	cout<<"\n";
 	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

x, y = map(int, input().split())

if (x+y)%3!=0 or x<1 or y<1:
    print(0)
    sys.exit()

m=(2*x-y)//3
n=x-2*m

def comb(n, r):
    #mod入り二項係数
    mod = 10**9+7
    N = 10**6 # 調整
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

print(comb(n+m,n))

Measured memory_bytes: 122048
def main():
    N, A, B = map(int,input().split())
    #print('N:%d A:%d B: %d' % (N,A,B)) 

    answer = []
    for i in range(N+1):
        s = sum( map(int,list(str(i)) )) # list of int -> sum
        if s >= A and s <= B: answer.append(i)
        #print('i:%d s:%d' % (i,s))
    print(sum(answer))

if __name__ == "__main__":
    main()

Measured memory_bytes: 41068
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
// #define ll long long
typedef long long ll;
typedef pair<int, int> P;

unsigned int len(unsigned int n)
{
    return n ? len(n/10)+1 : 0;
}

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

  int a,b;
  cin >> a >> b;
  int max_ = -200000;
  max_ = max(a+b, max_);
  max_ = max(a-b, max_);
  max_ = max(a*b, max_);
  cout << max_ << endl;

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll MAX_N = 55;
const ll MAX_SUM = 2555;
ll dp[MAX_N][MAX_N][MAX_SUM]; // dp[i][j][k]:i番目までからj枚を選んでkにする選び方の総数

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a;
    cin >> n >> a;
    vector<ll> x(n);
    rep(i, n)
    {
        cin >> x[i];
    }

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    rep(i, n)
    {
        rep(j, n)
        {
            rep(k, MAX_SUM)
            {
                if (dp[i][j][k]) {
                    dp[i + 1][j][k] += dp[i][j][k];
                    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 60672
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect
def main():
    n,d,a=map(int,input().split())
    XH=[list(map(int,input().split())) for i in range(n)]
    XH.sort()
    X,H=zip(*XH)
    right=[0]*n
    for i,x in enumerate(X):
        right[i]=bisect(X,x+2*d)
    damage=[0]*(n+1)
    ans=0
    for i,(x,h) in enumerate(XH):
        if i!=0:
            damage[i]+=damage[i-1]
        h-=damage[i]
        if h>0:
            cunt=-(-h//a)
            ans+=cunt
            damage[i]+=a*cunt
            damage[right[i]]-=a*cunt
    print(ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 70776
h, w = map(int, input().split())

c1 = (h + 1) // 2
c2 = h - c1

w1 = (w + 1) // 2
w2 = w - w1
if h == 1 or w == 1:
  print(1)
else:
  print(c1 * w1 + c2 * w2)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
string s[233];
int t,n;
int main(){
	for (char c='a';c<='c';c++)
		for (cin>>t;t--;) s[n++]+=c;
	for (;n>1;){
		sort(s,s+n);
		s[0]+=s[--n];
	}
	cout<<s[0];
}

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

int main() {
  
  int x,a,b;
  cin >> x >> a >> b;
  if(x>=b-a){
    if(b-a<=0){
      cout << "delicious" << endl;
    } else {
      cout << "safe" << endl;
    }
  } else {
    cout << "dangerous" << endl;
      
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
signed main(){
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double pi=acos(-1);
    int t=60*h+m;
    double deg=5.5*t;
    deg=min(deg,360-deg);
    double radeg=deg*pi/180;
    double cosc=cos(radeg);
    double ans=sqrt(a*a+b*b-2*a*b*cosc);
    printf("%.12lf\n",ans);
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long s;
    cin >> s;
    long long M = 1000000000;
    long long lo = 1, hi = 2*M;
    // lo is to low, hi is high enough
    while (hi - lo > 1) {
        long long mid = (hi + lo) / 2;
        if ((mid / 2) * ((mid+1) / 2) >= s) {
            hi = mid;
        } else {
            lo = mid;
        }
    }
    long long x2 = hi/2, y3 = (hi+1)/2;
    long long x3 = 1;
    long long y2 = x2*y3 - s;
    long long x1 = 0, y1 = 0;
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x, k, d;
    cin, x, k, d;
    x = abs(x);
    if (x / d >= k) {
        print(x - d * k);
        return 0;
    }
    k = k - x / d;
    x = x % d;
    if (k % 2 == 0) {
        print(x);
    } else {
        print(d - x);
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, K;
    cin>>N>>K;
    vector<ll> X(K);
    for(ll i=0; i<K; i++) 
        cin>>X[i];
    sort(X.begin(), X.end());
    if(N>=K) 
        cout<<0<<endl;
    else
    {
        vector<ll> D(K-1);
        for(ll i=0; i<K-1; i++)
            D[i]=X[i+1]-X[i];
        sort(D.begin(), D.end());
        ll ans=0;
        for(ll i=0; i<K-N; i++)     
            ans+=D[i];
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 4692
#include <iostream>
using namespace std;
int main(void){
    int a,b,c[13]={3,1,0,1,2,1,2,1,1,2,1,2,1};
    cin>> a>>b;
    if(c[a] == c[b]){
        cout <<"Yes" << endl;
    }
    else{
        cout << "No " << endl;
    }
    
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
public class Main {
	int N;
	int[] M,L;
	int[][] S,E;
	boolean[] used;
	public long dfs(int n){
		if(n == N){
			return 0L;
		}
		
		long ret = 0;
		boolean ok = true;
		for(int j = 0;j < M[n];j++){
			for(int s = S[n][j];s < E[n][j];s++){
				if(used[s]){
					ok = false;
					break;
				}
			}
			if(!ok)break;
		}
		if(ok){
			
			for(int j = 0;j < M[n];j++){
				for(int s = S[n][j];s < E[n][j];s++){
					used[s] = true;
				}
			}
			
			ret = Math.max(ret,dfs(n + 1) + L[n]);
			
			for(int j = 0;j < M[n];j++){
				for(int s = S[n][j];s < E[n][j];s++){
					used[s] = false;
				}
			}
		}
		ret = Math.max(ret,dfs(n + 1));
		return ret;
	}
	
	public void solve(){
		
		while(true){
			N = nextInt();
			if(N == 0)break;
			used = new boolean[23];
			M = new int[N];
			L = new int[N];
			S = new int[N][];
			E = new int[N][];
			for(int i = 0;i < N;i++){
				M[i] = nextInt();
				L[i] = nextInt();
				S[i] = new int[M[i]];
				E[i] = new int[M[i]];
				for(int j = 0;j < M[i];j++){
					S[i][j] = nextInt();
					E[i][j] = nextInt();
				}
			}
			out.println(dfs(0));
		}
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 35740
#include<bits/stdc++.h>
#define N 250000
using namespace std;

int L[N],R[N],ans=0;
int check[30]={0};

int main()
{
    char s[N];
    scanf("%s",s);
    int len=strlen(s);
    int now=26;
    R[0]=len-1;
    for(int i=len-1;i>=0;i--)
    {
        if(!check[s[i]-'a'])
        {
            now--;
            check[s[i]-'a']=1;

            if(now==0)
            {
                L[ans]=i;
                ans++;
                R[ans]=i-1;
                now=26;
                memset(check,0,sizeof(check));
            }
        }
    }
    L[ans]=0;
    int last=0;
    char ans_now;
    for(int i=ans;i>=0;i--)
    {
        int now=26;
        memset(check,0,sizeof(check));
        for(int j=last;j<=R[i];j++)check[s[j]-'a']=1;
        for(int j=0;j<26;j++)
        if(!check[j])
        {
            printf("%c",j+'a');
            ans_now=j+'a';
            break;
        }
        for(int j=last;j<len;j++)if(s[j]==ans_now)
        {
            last=j+1;
            break;
        }
    }
return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int a,b,c;
	cin >> a >> b >> c;
	int m = max(a,max(b,c));
	if (m == a) {
		cout << "A" << endl;
	}
	else if (m == b) {
		cout << "B" << endl;
	}
	else {
		cout << "C" << endl;
	}
	return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const int MOD = 1000000007;

int main() {
  ll Ans = 0;  // 回答：
  int N,K; cin >> N >> K; // 人数・菓子種類

  vector<int> Z(N,1);   // お菓子を持って無いずぬけ君フラグ

  vector<int> D(K); // その菓子を持っている人の数

  rep(i,K){
    cin >> D.at(i);
    rep(j,D.at(i)){   // 持っている人の調査
      int wk_Z;
      cin >> wk_Z;  // 持ってたずぬけ君
      Z.at(wk_Z-1) = 0;
    }

  }

  rep(i,N){
    if( Z.at(i) != 0 ){Ans++;}
  }
  cout << Ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main (){
  long long int n;
  cin>>n;
  vector<int> v(n);
  long long int i,k=0;
  for(i=0;i<n;i++){
    cin>>v[i];
    k+=v[i];
  }
  long long int m =2020202020,l=0;
  for(i=0;i<n;i++){
    l+=v[i];
    k-=v[i];
    m = min(abs(k-l),m);
  }
  cout<<m;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

//#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

int main() {
    int X; cin >> X;
    cout << 1000*(X/500) + 5*((X%500)/5) << endl; 
}


Measured memory_bytes: 256
N = gets.to_i
S = N.times.map { gets.chomp }

counter = Hash.new(0)

S.each do |s|
  counter[s.chars.sort] += 1
end

ans = 0

counter.each_value do |v|
  next if v <= 1

  ans += v * (v - 1) / 2
end 

puts ans


Measured memory_bytes: 75132
fn read_line<T>() -> Vec<T>
where T: std::str::FromStr, <T as std::str::FromStr>::Err : std::fmt::Debug {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn main() {
    let x: Vec<i32> = read_line();
    let result = if x[1] > 1 {
        x[0] - x[1]
    } else {
        0
    };

    println!("{}", result);
}


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

int main() {
    int N,M;
    int X[1000]={0};
    string s[1000];
    string t[1000];
    cin >>N;
    for(int i=0;i<N;i++){
        cin >>s[i];
    }
    cin >>M;
    for(int i=0;i<M;i++){
        cin >>t[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(s[i]==s[j]){
                X[i]++;
            }
        }
        for(int j=0;j<M;j++){
            if(s[i]==t[j]){
                X[i]--;
            }
        }
    }
        int ans=0;
    for(int i=0;i<N;i++){
            if(ans<=X[i]){
                ans=X[i];
            }
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 256