akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
class Main {
    public static void main(String[] arg){
        Scanner in = new Scanner(System.in);
        while(true){
            int x = in.nextInt();   
            int y = in.nextInt();
            if (x == 0 && y == 0)break;
            StringBuilder sb = new StringBuilder();
            for(int i = 0;i < x;i++){
                for(int j=0;j < y;j++){
                    sb.append("#");
                }
                sb.append("\n");
            }
            System.out.println(sb);
        }   
    }
}

Measured memory_bytes: 20880
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    string S; cin >> S;
    map<char,int> m,m2;
    int A[N],B[N+2];
    B[N]=B[N+1]=0;
    int cnt;
    vi G[10];
    int pos[10];
    rep(i,10) pos[i]=-1;
    rep(i,N){
        G[(int)S[i]-'0'].push_back(i);
        if(m[S[i]]==0) {
            pos[(int)(S[i]-'0')]=i;
        }
        m[S[i]]++;
    }
    cnt=0;
    per(i,N){
        if(m2[S[i]]==0){
            cnt++;
        }
        m2[S[i]]++;
        B[i]=cnt;
    }
    int ans=0;
    rep(i,10){
        if(pos[i]==-1) continue;
        rep(j,10){
            auto a=upper_bound(all(G[j]),pos[i]);
            if(a==G[j].end()) continue;
            ans+=B[*a+1];
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 976
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int X,A,B;
	cin >> X>>A>>B;
	if ((B - A) > X)
	{
		cout << "dangerous" << endl;
	}
	else
	{
		if (B > A)
		{
			cout << "safe" << endl;
		}
		else
		{
			cout << "delicious" << endl;
		}

	}
	

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > Pi;
typedef pair < ll  , ll  > Pl;

const int INF = (1 << 30) - 1;
const ll LLINF = 1LL << 60;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int mod = 1000000007;

int main()
{
    int N;
    Pi red[105], blue[105];
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> red[i].first >> red[i].second;
    }
    for(int i = 0; i < N; i++) {
        cin >> blue[i].first >> blue[i].second;
    }
    sort(blue, blue + N);
    int ans = 0;
    bool used[105] = {};
    for(int i = 0; i < N; i++) { //B
        int pos = -1;
        for(int j = 0; j < N; j++) { //R
            if(!used[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
                if(pos == -1 || red[j].second > red[pos].second) pos = j;
            }
        }
        if(pos != -1) {
            ans++;
            used[pos] = true;
        }
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
using System;
using System.Runtime.InteropServices;

namespace AGC026A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int cur = -1;
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == cur)
                {
                    cur = -1;
                    ans++;
                    continue;
                }

                cur = a[i];
            }
            
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

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

  int32_t N;
  cin >> N;
  string C;
  cin >> C;
  int32_t rcnt = 0;
  int32_t wcnt = 0;
  for (int i = 0; i < N; i++) {
    if (C[i] == 'W') wcnt++;
    else rcnt++;
  }
  int32_t res = 0;
  for (int i = 0; i < N; i++) {
    if (C[i] == 'R' && i >= rcnt) res++;
  }
  cout <<res << endl;
 

  return 0;
}


Measured memory_bytes: 3700
#include <iostream>

using namespace std;

int main(void) {
	int A,B;
	cin >> A >> B;
	if (A > B) {
		cout << A+max(A-1,B) << endl;
	}
	else {
		cout << B+max(A,B-1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<bool> vb;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

vll n;

int main(){
	n=vll(3);
	for(int i=0;i<3;i++) cin>>n[i];
	sort(n.begin(),n.end());
	for(int i=0;i<3;i++){
		if(n[i]%2==0){
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<n[0]*n[1]<<endl;
}

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;


//===


int main() {
	int A, B;
	cin >> A >> B;
	if (A > 12) {
		cout << B << endl;;
	}
	else if (A <= 12 && A >= 6) {
		cout << B / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Solve{
    int n;
    int m;
    int q;
    int[] a;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        bool[] check = new bool[m];
        int[] counts = new int[m];
        int[] place = new int[m];
        int[] s = new int[m];
        int count = m-2;
        for(int i=0;i<m;i++){
            check[i]=false;
            counts[i] = 0;
        }
        {
            int j = 0;
            for(int i=q-1;i>=0;i--){
                if(!check[a[i]]){
                    check[a[i]] = true;
                    place[a[i]] = j;
                    s[j] = a[i];
                    j++;
                }
            }
            for(int i=0;i<m;i++){
                if(!check[i]){
                    place[i] = j;
                    s[j] = i;
                    j++;
                }
            }
        }
        for(int i =  q-1;i>=0;i--){
            if(counts[place[a[i]]]<n){
                if(place[a[i]] == 0 || counts[place[a[i]]-1] > counts[place[a[i]]]){
                    counts[place[a[i]]]++;
                }
            }
        }
        while(count >= 0){
            if(s[count]<s[count+1]){
                count--;
            }
            else{
                break;
            }
        }
        if(count>=0 && counts[count]<n){
            Console.WriteLine("No");
        }
        else{
            Console.WriteLine("Yes");
        }
        // for(int i=0;i<=count;i++){
        //     if(counts[i]<n){
        //         Console.WriteLine("No");
        //         return;
        //     }
        // }
        // Console.WriteLine("Yes");
    }
    void getinput(){
        string[] str = Console.ReadLine().Split(' ');
        n = int.Parse(str[0]);
        m = int.Parse(str[1]);
        q = int.Parse(Console.ReadLine());
        str = Console.ReadLine().Split(' ');
        a = new int[q];
        for(int i=0;i<q;i++){
            a[i] = int.Parse(str[i])-1;
        }
    }    
}

Measured memory_bytes: 10968
/*
    Mbak Sana Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,m,i,j,k,x,y,ans,curr,temp;
    int a,b,c;
    cin >> a >> b >> c;
    int sum = a+b+c;
    if(sum >= 22) cout << "bust";
    else cout << "win";
    cout << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll i,j;
    int a[n+1];
    for(i=1;i<=n;i++)
    {
    	a[i]=0;
	}
    for(i=0;i<k;i++)
    {
    	ll d;
    	cin>>d;
    	for(j=0;j<d;j++)
    	{
    		ll x;
    		cin>>x;
    		a[x]++;
		}
	}
	ll s=0;
	for(i=1;i<=n;i++)
	{
		if(!a[i])
		s++;

	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define ll long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

vector<string> v;

signed main(){
	
	string s;cin >> s;
	int k;cin>>k;
	
	
	rep(start,s.size())
	{
		rep(len,5)
		{
			if(start + len > s.size()-1) continue;
			
			string subs = s.substr(start,len+1);
			v.push_back(subs);
		}
	}
	
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	
	
	
	cout << v[k-1] << endl;
	
}

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

#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(int i=x;i<y;i++)
#define foreI(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sl "\n";
#define ii pair<ll,ll>
#define mk make_pair


typedef long long ll;
typedef unsigned long long ull;

using namespace std;
string a,b;
const int MAXN = 3005;
ll dp[MAXN][MAXN];
int n,m;
string ans;
ll solve(int i,int j){
    if(i==n)return 0;
    if(j==m)return 0;
    ll &r = dp[i][j];
    if(r!=-1)return r;
    if(a[i]==b[j]){r=solve(i+1,j+1)+1;}
    else r=max(solve(i+1,j),solve(i,j+1));
    return r;
}
void build(int i,int j){
    if(i==n)return;
    if(j==m)return;
    ll answer = solve(i,j);
    if(a[i]==b[j]&&answer==solve(i+1,j+1)+1){ans.pb(a[i]);build(i+1,j+1);}
    else if(answer==solve(i+1,j)){build(i+1,j);}
    else if(answer==solve(i,j+1)){build(i,j+1);}
    return;
}
int main() {FIN;
   
    cin>>a>>b;
    n=a.size();
    m=b.size();
    memset(dp,-1,sizeof(dp));
    solve(0,0);
    build(0,0);
    cout<<ans<<sl;
    return 0;
}




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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define FI ios::sync_with_stdio(false); cin.tie(0);

#define LL long long

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MX = 1e5 + 5;

int main() {
	#define int long long
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}

	int ans = 0;
	int last = 0;
	for(int i=0;i<n;i++) {
		if(a[i] < last) {
			ans += last - a[i];
		}
		last = max(last, a[i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4836
N, A, B, K = map(int, input().split())

mod = 998244353
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 )

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


ans = 0

for i in range(N+1):
    if (K - A*i) % B == 0 and K - A*i >= 0:
        j = (K - A*i) // B
        ans += cmb(N, i, mod) * cmb(N, j, mod)
        ans %= mod

print(ans)


Measured memory_bytes: 38936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,m;
int main(void){
    cin>>n>>m;
    ll l=0,r=1000000000000000,M=(l+r)/2;
    while(r-l>1){
        if(2*M<=m&&n+(m-2*M)/2>=M){
            l=M;
            M=(l+r)/2;
        }else{
            r=M;
            M=(l+r)/2;
        }
    }
    cout<<l<<endl;

}



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

using namespace std;

int		main(void)
{
	string S;

	cin >> S;
	int A = stoi(S.substr(0, 2));
	int B = stoi(S.substr(2));
	string ans = "NA";

	if (1 <= A && A <= 12)
	{
		if (1 <= B && B <= 12)
			ans = "AMBIGUOUS";
		else
			ans = "MMYY";
	}
	else if (1 <= B && B <= 12)
		ans = "YYMM";
	cout << ans << endl;
}


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

int main(){
  int a,b,n,r,c;
  while(1){
    cin>>a>>b;
    if(a==0)break;
    int route[b+1][a+1];

    for(int i=0;i<b+1;i++)
      for(int j=0;j<a+1;j++)
	route[i][j]=0;
    cin>>n;
    while(n--){
      cin>>r>>c;
      route[c][r]=-1;
    }

    route[1][1]=1;

    for(int i=1;i<b+1;i++)
      for(int j=1;j<a+1;j++)
	if(route[i][j]!=-1){
	  if(route[i-1][j]!=-1)route[i][j]+=route[i-1][j];
	  if(route[i][j-1]!=-1)route[i][j]+=route[i][j-1];
	}

    cout<<route[b][a]<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll n,m;
    cin>>n>>m;
    vector<tuple<ll, ll, string>> t;
    pair<ll, ll> p;
    for (ll i = 0; i < m; i++)
    {
        ll p;
        string s;
        cin >> p >> s;
        t.emplace_back(p, i, s);
    }
    ll a,wa=0;
    sort(t.begin(), t.end());
    bool flag = true;
    for (ll i = 0; i < m; i++)
    {
        /*
        cout <<get<0>(t[i])<<" ";
        cout << get<1>(t[i]) << " ";
        cout << get<2>(t[i]) <<endl;
        */
       if(a!=get<0>(t[i])){
           flag = true;
           wa = 0;
       }
       if(flag&&get<2>(t[i])=="AC"){
           flag = false;
           p.first++;
           p.second += wa;
       }
       else if(flag&&get<2>(t[i])=="WA"){
           wa++;
       }
       a = get<0>(t[i]);
    }
    cout << p.first << " " << p.second << endl;
}


Measured memory_bytes: 7860
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int arr[4], t, sum = 0;
    for (int i = 0; i < 4; i++) scanf("%d", &arr[i]);
    sort(arr, arr+4);
    for (int i = 0; i < 2; i++) { scanf("%d", &t); sum = max(sum, t); }
    for (int i = 1; i < 4; i++) sum+= arr[i];
    printf("%d\n", sum);
    return 0;
}



Measured memory_bytes: 2760
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void get_max(T& a, const T b) { a = max(a, b); }
template <class T> void get_min(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int C, R;
	while (scanf("%d%d", &R, &C), R | C)
	{
		static bool rev[10][10000];
		for (int i = 0; i < R; ++i)
		{
			for (int j = 0; j < C; ++j)
			{
				int t;
				scanf("%d", &t);
				rev[i][j] = t == 0;
			}
		}

		int res = 0;
		for (int i = 0; i < 1 << R; ++i)
		{
			int sum = 0;
			for (int x = 0; x < C; ++x)
			{
				int s = 0;
				for (int y = 0; y < R; ++y)
					if (rev[y][x] ^ (i >> y & 1))
						++s;
				sum += max(s, R - s);
			}
			get_max(res, sum);
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 980
n = int(input())
t = []
x = []
y = []
for _ in range(n):
    ti, xi, yi = map(int,input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)
for i in range(n):
    if ((x[i]+y[i])%2==0 and t[i]%2==1 or (x[i]+y[i])%2==1 and t[i]%2==0 or x[i]+y[i]>t[i]):
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 11764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n, m;
    cin >> n >> m;
    map<int,int> mp;
    rep(i, n) {
        int k; cin >> k;
        rep(j, k) {
            int a; cin >> a;
            mp[a]++;
        }
    }
    int cnt = 0;
    for( auto i = mp.begin(); i != mp.end() ; ++i ) {
        if(i->second == n) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e12
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=100000;

int digsum(int x){
    int res=0;
    while(x>0){
        res+=x%10;
        x=x/10;
    }
    
    return res;
}

int main(){
    
    int ans=INF;
    int cal[maxn+1]={0};
    int n;
    cin >> n;
    
    for(int i=1;i<=n;i++){
        cal[i]=digsum(i);
    }
    
    for(int i=1;i<=n/2;i++){
        
        ans=min(ans,cal[i]+cal[n-i]);
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
const int maxn=2e5+5;
int ls;
int nxt[26][maxn],pre[maxn],f[maxn];
char s[maxn],ch[maxn];
int main()
{
	scanf("%s",s+1);
	ls=strlen(s+1);
	for (int i=0;i<26;i++)
	{
	  int j=ls+1,p=ls;
	  while (j>=1)
	  {
	  	while (p>=1&&s[p]-'a'!=i)p--;
	  	while (j>=p+1)nxt[i][j]=p,j--;
	  	p--;
	  }
	}
	memset(f,0x3f,sizeof(f));
	f[ls+1]=0;
	for (int i=ls+1;i>=1;i--){
		for (int j=0;j<26;j++){
			if (f[i]+1<f[nxt[j][i]]){
				f[nxt[j][i]]=f[i]+1;
				pre[nxt[j][i]]=i;
				ch[nxt[j][i]]='a'+j;
			}else{
				if (f[i]+1==f[nxt[j][i]])if (j<ch[nxt[j][i]]-'a'){
					pre[nxt[j][i]]=i;
					ch[nxt[j][i]]='a'+j;
				}else if (j==ch[nxt[j][i]]-'a'&&s[i]<s[pre[nxt[j][i]]]){
				  pre[nxt[j][i]]=i;
				  ch[nxt[j][i]]='a'+j;
				}
			}
		}
	}
	int p=0;
	printf("%c",ch[0]);
	while (pre[p]!=ls+1)putchar(s[pre[p]]),p=pre[p];
	return 0;
}

Measured memory_bytes: 22400
a, b, c = map(int, input().split())

total = a + b + c

if a % 2 == 0 and b % 2 == 0 and c % 2 == 0 and a == b == c:
    print(-1)
elif a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
    print(0)
else:
    count = 1
    while True:
        a, b = (total - a) / 2, (total - b) / 2
        if a % 2 != 0 or b % 2 != 0:
            print(count)
            break
        else:
            count += 1


Measured memory_bytes: 38384
import time
import random
def score(a,c,s,d):
  l=[-1 for i in range(26)]
  r=0
  for i in range(d):
    l[a[i]]=i
    r+=s[i][a[i]]
    for j in range(26):
      r-=c[j]*(i-l[j])
  return r
  
st=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

ans=[]
l=[-1 for i in range(26)]
ld=[]
for i in range(d):
  ms=-10**9
  mt=None
  for j in range(26):
    js=c[j]*(i-l[j])+s[i][j]
    if ms<js:
      ms=js
      mt=j
  l[mt]=i
  ans.append(mt)
  ld.append([l[mt],d])
  if l[mt]>=0:
    ld[l[mt]][1]=i

os=score(ans,c,s,d)
nt=st
rate=1000
while nt-st<1.50:
  nt=time.time()
  na=[ans[i] for i in range(d)]
  for i in range(5):
    na[random.randint(1,d-1)]=random.randint(0,25)
  ns=score(na,c,s,d)
  if ns>os:
    os=ns
    ans=na
  
  


for i in ans:
  print(i+1)

Measured memory_bytes: 87436
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int A, B;
	cin >> A >> B;
	if (A + B >= 10)
		cout << "error" << endl;
	else
		cout << A + B << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long Int;
#define INF (1LL << 62)

Int x[108000];
Int n, a, b;
vector<Int> edge;
int main(){
  cin >> n >> a >> b;
  for(int i = 0;i < n;i++){
    cin >> x[i];
    if(i)edge.push_back(x[i]-x[i-1]);
  }
  sort(edge.begin(), edge.end());

  Int sum = x[n-1] - x[0];

  Int res = sum * a;
  Int tmp = res;
  for(int i = 0;i < n-1;i++){
    tmp -= edge.back() * a;
    edge.pop_back();
    tmp += b;
    res = min(res, tmp);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1912
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int k = sc.nextInt();
		int x = sc.nextInt();
		
		// 計算
		String result = "No";
		if(500*k >= x) result = "Yes";
		
		// 出力
		System.out.println(result);
	}
	
}




Measured memory_bytes: 21844
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
    next if arr[i] == 2 
    i.step(INF, i) do |j| 
        arr[j] += 1 
    end
end
puts a.select {|o| arr[o] == 1}.size

Measured memory_bytes: 39964
import sys

def bubble_sort(n, data):
    flag = True
    i = 0
    cnt = 0

    while flag:
        flag = False
        
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                data[j], data[j-1] = data[j-1], data[j]
                cnt += 1
                flag = True

        i += 1

    print(' '.join([str(i) for i in data]))
    print(cnt)
        
def main():
    n = int(sys.stdin.readline().strip())
    data = [int(i) for i in sys.stdin.readline().strip().split(' ')]
    bubble_sort(n, data)
    
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 7796
n = int(input())
S = tuple(map(int, input().split(' ')))

q = input()
T = tuple(map(int, input().split(' ')))

cnt = 0

for i in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            cnt += 1
            break
        elif i < S[mid]:
            right = mid
        else:
            left = mid + 1

print(cnt)

Measured memory_bytes: 18976
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')

def fmod(x):
    ans = 1
    for i in range(1, x + 1):
        ans *= i
        ans %= MOD
    return ans

def solve():
    n, m = [int(x) for x in input().split()]
    n, m = min(n,m), max(n,m)
    x = m - n
    if x > 1:
        print(0)
    elif x == 1:
        print((fmod(n) * fmod(m))%MOD)
    else:
        print((fmod(n) * fmod(m)*2)%MOD)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


Measured memory_bytes: 9812
import java.util.*;

class Main {
	Scanner sc;
	int N, M;
	List<Integer>[] to;
	
	@SuppressWarnings("unchecked")
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		to = new ArrayList[N];
		for (int i = 0; i < N; i++)
			to[i] = new ArrayList<Integer>();
		
		M = sc.nextInt();
		for (int i = 0; i < M; i++) {
			int s = sc.nextInt()-1;
			int t = sc.nextInt()-1;
			to[s].add(t);
		}
		double min = Double.MAX_VALUE;
		// expected value
		double[] ev = new double[N];
		for (int i = 0; i < N-1; i++) {
			for (int j = N-2; j >= 0; j--) {
				double sum = 0d;
				double max = -Double.MAX_VALUE;
				for (int v : to[j]) {
					sum += ev[v]+1;
					max = Math.max(max, ev[v]);
				}
				int c = to[j].size();
				if (i == j && c > 1) ev[j] = (sum-max-1) / (c-1);
				else ev[j] = sum / c;
			}
			min = Math.min(min, ev[0]);
		}
		System.out.println(min);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 94768
#include <iostream>
#include <string>
#include <cassert>
using namespace std;

struct TNode
{
	int Id;
	TNode* Parent;
	TNode* LChild;
	TNode* RChild;
};

struct TTree
{
private:
	void Delete(const TNode* Node)
	{
		if(Node == NULL) return;
		Delete(Node->LChild);
		Delete(Node->RChild);
		delete Node;
	}
public:
	TNode* Root;
	TTree()
	{
		Root = NULL;
	}
	~TTree()
	{
		Delete(Root);
	}
};

void Insert(TTree& Tree, TNode* z)
{
    assert(z != NULL);
	TNode* y = NULL;
	TNode* x = Tree.Root;
	while(x != NULL){
		y = x;
		if(z->Id < x->Id){
			x = x->LChild;
		}else{
			x = x->RChild;
		}
	}
	z->Parent = y;
	if(y == NULL){
		Tree.Root = z;
	}else if(z->Id < y->Id){
		y->LChild = z;
	}else{
		y->RChild = z;
	}
}

void InorderOutput(const TNode* Node)
{
	if(Node == NULL) return;
	InorderOutput(Node->LChild);
	cout << ' ' << Node->Id;
	InorderOutput(Node->RChild);
}

void PreorderOutput(const TNode* Node)
{
    if(Node == NULL) return;
    cout << ' ' << Node->Id;
    PreorderOutput(Node->LChild);
    PreorderOutput(Node->RChild);
}

void Print(const TTree& Tree)
{
	InorderOutput(Tree.Root);
	cout << endl;
	PreorderOutput(Tree.Root);
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	TTree Tree;
//	Tree.Root = NULL;
	for(int i = 0; i < n; i++){
		string Command;
		cin >> Command;
		if(Command == "insert"){
			int Id;
			cin >> Id;
			TNode* Node;
			Node = new TNode;
			*Node = {Id, NULL, NULL, NULL};
			Insert(Tree, Node);
		}else{
			Print(Tree);
		}
	}
//	Delete(Tree.Root);
    return 0;
}

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

 int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   
   int a, b;
   cin >> a >> b;
   auto gcd = [&](int c, int d) {
		if(c < d) {
			swap(c, d);
		}
		while(c % d > 0) {
			int empty = c;
			c = d;
			d = empty % d;
		}
		return d;
	};
	cout << (long)a * b / gcd(a, b) << endl;
}
       
       

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){
			for(int j=i+1;j<s.size();j++){
				if(s[j]=='F'){
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

map<pair<char, int>, char> m;
char suits[] = {'S', 'H', 'C', 'D'};

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	char suit;
	int rank;
	for(int i=0;i<n;++i) {
		cin >> suit >> rank;
		m[make_pair(suit,rank)] = 'X';
	}
	for(int i=0;i<4;++i)
		for(int j=1;j<=13;++j)
			if(m[make_pair(suits[i],j)]!='X')
				cout << suits[i] << ' ' << j << '\n';
	return 0;

} // br1



Measured memory_bytes: 3152
get_digit = lambda x :len(str(x))

N = int(input())
N_sq = int(N**(1/2))
ret = get_digit(N)
for A in range(1, N_sq+1):
    if N % A == 0:
        B = N // A
        tmp = max(get_digit(A), get_digit(B))
        ret = min(ret, tmp)
        
print(ret)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        int N = S.length();
        int[] ten = new int[N+1];
        ten[0] = 1;
        for (int i = 1; i < ten.length; i++) {
            ten[i] = (ten[i-1] * 10) % 2019;
        }
        int[] sumup = new int[N+1];
        sumup[0] = 0;
        for (int i = 1; i <= N; i++) {
            sumup[i] = (sumup[i-1] + Integer.parseInt(S.substring(N-i,N-i+1)) * ten[i-1]) % 2019; 
        }
        // for (int i = 0; i < sumup.length; i++) {
        //     System.out.println(sumup[i]);
        // }
        int[] count = new int[2019];
        for (int i = 0; i <= N; i++) {
            int res = sumup[i] % 2019;
            count[res] ++;
        }
        // System.out.println(count[0]);
        int ans = 0;
        for (int i = 0; i < count.length; i++) {
            ans += count[i]*(count[i]-1)/2;
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 51300
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n>=100&&n<=111){
        printf("111\n");
    }
    if(n>=112&&n<=222){
        printf("222\n");
    }
    if(n>=223&&n<=333){
        printf("333\n");
    }
    if(n>=334&&n<=444){
        printf("444\n");
    }
    if(n>=445&&n<=555){
        printf("555\n");
    }
    if(n>=556&&n<=666){
        printf("666\n");
    }
    if(n>=667&&n<=777){
        printf("777\n");
    }
    if(n>=778&&n<=888){
        printf("888\n");
    }
    if(n>=889&&n<=999){
        printf("999\n");
    }
    return 0;
}


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

using namespace std;

int main(void) {
    int A, P;
    cin >> A >> P;

    int n = 3*A + P;
    int ans = n / 2; 

    cout << ans << endl;

    // int X, A;
    // cin >> X >> A;

    // if(X < A) {
    //     /*
    //      * XがA未満
    //      */
    //     cout << 0 << endl;
    // }
    // else {
    //     /*
    //      * XがA以上
    //      */
    //     cout << 10 << endl;
    // }

    // //cout << X << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int **p;
    int i,j,k,n;
    scanf("%d",&n);
    p= (int**)malloc((3*n)*sizeof(int));
    for(i = 0 ;i<n;i++)
    {
        p[i] = (int*)malloc(3*sizeof(int));
    }
    for(i = 0 ;i <n;i++)
    {
        for(j = 0 ;j < 3;j++)
        {
            scanf("%d",&p[i][j]);
        }
    }
   
   for(i=0;i<n;i++)
   {	int a,b,c;
   		a=p[i][0];b=p[i][1];c=p[i][2];
   		if(a*a==(b*b+c*c) || b*b==(a*a+c*c) || c*c==(a*a+b*b))
   		{
   			printf("YES\n");
   		}else
   		{
   			printf("NO\n");
   			}
   	}   
    return 0;
}

Measured memory_bytes: 620
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
S = 0
for i in range(N+1):
    S += abs(A[i+1] - A[i])

for i in range(1, N+1):
    T = S - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1])
    print(T)


Measured memory_bytes: 14040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    int n;ll k;cin>>n>>k;
    vector<pair<int,int>>v(n);
    int x,y;
    rep(i,n){
        cin>>x>>y;v[i]=make_pair(x,y);
    }
    sort(v.begin(),v.end());
    ll count=0;int i=0;int ans;
    while(count<k){
        count+=v.at(i).second;
        ans=v.at(i).first;
        i++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 10000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll N, A[200001];

int main() {
	cin >> N;
	ll S = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
		S += A[i];
	}
	ll minx = S, sum = 0;
	for (int i = 1; i <= N; i++)
	{
		sum += A[i];
		minx = min(minx, abs(sum - (S - sum)));
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 5044
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};


typedef struct node * Node;



Node root;


void insert(int k)
{
  Node x;
  Node y;
  Node z;
  y = NIL;
  x = root;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if(y==NIL)
    root = z;
  else if(z->key<y->key)
    y->left = z;
  else
    y->right = z;

}

void inorderTreeWalk(Node x)
{
  if(x==NIL)
    return;
  
  inorderTreeWalk(x->left);
  printf(" %d",x->key);
  inorderTreeWalk(x->right);
}

void preorderTreeWalk(Node x)
{
  if(x==NIL)
    return;
  
  printf(" %d",x->key);
  preorderTreeWalk(x->left);
  preorderTreeWalk(x->right);
  
}

Node treeMinimum(Node x)
{
  while(x->left!=NIL)
    x = x->left;
  return x;
}


Node treeSearch(Node x,int k){
  if(x==NIL || k==x->key)
    return x;
  if(k<x->key)
    return treeSearch(x->left,k);
  else
    return treeSearch(x->right,k);
}


Node treeSuccessor(Node x)
{
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);

  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
  return y;
}


void treeDelete(Node z)
{
  Node x, y;
  if(z->left==NIL || z->right==NIL)
    y=z;
  else
    y =treeSuccessor(z);
  if(y->left!=NIL)
    x = y->left;
  else
    x = y->right;

  if(x!=NIL)
    x->parent = y->parent;

  if(y->parent==NIL)
    root = x;
  else if(y==y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;

  if(y!=z)
    z->key = y->key;
}


int main()
{
  char str[20];
  int x, m, i;
  Node T;

  scanf("%d",&m);
  for( i=0 ; i<m ; i++ ){
    scanf("%s",str);
    if(str[0]=='f'){
      scanf("%d",&x);
      T = treeSearch(root,x);
      if(T!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(str[0]=='p'){
      inorderTreeWalk(root);
      printf("\n");
      preorderTreeWalk(root);
      printf("\n");
    }
    else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
  
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c;cin>>a>>b>>c;
  int t = a*100+b*10+c;
  if(t%4==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;

  }

  return 0;
}


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

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

    int A, B, C, D;
    D = N%10; N /= 10;
    C = N%10; N /= 10;
    B = N%10; N /= 10;
    A = N%10;

    if( A+B+C+D == 7 ) cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
    else if( A+B+C-D == 7 ) cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
    else if( A+B-C+D == 7 ) cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
    else if( A+B-C-D == 7 ) cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
    else if( A-B+C+D == 7 ) cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
    else if( A-B+C-D == 7 ) cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
    else if( A-B-C+D == 7 ) cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
    else if( A-B-C-D == 7 ) cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0045
{
    class Program
    {
        static void Main(string[] args)
        {
            Sales sales = new Sales();
            double sum=0;
            double avarage=0;
            string str = "";
            while (!((str = Console.ReadLine()) == null))
            {
                double[] line = str.Split(',').Select(double.Parse).ToArray();
                sales.AddData(line[0], line[1]);
            }
            foreach (var key in sales.data.Keys)
            {
                sum+=sales.data[key] * key;
            }
            avarage = sales.data.Values.Average();
            Console.Write(sum+"\n"+ avarage.ToString("f0") +"\n");
        }
    }
    class Sales
    {
        public Dictionary<double,double> data = new Dictionary<double,double>();
        public void AddData(double bid,double amount)
        {
            data.Add(bid,amount);
        }
    }
}



Measured memory_bytes: 14428
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,a[4][13];
  char mar;
  memset(a,0,sizeof(a));
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>mar>>num;
    if(mar=='S') a[0][num-1]=1;
    if(mar=='H') a[1][num-1]=1;
    if(mar=='C') a[2][num-1]=1;
    if(mar=='D') a[3][num-1]=1;
  }

  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      if(a[i][j]==0){
	if(i==0) cout<<'S'<<' '<<j+1<<endl;
	if(i==1) cout<<'H'<<' '<<j+1<<endl;
	if(i==2) cout<<'C'<<' '<<j+1<<endl;
	if(i==3) cout<<'D'<<' '<<j+1<<endl;
      }
    }
  }
  return(0);
}



Measured memory_bytes: 3108
unittest
{
	assert( [ "24" ].parse.expand.solve == 3 );
	assert( [ "1" ].parse.expand.solve == 0 );
	assert( [ "64" ].parse.expand.solve == 3 );
	assert( [ "1000000007" ].parse.expand.solve == 1 );
	assert( [ "997764507000" ].parse.expand.solve == 7 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	auto ans = 0L;
	foreach( pc; n.primefactorize.group )
	{
		for( auto i = 1L; i <= pc[ 1 ]; i++ )
		{
			pc[ 1 ] -= i;
			ans++;
		}
	}
	return ans;
}

// 素数列
auto primes( long x )
{
	Appender!( long[] ) ps;
	if( x < 2 ) return ps.data;
	
	auto cs = new bool[]( x + 1 );
	ps ~= 2L;
	for( auto i = 3L; i * i < cs.length; i += 2 )
	{
		if( cs[ i ] ) continue;
		for( auto j = i; i * j < cs.length; j++ )
		{
			cs[ i * j ] = true;
		}
	}
	for( auto i = 3L; i < cs.length; i += 2 )
	{
		if( !cs[ i ] ) ps ~= i;
	}
	return ps.data;
}

// 素因数分解
auto primefactorize( long x )
{
	Appender!( long[] ) fs;
	if( x < 2 ) return fs.data;
	
	auto s = cast( long ) x ^^ 0.5L;
	foreach( p; s.primes )
	{
		while( x % p == 0 )
		{
			x /= p;
			fs ~= p;
		}
		if( x < 2 ) break;
	}
	if( 2 <= x ) fs ~= x;
	return fs.data;
}


Measured memory_bytes: 4188
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
  int a;
  rep(i,5) {
	cin >> a;
    if (a == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
  return 0; 
}

Measured memory_bytes: 3616
// {{{ include and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i, a, b) for(int i=a; i < b;i++)
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <deque>
#include <set>
using namespace std;
// }}}

// {{{ io
void newline() {cout << endl;}
template <typename T>
void display(T input){cout << input;}
template <typename T>
void put(T input){display(input); newline();}
  // }}}

const int n_max = 100000;
const int prime_number_max = 200270;
const int p_max = 100;
vector<int> prime_numbers;
int n, p;

void reserve_prime_numbers(){
   const int sievesize = prime_number_max;
   std::vector<int> sieve(prime_number_max, 1);
   sieve.reserve(prime_number_max);
   prime_numbers.reserve(prime_number_max);
   for (int i = 2; i * i < sievesize; i++)
      if (sieve[i])
         for (int j = i + i; j < sievesize; j += i)
            sieve[j] = 0;
   for (int j = 2; j < sievesize; j++)
      if (sieve[j])
        prime_numbers.push_back(j);
}

int get_index(){
  int i=0;
  for(; prime_numbers[i]<=n; i++){}
  return i;
}

int binary_search_index_rec(int s, int e){
  int i=(s+e)/2;
  if(s==e-1){return i;}
  if(prime_numbers[i]==n){return i;}
  if(prime_numbers[i]>n) return binary_search_index_rec(s, e-(e-s)/2);
  if(prime_numbers[i]<n) return binary_search_index_rec(s+(e-s)/2, e);
}

int binary_search_index(){
  return binary_search_index_rec(0, prime_numbers.size()-1);
}

int solve(){
  vector<int> prime_numbers_sum;
  int index = get_index();
  // int index = binary_search_index();
  for(int i=0+index; i<25+index; i++){
    for(int l=i; l<25+index; l++){
      int sum = prime_numbers[i] + prime_numbers[l];
        prime_numbers_sum.push_back(sum);
    }
  }
  sort(prime_numbers_sum.begin(), prime_numbers_sum.end());
  return prime_numbers_sum[p-1];
}

int main(){
  ios::sync_with_stdio(false);
  prime_numbers.reserve(prime_number_max);
  reserve_prime_numbers();
  while(cin >> n >> p && n != -1 && p != -1)
    put(solve());
}

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

#define ll long long
#define N 110
#define M 100010
#define pii pair <int, int>
#define fi first
#define se second
const ll p = 1e9 + 7;
int n, k;
ll f[N][M];
pii g[M]; 
map <int, int> mp;

int main() {
	while (scanf("%d%d", &k, &n) != EOF) {
		memset(f, 0, sizeof f);
		mp.clear();
		int m = 0;
		for (int i = 1, j; i <= k; i = j + 1) {
			j = k / (k / i);
			g[++m] = pii(j, j - i + 1);
			mp[j] = m;
		}
		for (int i = 1; i <= m; ++i) {
			f[1][i] = (f[1][i - 1] + g[i].se) % p; 
		}
		for (int i = 2; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				f[i][j] = (f[i][j - 1] + 1ll * g[j].se * f[i - 1][mp[k / g[j].fi]] % p) % p;
			}
		}
		printf("%lld\n", f[n][m]);
	}
	return 0;
}


Measured memory_bytes: 89600
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

const int MOD = 1e9+7;

int mpow(int v,int k){
	int r(1),t(v);
	while(k)
	{
		if(k&1) {
			r*=t;
			r%=13;
		}
		t*=t;
		t%=13;
		k>>=1;
	}
	return r;
}

signed main() {
	std::string s;
	std::cin >> s;
	std::vector<int> d(13,0);
	if(s[s.size()-1]=='?') {
		rep(i,10) d[i]=1;
	}
	else {
		d[s[s.size()-1]-'0']=1;
	}
	int j=1;
	for(int i=s.size()-2;i>=0;i--,j++) {
		std::vector<int> p(13,0);
		int a = mpow(10,j);
		if(s[i]=='?') {
			for(int l=0;l<10;l++) {
				int b = a*l%13;
				rep(k,13) {
					p[(k+b)%13] += d[k];
					p[(k+b)%13]%=MOD;
				}
			}
		}
		else {
			int b = a;
			b*=s[i]-'0';
			b%=13;
			rep(k,13) {
				p[(k+b)%13] += d[k];
				p[(k+b)%13]%=MOD;
			}
		}
		std::swap(d,p);
	}
	print(d[5]);

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
 
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a.at(i);
bool ans = false;
int x = a.at(0);
int cnt = 1;
while(true){
   if(x == 2){
     cout << cnt << endl;
     return 0;
   }
   if(cnt == n){
     cout << -1 << endl;
     return 0;
   }
   cnt++;
  x = a.at(x-1);
}
}

Measured memory_bytes: 3768
#include<iostream>

using namespace std;

int main() {
	int n,sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		while (a % 2 == 0) {
			a /= 2;
			sum++;
		}
	}
		cout << sum << endl;

	return 0;
}

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

ans = 0
pre = 0
for a, b in zip(A, B):
    if a >= pre:
        a -= pre
        ans += pre
    else:
        ans += a
        pre = b
        continue
    if a >= b:
        ans += b
        pre = 0
    else:
        ans += a
        pre = b - a
a = A[-1]
if a >= pre:
    ans += pre
else:
    ans += a
print(ans)
    

Measured memory_bytes: 18476