akhauriyash/Code-Regression huggingface dataset:
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int N, K;

    AtCoder(FastScanner sc) {
        N = sc.nextInt();
        K = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(N % K == 0 ? 0 : 1);
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
    long long a,b,x;
    long long min,max;
    long long count=0;
    cin>>a>>b>>x;
    a%x==0?min=a/x:min=a/x+1;
    max=b/x;
    
    cout<<max-min+1<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

ll solve(ll n, int w[3], int v[3]) {
	vector<vector<ll>>dp(4, vector<ll>(n+1, 0));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j <= n; j++) {
			if (j - w[i] >= 0) {
				dp[i+1][j] = max(dp[i+1][j - w[i]] + v[i], dp[i][j]);
			}
			else dp[i+1][j] = dp[i][j];
		}
	}
	return dp[3][n] + n;
}

int main() {
	while (cin >> N) {
		int a[3];
		int b[3];
		cin >> a[0] >> a[1] >> a[2];
		cin >> b[0] >> b[1] >> b[2];
		int v[3];
		for (int i = 0; i < 3; i++)v[i] = b[i] - a[i];
		N = solve(N, a, v);
		for (int i = 0; i < 3; i++)v[i] = a[i] - b[i];
		N = solve(N, b, v);
		cout << N << endl;
	}
}


Measured memory_bytes: 976996
L = list(map(int,input().split()))
L.sort()

once = L[2]-L[1]
dif = L[2] - once - L[0]

if dif % 2 == 0:
    ans = once + dif // 2
else:
    dif += 1
    ans = 1 + once + dif // 2 

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 1};
int dx[4] = {0, 1, 0, 1};

const ll MAX_N = 100000;
ll n, m;
ll A[MAX_N];

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n >> m;
	rep(i,0,n) {
		cin >> A[i];
	}
	priority_queue<ll> Q;
	rep(i,0,n) {
		Q.push(A[i]);
	}
	rep(i,0,m) {
		ll a = Q.top();
		Q.pop();
		Q.push(a/2);
	}
	ll ret = 0;
	rep(i,0,n) {
		ret += Q.top();
		Q.pop();
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  int cnt = (N-1)*(N-2)/2;
  if(cnt < K){
    cout << -1 << endl;
    return 0;
  }

  vector<pair<int, int>> ans;
  FOR(i, 1, N) ans.emplace_back(0, i);

  FOR(i, 1, N){
    FOR(j, i+1, N){
      if(cnt-- > K) ans.emplace_back(i, j);
    }
  }


  cout << ans.size() << endl;
  REP(i, ans.size()){
    cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
  }


  return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var inp = Console.ReadLine().ToCharArray();
        int ans = int.MaxValue;
        for (char c = 'a'; c <= 'z'; c++)
        {
            if (!inp.Contains(c)) continue;
            var s = new string(inp).ToCharArray();
            while (s.Distinct().Count() > 1)
            {
                for (int i = 0; i < s.Length - 1; i++)
                {
                    if (s[i + 1] == c) s[i] = c;
                }
                s = s.Where((f, g) => g < s.Length - 1).ToArray();
            }
            ans = Math.Min(ans, inp.Length - s.Length);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13280
class BinaryIndexedTree:
    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i - 1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i - 1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r - 1)
        if l: res -= self.sum(l - 1)
        return res

    def update(self, i, x):
        """ 値の更新：添字i, 値x """
        self.add(i, x - self.get(i))

    def bisearch_fore(self, l, r, x):
        """ 区間[l, r]を左から右に向かってx番目の値がある位置 """
        l_sm = self.sum(l - 1)
        ok = r + 1
        ng = l - 1
        while ng + 1 < ok:
            mid = (ok + ng) // 2
            if self.sum(mid) - l_sm >= x:
                ok = mid
            else:
                ng = mid
        if ok != r + 1:
            return ok
        else:
            return 1<<60

def resolve():
    N, Q = map(int, input().split())
    A = list(map(int, input().split()))


    pi = [-1] * (N + 1)  # 各数について最後に出てきた場所
    ps = [[] for i in range(N)]

    for i in range(N):
        l = pi[A[i]]
        if l != -1:
            ps[l].append(i)
        pi[A[i]] = i

    qs = [[] for i in range(N)]
    for i in range(Q):
        l, r = map(lambda x:int(x)-1, input().split())
        qs[l].append((r, i))

    BIT = BinaryIndexedTree(N + 1)
    ans = [0] * Q

    for x in range(N - 1, -1, -1):
        for y in ps[x]:
            BIT.add(y, 1)

        for r, i in qs[x]:
            ans[i] = (r - x + 1) - BIT.sum(r)

    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()


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

int main(){
int x;
cin >>x;
long long ans =1;
for(int i=2;i<=x+10;i++){
  long long a =i*i;
  while(1){
    if(a>x){
      break;
    }    
    ans = max(ans,a);
    a*=i;

  }
}
cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    int b;
    cin>>a;
    cin>>b;
    if((int)(b/a)*a == b){
        cout<<a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
S = input()
j = 0
for i in range(26):
  if S == Alpha[i]:
    j = i + 1
    break
print(Alpha[j])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
 
string ex(long long int a){
	string s="000000000000000000000000000000";
	for(int i=0;i<30;i++){
		if(a&1<<i){
			s[29-i]='1';
		}
	}
	
	//cout<<s<<endl;
	
	return s;
}
 
int main(){
	long long int n,k;
	cin>>n>>k;
	
	string s1;
	s1=ex(k);
	string s2="000000000000000000000000000000";
	string s3="000000000000000000000000000000";
	
	
	long long int cnt=0;
	for(int i=0;i<30;i++){
		if(cnt==0&&s1[i]=='1'){
			cnt++;
		}else if(cnt==1){
			s3[i]='1';
		}
	}
	
	//cout<<s1<<endl;
	//cout<<s2<<endl;
	//cout<<s3<<endl;
	
	
	long long int ans1=0;
	long long int ans2=0;
	long long int ans3=0;
	
	long long int ans=0;
	
	vector<string> a(n);
	vector<long long int> b(n);
	int flag;
	for(int i=0;i<n;i++){
		long long int x;
		cin>>x>>b[i];
		a[i]=ex(x);
		
		flag=0;
		for(int j=0;j<30;j++){
			if(s1[j]=='0'&&a[i][j]=='1'){
				flag=1;
				break;
			}
		}
		if(flag==0)ans1+=b[i];
		
		/*
		for(int l=0;l<15;l++){
			s2="000000000000000000000000000000";
			int cnt=0;
			for(int m=0;m<30;m++){
				if(cnt<=l&&s1[m]=='1'){
					cnt++;
					s2[m]='1';
				}else if(cnt==l+1&&s1[m]=='1'){
					cnt++;
				}else if(cnt>l+1){
					s2[m]='1';
				}
			}
			
			//cout<<s2<<endl;
			
			ans2=0;
			flag=0;
			for(int j=0;j<30;j++){
				if(s2[j]=='0'&&a[i][j]=='1'){
					flag=1;
					break;
				}
			}
			if(flag==0)ans2+=b[i];
			ans=max(ans,ans2);
		}
		
		*/
		
		
		flag=0;
		for(int j=0;j<30;j++){
			if(s3[j]=='0'&&a[i][j]=='1'){
				flag=1;
				break;
			}
		}
		if(flag==0)ans3+=b[i];
	}
	
	for(int l=0;l<30;l++){
		s2="000000000000000000000000000000";
		int cnt=0;
		for(int m=0;m<30;m++){
			if(cnt<=l&&s1[m]=='1'){
				cnt++;
				s2[m]='1';
			}else if(cnt==l+1&&s1[m]=='1'){
				cnt++;
			}else if(cnt>l+1){
				s2[m]='1';
			}
		}
		//cout<<s2<<endl;
		ans2=0;
		for(int i=0;i<n;i++){
			//cout<<s2<<endl;
			
			flag=0;
			for(int j=0;j<30;j++){
				if(s2[j]=='0'&&a[i][j]=='1'){
					flag=1;
					break;
				}
			}
			if(flag==0)ans2+=b[i];
		}
		//cout<<ans2<<endl;
		ans=max(ans,ans2);
	}
	
	ans=max(ans1,max(ans,ans3));
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 10112
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3056
#include<iostream>
using namespace std;
int N;
void dfs(int id,string s,int ap)
{
	if(id==N)
	{
		cout<<s<<endl;
		return;
	}
	for(int i=0;i<=ap;i++)
	{
		string t=s;
		t+=(char)(i+'a');
		dfs(id+1,t,ap+(i==ap));
	}
}
main()
{
	cin>>N;
	dfs(0,"",0);
}


Measured memory_bytes: 1536
import sys
s = int(input())
a = s //100
b = s % 100
mmyy = 0
yymm = 0

if 1<=a <= 12:
    if 1<=b <= 12:
         yymm = 1
         mmyy = 1
    else:
        mmyy = 1
elif 0 <= a <= 99:
    if 1<=b <= 12:
         yymm = 1

if mmyy == 1 and yymm == 1:
    print("AMBIGUOUS")
elif mmyy == 1:
    print("MMYY")
elif yymm == 1:
    print("YYMM")
else:
    print("NA")

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

int main() {
  int d[3];

  for (int i{}; i < 3; ++i) {
    cin >> d[i];
  }
  sort(d, d+3);
  int ans = d[2] * 10 + d[1] + d[0];

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


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    prt(A*B)

    return 0;
}


Measured memory_bytes: 3496
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String[] ss = S.split("");
		String[] tt = T.split("");
		int res = 0;
		for (int i = 0; i < ss.length; i++) {
			if (!ss[i].equals(tt[i])) {
				res++;
			}
		}
		System.out.println(res);
	}
}

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

int main(){
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  for(int i = 0; i < N; i++){
    cout << S.at(i) << T.at(i);
  }
  cout << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int count = 0;
    std::string S,T;
    cin >> S >> T;
    for (int i = 0; i < 3; ++i) {
        if(S[i] == T[i]){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<deque>
#include<cstdlib>
using namespace std;
const int md=1e9+7;
int qmul(int x,int p)
{
	if(p==0)return 1;
	if(p==1)return x;
	int res=qmul(x,p>>1);
	res=1LL*res*res%md;
	if(p&1)res=1LL*res*x%md;
	return res;
}
vector<int>v[200010];
int ans;
int n;
int dep[200010];
int s[200010];
struct abc{
	int a,b,c;
	abc(int _a,int _b,int _c):a(_a),b(_b),c(_c){}
};
deque<abc>dp[200010];
void dfs(int x)
{
	s[dep[x]]++; 
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		dep[y]=dep[x]+1;
		dfs(y);
	}
}
void solve(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		solve(y);
		if(dp[y].size()>dp[x].size())
		{
			swap(dp[x],dp[y]);
		}
	}
	int mx=0,ta=0,tb=0,tc=0;
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		mx=max(mx,(int)dp[y].size());
		for(int j=0;j<dp[y].size();j++)
		{
			ta=1LL*dp[x][j].a*dp[y][j].a%md;
			tb=(1LL*dp[x][j].a*dp[y][j].b%md+1LL*dp[x][j].b*dp[y][j].a%md)%md;
			tc=(1LL*dp[x][j].b*dp[y][j].b%md+1LL*dp[x][j].c*(dp[y][j].a+dp[y][j].b)%md)%md;
			dp[x][j].a=ta;
			dp[x][j].b=tb;
			dp[x][j].c=tc;
		}
	}
	for(int i=0;i<mx;i++)
	{
		dp[x][i].a+=dp[x][i].c;
		if(dp[x][i].a>=md)dp[x][i].a-=md;
		dp[x][i].c=0;
	}
	dp[x].push_front(abc(1,1,0));
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		v[x].push_back(i);
	}
	dfs(0);
	solve(0);
	for(int i=0;i<dp[0].size();i++)
	{
		ans+=1LL*dp[0][i].b*qmul(2,n+1-s[i])%md;
		if(ans>=md)ans-=md;
	}
	printf("%d",ans);
	return 0;
} 

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

int main(){
	long long n,div=1,x,ket,ans=0;
	long long ne[11][11]={};
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i/(div*10)>0){
			div*=10;
		}
		ne[i%10][i/div]++;
		/*if(i%10!=0){
			if(i%10==i/div){
				x=i%10;
				while(1){
					if(x>n){
						break;
					}
					ans++;
					if(x==i%10){
						x=x*10+i%10;
					}else{
						x=(x-i%10)*10+i%10;
					}
				}
			}else{
				x=(i%10)*10;
				ket=1;
				while(1){
					if(x+i/div>n){
						break;
					}
					ans+=ket;
					ket*=10;
					x*=10;
				}
			}
		}*/
	}
	div=1;
	for(int i=1;i<=n;i++){
		if(i/(div*10)>0){
			div*=10;
		}
		ans+=ne[i/div][i%10];
		/*cout<<ans<<endl;
		cout<<ne[i%10][i/div]<<endl;*/
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import groupby

s = list(input())
ss = s * 2
k = int(input())
x = 0
y = 0
if len(s) == 1:
    print(k // 2)
elif s.count(s[0]) == len(s):
    print(len(s) * k //2)
else:  
    for key, value in groupby(s):
        x += len(list(value)) // 2
    for key, value in groupby(ss):
        y += len(list(value)) // 2
    print((y-x) * (k-1) + x)


Measured memory_bytes: 3064
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

count = 0
for i in range(N):
    if X[i][0] ** 2 + X[i][1] ** 2 <= D ** 2:
        count += 1
    else: continue
print(count)

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

int main() {
  
  int N; string S; cin >> N >> S; int ans = 0;
  
  for (int i = 0; i < N - 2; i++) {
    if (S.substr(i, 3) == "ABC") {
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

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

x2=0
x4=0
x1=0
for x in a:
  if x%2==0:
    x2+=1
  if x%4==0:
    x4+=1
  if x%2==1:
    x1+=1
    
if x4+x1==n:
  if x4>=x1-1:
    print('Yes')
  else:
    print('No')
  
else:
  if x4>=x1:
    print('Yes')
  else:
    
    print('No')


Measured memory_bytes: 19820
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

int main() {
  ll N;
  string S;
  cin >> N >> S;

  unordered_map<ll, ll> um;
  for (ll i = 0; i < N; i++) {
    ll tmp = S[i] - '0';
    um[tmp] = i;
  }

  ll ans = 0;
  unordered_map<ll, ll> found;

  for (ll i = 0; i <= 9; i++) {
    for (ll j = 0; j <= 9; j++) {
      ll pos;
      bool found_i = false;
      bool found_j = false;
      for (ll k = 0; k < N; k++) {
        ll tmp = S[k] - '0';
        if (!found_i && (tmp == i)) {
          found_i = true;
        } else if (found_i && (tmp == j)) {
          found_j = true;
          pos = k;
          break;
        }
      }  // k
      if (found_j) {
        for (ll x = 0; x <= 9; x++) {
          if (um.count(x) != 0 && pos < um[x]) ans++;
        }  // x
      }
    }  // j
  }    // i

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# http://hos.ac/slides/20130319_enumeration.pdf
class CombP
  P = 10**9 + 7
  def initialize(n)
    @inv = Array.new(n, 0)
    self.inv(n)
    @fac = Array.new(n, 0)
    @facInv = Array.new(n, 0)
    self.fact(n)
  end
  def inv(n)
    @inv[1] = 1
    (2..n).each do |i|
      @inv[i] = P - ((P / i) * @inv[P % i]) % P
    end
  end
  def fact(n)
    @fac[0] = 1
    @facInv[0] = 1
    (1..n).each do |i|
      @fac[i] = (@fac[i-1] * i) % P
      @facInv[i] = (@facInv[i-1] * @inv[i]) % P
    end
  end
  def choose(n, k)
    if !(0 <= k && k <= n)
      return 0
    end
    return (((@fac[n] * @facInv[k]) % P) * @facInv[n - k]) % P
  end
end

def find_dup(a, n)
  aa = Array.new(n+2)
  a.each_with_index do |e, i|
    if aa[e].nil?
      aa[e] = i
    else
      return i - aa[e]
    end
  end
end

if $0 == __FILE__
  n = gets.chomp.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  d = find_dup(a, n)
  combp = CombP.new(n+2)

  (1..(n+1)).each do |i|
    puts (combp.choose(n + 1, i) - combp.choose(n-d, i - 1)) % CombP::P
  end

end



Measured memory_bytes: 14732
import heapq
N,M = map(int,input().split())
list_A = list(map(int,input().split()))	
list_A = list(map(lambda x: int(x)*(-1),list_A))

#print(list_A)

#heapifyが動作が重い。for文の中に入れるとTLE。
heapq.heapify(list_A) #list_Aを優先度付きキューに
for i in range(M):
  
  target = heapq.heappop(list_A)
  #print("after heappop",list_A)
  
  '''負の要素の切り捨て除算は切り捨てがマイナスの方に
  行くため少しだけややこしい。'''
  target = (-1)*((-target) // 2)
  heapq.heappush(list_A, target)  # 要素の挿入
  #print("No.",i,"change finished",list_A)

print((-1)*sum(list_A))




Measured memory_bytes: 92408
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


string N;
int mem[10][2][2][2][2][2][2];


int search(int k = 0, bool t =  true, bool x = false, bool y = false, bool z = false, bool w = false, bool v = true){
	if(k == SIZE(N)) return x && y && z && (!w);
	int r = t ? N[k]-'0' : 9;
	int &res = mem[k][t][x][y][z][w][v];
	if(res != -1) return res;
	res = 0;
	repe(i, 0, r) res += search(k+1, t && i == r, x || i == 3, y || i == 5, z || i == 7, (w || (i != 3 && i != 5 && i != 7)) && !(v && i == 0), v && i == 0);
	return res;
}


signed main(){
	cin >> N;

	rep(a, 0, 10)
		rep(b, 0, 2)
		rep(c, 0, 2)
		rep(d, 0, 2)
		rep(e, 0, 2)
		rep(f, 0, 2)
		rep(g, 0, 2)
		mem[a][b][c][d][e][f][g] = -1;

	cout << search() << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007


#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll ans=0;
  int n,d,x,a;
  cin>>n>>d>>x;
  rep(i,n){
    cin>>a;
    ans+=(d-1)/a+1;
  }
  cout<<ans+x<<endl;
  return 0;
}


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

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;i<100004;++i){
		bool flag = true;
		for(int j=0;j<prime.size();++j){
			if(i % prime[j]==0){
				flag = false;
				break;
			}
		}
		if(flag)prime.push_back(i);
	}
	int k,res=0,c=0;
	cin >> k;
	while(res<k){
		res = prime[c];
		c++;
	}
	cout << res << endl;
}

Measured memory_bytes: 384
def luggage_num(P):
    i = 0
    for _ in range(k):
        t = 0
        while t + w[i] <= P:
            t += w[i]
            i += 1
            if i == n:
                return n
    return i

n, k = map(int, input().split())
w = []
for _ in range(n):
    w.append(int(input()))

right = n * max(w)
left = 0

while right - left > 1:
    mid = int((right + left) / 2)
    if luggage_num(mid) >= n:
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 9556
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m, d;
	cin >> n >> m >> d;
	double k = d == 0 ? 1.0 / n : 2.0 * (n - d) / n / n;
	cout << setprecision(20) << fixed << k * (m - 1) << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
#define INF 1000000007
using namespace std;
signed main(){
    int n;
    cin>>n;
    int x;
    cin>>x;
    int l[114514];
    int c=1;
    int d=0;
    for(int i=0;i<n;i++){
        
        cin>>l[i];
        d+=l[i];
        if(d<=x)c++;
    }
    cout<<c<<endl;
    return 0;
}




Measured memory_bytes: 384
/*
𝓐𝓾𝓽𝓱𝓸𝓻:-
𝓢𝓪𝓾𝓻𝓪𝓫𝓱𝓼𝓱𝓪𝓭𝓸𝔀
------------------------
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopb(i,a,b) for(int i=a;i>=b;i--)
#define fore(name)  for(auto it=name.begin();it!=name.end();it++)
#define w  int t;cin>>t;while(t--)
#define pb(x) push_back(x)
#define in(y) insert(y)
#define bitscount 32
#define make(x,y) make_pair(x,y)
#define LOAD_FACTOR_set(name) name.reserve(32768);name.max_load_factor(0.25);
#define LOAD_FACTOR_map(name) name.reserve(1024);name.max_load_factor(0.25);
#define lcm(a,b) ((a*b))/(__gcd(a,b))
#define int long long int
#define REDBULL ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define all(x) (x).begin(), (x).end()


typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ordered_justset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

struct HASH {
	size_t operator()(const pair<int, int>&x)const {
		return ((int)x.first) ^ (((int)x.second) << 32);
	}
};
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		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);
	}
};
typedef pair<int, int> pi;
#define UNMAP(name) unordered_map<int,int,custom_hash> name
#define MAX 10000000000000
void solve()
{
	int n, x, t;
	cin >> n >> x >> t;
	int check = n / x;
	if (n % x != 0)
		check++;
	int ans = check * t;
	cout << ans << endl;

}
int32_t main()
{
	REDBULL
	// w
	solve();

	return 0;
}

Measured memory_bytes: 3688
N,K=map(int,input().split())
List = list(map(int, input().split()))
INF = 10000000000
expList = [INF]*1001
def expectationF(num):
  if expList[num] == INF:
    exp = 0
    for i in range(1,num+1):
      exp += i/num
    expList[num] = exp
  return expList[num]

res = 0
mid = 0
midList=[]
for i in range(N):
  if i>=1:
    midList.append(expectationF(List[i])+midList[i-1])
  else:
    midList.append(expectationF(List[i]))
m=K-1
for j in range(N-m):
  if j == 0:
    mid = midList[j+m]
  else:
    mid = midList[j+m]- midList[j-1] 
  res = max(res,mid)
print(res)

Measured memory_bytes: 32276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll dp[10][1001000];
ll n, m;
ll hp[110];
vector<ll> mp[2];
vector<ll> d[2];

int main() {
	while (cin >> n&&n) {
		mp[0].clear();
		mp[1].clear();
		d[0].clear();
		d[1].clear();
		rep(i, n)cin >> hp[i];
		cin >> m;
		rep(i, m) {
			string s;
			ll mpp, dd;
			cin >> s >> mpp >> s >> dd;
			if (s == "All") {
				mp[0].push_back(mpp);
				d[0].push_back(dd);
			}
			else {
				mp[1].push_back(mpp);
				d[1].push_back(dd);
			}
		}
		rep(i, 1001000) {
			dp[0][i] = INF;
			dp[1][i] = INF;
		}
		dp[0][0] = 0;
		dp[1][0] = 0;
		rep(i, mp[0].size()) {
			rep(j, 1001000) {
				if (j + d[0][i] < 1001000) {
					dp[0][j + d[0][i]] = min(dp[0][j + d[0][i]], dp[0][j] + mp[0][i]);
				}
			}
		}
		rep(i, mp[1].size()) {
			rep(j, 1001000) {
				if (j + d[1][i] < 1001000) {
					dp[1][j + d[1][i]] = min(dp[1][j + d[1][i]], dp[1][j] + mp[1][i]);
				}
			}
		}
		rep(i, 2) {
			for (int j = 1000000; j >= 0; j--) {
				dp[i][j] = min(dp[i][j], dp[i][j + 1]);
			}
		}
		//rep(i, 2) {
		//	rep(j, 50) {
		//		if (dp[i][j] == INF)cout << -1 << " ";
		//		else cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		ll ans = INF;
		rep(i, 1001000) {
			ll sum = dp[0][i];
			rep(j, n) {
				if (hp[j] - i >= 0)sum += dp[1][hp[j] - i];
			}
			ans = min(ans, sum);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 18772
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 100010
string a[2];
int t[2][N];

int main(){
	cin>>a[0]>>a[1];
	rep(i, 2) rep(j, a[i].size()){
		t[i][j+1] = t[i][j]+(a[i][j]=='A'?1:2);
	}
	int q;
	cin>>q;
	while(q--){
		int a, b, c, d;
		cin>>a>>b>>c>>d;
		a--; c--;
		if((-t[0][a]+t[0][b]+t[1][c]-t[1][d])%3==0)	cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1664
N, K = map(int, input().split())
h = []
for _ in range(N):
    h_ = int(input())
    h.append(h_)
    
h.sort()
s = [0]*(N-K+1)
for i in range(N-K+1):
    s[i] = h[i+K-1] - h[i]
    
print(min(s))

Measured memory_bytes: 11036
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String a = stdIn.next();
		String b = stdIn.next();
		String c = stdIn.next();
		
		if(a.charAt(a.length()-1)==b.charAt(0) && b.charAt(b.length()-1)==c.charAt(0)) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;	
	int t = (int) ceil(1.0*n / 1.08);
	for(int i = t-1000;i<=t+1000;i++){
		int k = floor(1.08*t);
		if(k == n){
			cout << t << endl;
			return 0;
		}
	}
	puts(":(");
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

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

int main()
{
	char A,B;
	cin >> A >> B;
	if (A < B) cout << "<" << endl;
	else if (A == B) cout << "=" << endl;
	else cout << ">" << endl;
	return 0;
}

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

int main()
{
int i;
int j;
int N;
int M;

	cin >> N;
	cin >> M;

	i = M / N;
	for( ; i >= 1; i-- )
	{
		if( M % i == 0 )
		{
			cout << i << endl;

			return 0;
		}
	}

	return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
int main(){

  
  int x,y,tmp;
  

  while(1){
   scanf("%d%d",&x,&y);
   if(x == 0 && y == 0){
    break;
 } else if(x > y){
   tmp = x;x = y; y = tmp ;
 }
   printf("%d %d\n",x,y);
  
 }


  return 0;
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int main(){
    ll n,m; cin >> n >> m;
    vector<vector<int>> s(m,vector<int>(n,0));
    vector<int> p(m);
    rep(i,m){
        ll k; cin >> k;
        rep(j,k){
            int temp;cin >> temp;
            temp--;
            s[i][temp] = 1;
        }
    }
    rep(i,m)cin >> p[i];
    auto check = [&](ll x, int y) -> bool{
        bool ok = true;
        int count = 0;
        rep(i,n){
            ll temp = x >> i;
            if(s[y][i])if(temp & 1)count++;
        }
        if(count%2 != p[y])ok = false;
        // if(ok)print("ok",x,y);
        return ok;
    };

    ll res = 0;
    rep(i,(1 << n)){
        bool ok = true;
        rep(j,m){
            if(!check(i,j))ok = false;
            // ok = check(i,j);
        }
        if(ok)res++;
    }

    cout << res << endl;
    return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;
  vector<int> apple(N);
  int flavor=0;
  for(int i=0; i<N; i++){
    apple[i]=L+i;
    flavor+=apple[i];
  }
  int M;
  int a;
  for(int i=0; i<N; i++){
    int x=abs(apple[i]);
    if(i==0){
      M=x;
      a=0;
    }
    if(x<M){
      M=min(M,x);
      a=i;
    }
  }
  cout << flavor-apple[a] <<endl; 
  
    
}

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

int main() {
  int N;
  cin >> N;
  int a;
  a=N%10;
  if(a==3)
    cout << "bon" << endl;
  else if (a==0 || a==1 || a==6 || a==8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N],sum;

char s[N];

int main()
{
	fast;
	int a=0,b=0;
	cin>>s+1;
	n=strlen(s+1);
	int q=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='1')
			a++;
		else
			b++;
	}
	cout<<min(a,b)*2;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=2019;
const ll LINF=1LL<<60;
const int INF=1<<30;

//繰り返し二乗法
ll mod_pow(ll x,ll n){
	ll res = 1;
	while(n > 0){
		if(n & 1){
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main(){
	string s;cin>>s;
	ll n = s.size();
	ll tmp = 0;
	ll ans = 0;
	vector<int> a(2019,0);
	a[0] = 1;
	ll bit = 0;
	for(ll i = n - 1; i >= 0; i--) {
		tmp = tmp + (s[i] - '0') * mod_pow(10,bit);
		tmp %= 2019;
		a[tmp]++;
		bit++;
	}
	for(int i = 0; i < 2019; i++) {
		ans += a[i] * (a[i] - 1) / 2;
	}

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

Measured memory_bytes: 3724
#include <stdio.h>

int main()
{
  char kigo;
  int a,b;

  while(kigo != '?'){
    scanf("%d %c %d",&a,&kigo,&b);
    if(kigo == '+') printf("%d\n",a+b);
    else if(kigo == '-') printf("%d\n",a-b);
    else if(kigo == '*') printf("%d\n",a*b);
    else if(kigo == '/') printf("%d\n",a/b);
  }

  return 0;
}

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

vector<int> g[111111];
int p[111111];
ll ans;
ll n,k;

int dfs(int n){
  int ma=0;
  for(int i=0;i<g[n].size();i++){
    ma=max(ma,dfs(g[n][i]));
  }
  if(n==0)return 0;
  if(ma==k-1&&p[n]!=0){
    ans++;
    return 0;
  }
  return ma+1;
}

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

  for(int i=0;i<n;i++){
    cin>>p[i];
    p[i]--;
    if(i==0&&p[i]!=0){
	 ans++;
	 p[i]=0;
    }
    if(i){
	 g[p[i]].pb(i);
    }
  }

  dfs(0);

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




Measured memory_bytes: 12672
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int a[15][15];

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n, m, x;
    cin >> n >> m >> x;

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

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

    int res = 1e9 + 7;

    for (int i = 1; i < (1 << n); i++) {
        vector< int> level(m);
        int money = 0;

        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                money += c[j];
                for (int k = 0; k < m; k++) level[k] += a[j][k];
            }
        }
        if (*min_element(begin(level), end(level)) >= x) {
            res = min(res, money);
        }
    }

    if (res > 1e9) cout << -1;
    else cout << res << endl;
}

Measured memory_bytes: 3660
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      long m = sc.nextInt();
      long n = sc.nextInt();

      long k = 0;
      boolean stop = false;

      if(m<n) {
        k = m;
      }
      else{
        k = n;
      }
        for(;k>=1&&stop==false;k--){
          if(n%k==0&&m%k==0){
            stop=true;
      }

     }

      long l = n*m/(k+1);
        System.out.println(l);
}
}


Measured memory_bytes: 23764
import itertools

n,m,q = map(int,input().split())
li=[list(map(int,input().split())) for i in range(q)]
ans = 0

num_li = itertools.combinations_with_replacement(range(1,m+1),n)

for i in num_li:
    temp = 0
    for j in li:
        a,b,c,d = j
        if i[b-1] - i[a-1] == c:
            temp += d
    ans = max(ans,temp)
print(ans)

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

unsigned long long inverse[100100];
const unsigned long long p = 1000000007;
unsigned long long h, w, a, b;
unsigned long long comb1[200100][2];

unsigned long long beki(unsigned long long i, unsigned long long n)
{
    if(n == 0){
        return 1;
    }
    unsigned long long ans = beki(i, n / 2);
    ans = ans * ans;
    ans = ans % p;
    if(n % 2 == 1){
        ans = ans * i;
        ans = ans % p;
    }
    return ans;
}
unsigned long long comb(unsigned long long n, unsigned long long r)
{
    int check = 0;
    if((n == r) || (r == 0)){
        return 1;
    }
    if(n == (r + 1)){
        return (n % p);
    }
    if(n != (h - a - 1 + b)){
        check = 1;
    }
    if(comb1[r][check] != -1){
        return comb1[r][check];
    }
    comb1[r][check] = comb(n, r - 1) * (n - r + 1);
    if(comb1[r][check] < comb(n, r - 1)){
        cout << "error" << endl;
    }
    if(comb1[r][check] == 0){
        cout << r << " " << check << endl;
        while(1);
    }
    comb1[r][check] = comb1[r][check] % p;
    comb1[r][check] = comb1[r][check] * inverse[r];
    comb1[r][check] = comb1[r][check] % p;
    //cout << comb1[r][check] << endl;
    return comb1[r][check];
}

int main()
{
    cin >> h >> w >> a >> b;
    if((h - a) > (w - b)){
        swap(h, w);
        swap(a, b);
    }
    for(unsigned long long i = 1; i <= 100050; i++){
        inverse[i] = beki(i, p - 2);
    }
    for(int i = 1; i <= 100050; i++){
        comb1[i][0] = -1;
        comb1[i][1] = -1;
    }
    //cout << inverse[11] << endl;
    comb1[0][0] = 1;
    comb1[0][1] = 1;
    unsigned long long ans = 0;
    for(int i = 0; i < (h - a); i++){
        ans += comb(h - a - 1 + b, i) * comb(w - b - 1 + a, (h - 1 - i));
        ans = ans % p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    s=STR()
    t=STR()
    ct=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            ct+=1
    print(ct)


if __name__ == '__main__':
    do()

Measured memory_bytes: 9412
#include <cstdio>
#include <stack>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int h[100000];
int l[100000];
int r[100000];
int main() {
  while(true) {
    scanf("%d",&n);
    if (n==0) break;
    for(int i=0;i<n;++i) {
      scanf("%d", &h[i]);
    }
    long long answer = 0;
    stack<int> S;
    for(int i=0;i<n;++i) {
      while(!S.empty() && h[S.top()] >= h[i]) S.pop();
      if (S.empty()) {
        l[i] = 0;
      } else {
        l[i] = S.top() + 1;
      }
      S.push(i);
    }
    S=stack<int>();
    for(int i=n-1;i>=0;--i) {
      while(!S.empty() && h[S.top()] >= h[i]) S.pop();
      if (S.empty()) {
        r[i] = n-1;
      } else {
        r[i] = S.top() - 1;
      }
      S.push(i);
    }
     
    for(int i=0;i<n;++i) {
      answer = max(answer, 1ll * h[i] * (r[i]- l[i] +1));
    }
     
    printf("%lld\n", answer);
break;
  }
  return 0;
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

  int ans = 0;
  for (int i = 1; i < n; i++) {
    map<char,int> m;
    int cnt = 0;
    REP(j,i) m[s[j]]=1;
    for (int j = i; j < n; j++) {
      if (m[s[j]]!=1) continue;
      m[s[j]] = 2;
      cnt++;
    }
    ans = max(ans,cnt);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: u64,
        m: u64,
        mut a: [u64; n],
    }

    a.sort();
    a.reverse();
    let sum: u64 = a.iter().sum();
    let ans = if a[(m - 1) as usize] as f64 >= sum as f64 / (4 * m) as f64 {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  b = 1;
  for (int i = 2; i < a; i++) {
    for (int j = 2; a >= pow(i, j); j++) {
      int c = pow(i, j);
      if (c > b) b = c;
    }
  }
  cout << b << endl;
}

Measured memory_bytes: 256