akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace abc140_d
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToIntArray();
            // 人数
            var n = items[0];
            // 回転させる回数
            var k = items[1];
            // 向いている方向
            var s = Console.ReadLine();

            // 向いている方向が同じ人たちの列が最も長くなるところを回転させたい
            // →よくよく考えたら、(両端以外なら)どの場所を入れ替えても、幸福の増加量は+2では？
            // →一個飛ばしで、前から順々に入れ替えていくのが一番いい

            // もともとの合計値
            var sum = 0L;
            // 直前のグループの末尾インデックス
            var prev = 0;
            // グループの総数
            var count = 0;
            for (int i = 1; i < s.Length; i++)
            {
                if (s[i - 1] != s[i])
                {
                    sum += i - prev - 1;
                    prev = i;
                    count++;
                }
            }
            sum += s.Length - prev - 1;
            count++;

            // 各グループ数ごとの、最大回転数は下記の通り

            // グループ数 1 : 0回 o +0
            // グループ数 2 : 1回 ox +1
            // グループ数 3 : 1回 oxo +2
            // グループ数 4 : 2回 oxox +2+1
            // グループ数 5 : 2回 oxoxo
            // グループ数 6 : 3回 oxoxox
            // グループ数 7 : 3回 oxoxoxo

            var max = count / 2;
            if (k < max)
            {
                sum += k * 2;
            }
            else
            {
                sum += max * 2;
                // グループが偶数だったら、両端を回転するので、増加量が-1になることに注意
                if (count % 2 == 0)
                {
                    sum -= 1;
                }
            }

            Console.WriteLine($"{sum}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


Measured memory_bytes: 13536
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 23 17:33:45 2019
ABC042D
@author: maezawa
"""

MAX = 5*10**5+1
MOD = 10**9+7

fac = [0] * MAX
finv = [0]*MAX
inv = [0]*MAX

# テーブルを作る前処理
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2,MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

# 二項係数計算
def COM(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def HCOM(n,k):
    return COM(n+k-1,k)


#n, r = list(map(int, input().split()))
#ans = COM(n, r)
#print(ans)

h, w, a, b = list(map(int, input().split()))
cnt = 0
for i in range(h-a):
    p0 = HCOM(b, i) * HCOM(w-b,h-i-1)
    cnt = (cnt+p0)%MOD
print(cnt)

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll h, w;
    cin >> h >> w;

    multiset<ll> mi;
    set<P> st;
    REP(i, w) {
        mi.insert(0);
        st.insert({i, 0});
    }

    REP(i, h) {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        auto s = st.lower_bound({l, -INF});
        ll val = INF;
        while(s != st.end()) {
            auto [ii, b] = *s;
            if(ii > r)
                break;
            chmin(val, (r + 1 - ii) + b);
            s = st.erase(s);
            mi.erase(mi.find(b));
        }

        if(val != INF and r + 1 < w) {
            if(s != st.end()) {
                auto [ii, b] = *s;
                if(ii == r + 1) {
                    chmin(val, b);
                    st.erase(s);
                    mi.erase(mi.find(b));
                }
            }

            st.insert({r + 1, val});
            mi.insert(val);
        }
        if(mi.size() == 0)
            cout << -1 << en;
        else
            cout << *mi.begin() + i + 1 << en;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 25392
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int limit = 100005;
using edge = struct {int to; ll cost;};

int n;
vector<edge> tree[limit];
vector<long long> dist;

void dfs(int v, long long d = 0, int p = -1){
    dist[v] = d;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, d + e.cost, v);
    }
}

vector<long long> calcDist(int s){
    dist = vector<long long>(n);
    dfs(s);
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int u, v;
    cin >> u >> v;
    --u; --v;
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        --a; --b;
        tree[a].push_back({b, 1});
        tree[b].push_back({a, 1});
    }
    vector<ll> distT = calcDist(u);
    vector<ll> distA = calcDist(v);
    ll ans = 0;
    rep(i,n){
        if(distT[i] <= distA[i]){
            chmax(ans, distA[i] - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14192
my $s = <STDIN>;
my ($H,$N) = split(/ /,$s);

$s = <STDIN>;
my @dat = split(/ /,$s);

$sum = 0;
for(my $i=0;$i<=$#dat;$i++){
  $sum = $sum + $dat[$i];
}
if( $sum >= $H){
  print "Yes";
}else{
  print "No";
}


Measured memory_bytes: 16804
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	vl sum(n+1);
	rep(i,n){
		int cnt=0;
		if(i!=0&&s[i-1]=='A'&&s[i]=='C')cnt=1;
		sum[i+1]=sum[i]+cnt;
	}
	int l,r;
	while(q--){
		cin>>l>>r;
		r--;l--;
		int ans=sum[r+1]-sum[l];
		if(l!=0&&sum[l+1]!=sum[l])ans--;
		cout<<ans<<"\n";
	}
}

Measured memory_bytes: 2000
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		String str[];
		int word[];
		int a, b;

		n = sc.nextInt();
		String s = sc.nextLine();
		word = new int[4];
		for (int i = 0; i < n; i++) {
			str = sc.nextLine().split(" ");
			a = 0;
			b = 0;
			for (int j = 0; j < str.length; j++) {
				if (str[j].length() == 4) {
					word[0] = str[j].charAt(0) - 'a';
					word[1] = str[j].charAt(1) - 'a';
					word[2] = str[j].charAt(2) - 'a';
					word[3] = str[j].charAt(3) - 'a';
					for (int k = 3; k <= 27; k += 2) {
						int l = word[0] - k * ('t' - 'a');
						if (((k * ('h' - 'a') + l) % 26 + 26) % 26 == word[1]) {
							if (((k * ('a' - 'a') + l) % 26 + 26) % 26 == word[2] && word[0] == word[3]) {
								a = k;
								b = l;
								break;
							} else if (((k * ('i' - 'a') + l) % 26 + 26) % 26 == word[2] && ((k * ('s' - 'a') + l) % 26 + 26) % 26 == word[3]) {
								a = k;
								b = l;
								break;
							} else {
								break;
							}
						}
					}
					if (a != 0) {
						break;
					}
				}
			}
			for (int j = 0; j < str.length; j++) {
				if (j != 0) {
					System.out.print(" ");
				}
				for (int k = 0; k < str[j].length(); k++) {
					for (int l = 'a'; l <= 'z'; l++) {
						if (((a * (l - 'a') + b) % 26 + 26) % 26 + 'a' == str[j].charAt(k)) {
							System.out.print((char)l);
						}
					}
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
n,m=gets.split.map &:to_i
a=Array.new(n)
b=Array.new(n).map{[]}
m.times do
  x,y=gets.split.map &:to_i
  b[y-1]<< x-1
  b[x-1]<< y-1
end
t=[0]
a[0]=0
even=1
odd=0
j=false
loop do
  break if t==[]
  g=t.pop
  c=a[g]+1
  b[g].each do |e|
    if a[e]
      if (a[e]-c)%2!=0
        j=true
      end
    else
      t<< e
      a[e]=c
      c.even? ? even+=1 : odd+=1
    end
  end
end
if j
  p n*(n-1)/2 - m
else
  p even*odd - m
end
  
        


Measured memory_bytes: 13308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean flag = true;
		for(int i = 0; i < s.length(); i++) {
			if(i%2==0) {
				if(s.charAt(i) == 'L') {
					flag = false;
					break;
				}
			}else {
				if(s.charAt(i) == 'R') {
					flag = false;
					break;
				}
			}
		}
		System.out.println(flag?"Yes":"No");
		sc.close();
	}

}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,k,coun,i;string s;cin >> n >> k >> s;coun = 0;
  for (i=1;i<n;i++){
    if (s[i] != s[i-1]) coun += 1;
  }
  if (coun==1) coun += 1;
  coun = max(0,coun-(k*2));
  cout << n-1-coun << endl;
}

Measured memory_bytes: 512
/*
      author : nishi5451
      created: 12.08.2020 14:40:47
*/

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


int main(){
    int n,k;
    cin >> n >> k;
    int num = n%2==0 ? n/2 : (n+1)/2;
    if(num >= k) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define N 110
using namespace std;

vector<int> a(N);
int n;

void obradiKorak();

int main()
{
	int rez;
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	for (int i = 0; *max_element(a.begin(), a.begin()+n) > 0; i++)
	{
		rez++;
		obradiKorak();
	}
	
	cout << rez;
	return 0;
}

void obradiKorak()
{
	int ind = 0;
	for (int i = 0; i < n; i++)
	{
		if(a[i] != 0)
		{
			ind = 1;
			a[i]--;
		}
		else if (ind == 1)
		{
			return;
		}
	}
	return;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 100000000000000;

using namespace std;

ll modpow(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;
}

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

void solve()
{
    string s, t;
    cin>>s>>t;
    int anss=10000;
    int n1=s.length(), n2=t.length();
    repu(i,0,n1-n2)
    {
        int ans=0;
        rep(j,n2)
        {
            if(t[j]!=s[i+j])
                ans++;
        }
        anss=min(anss,ans);
    }
    cout<<anss<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    deque<char>deq;
    string str;
    char ch;
    int n,rev = 1;
    cin>>str>>n;
    deq.push_back('!');
    rep(i,n){
        int q,f;
        cin>>q;
        if(q == 1){
            rev *= -1;
        }
        else{
            cin>>f>>ch;
            f *= rev;
            if(f == 1 || f == -2)deq.push_front(ch);
            else deq.push_back(ch);
        }
    }
    if(rev < 0){
        reverse(all(deq));
        reverse(all(str));
    }
    for(auto &itr:deq){
        if(itr != '!')cout<<itr;
        else cout<<str;
    }
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 848
#include <stdio.h>
#include <string.h>

int main(void)
{
    int N;
    int Red_count = 0;
    int Blue_count = 0;    
    scanf("%d", &N);
    char s[N], str[1];
    scanf("%s", s);

    for(int i = 0; i < N; i++){

        if(s[i] == 'R'){
            Red_count = Red_count + 1;
        }
        else if (s[i] == 'B'){
            Blue_count = Blue_count + 1;
        }        
        
    }
    /* printf("Red_count : %d\n", Red_count); */
    /* printf("Blue_count : %d\n", Blue_count);     */
    if( Red_count > Blue_count ){
        printf("Yes\n");        
    }
    else{
        printf("No\n");
    }
    
    
    return 0;    
}


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

int main() {
  int n, k;
  cin >> n >> k;
  
  int list[n - 1];
  int t, i=0;
  while(cin >> t){
    list[i] = t;
    i++;
  }
  sort(list, list + n, greater<>());
  
  int min = 1000000000;
  for(int ii = 0; ii + k <= n; ii++) {
    int tmp = list[ii] - list[ii + (k - 1)];
    
    if(min > tmp){
      min = tmp;
      
      if(min == 0){ break; }
    }
  }
  
  cout << min << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
#define int ll
#define double long double
int n;
double dp[3001];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    dp[0]=1;
    for(int i=1; i<=n; i++){
        double x;
        cin>>x;
        for(int cnt=i; cnt>=1; cnt--){
            dp[cnt]=dp[cnt-1]*x+dp[cnt]*(1-x);
        }
        dp[0]*=(1-x);
    }
    double ans=0;
    //for(int i=0; i<=n; i++) cout<<dp[i]<<" ";
    for(int i=n/2+1; i<=n; i++) ans+=dp[i];
    cout<<fixed<<setprecision(10)<<ans;
}


Measured memory_bytes: 384
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <numeric>
#include <time.h>
#include <stack>
#include <bitset>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)
 
using namespace std;
 
typedef long long ll;
typedef double dbl;
 
template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}
 
template<class T>   
void print(const T* s, int n){
    for (int i = 0; i < n; i++)
        cout << s[i] << ' ';
    cout << endl;
}

template<class T>
void print(vector<vector<T>> s){
    for (int i = 0; i < s.size(); i++)
        print(s[i]);
}

int solve(){
    string s;
    cin >> s;
    for (char c : s)
        cout << (c != '?' ? c : 'D');
    cout << endl;
    return 0;    
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed; 
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (V[i] > C[i]) ans += (V[i] - C[i]);
  }
  cout << ans << endl;
};


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

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

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll h,w,n;cin>>h>>w>>n;
  vector<ll> ans(10,0);
  ans[0]=(h-2)*(w-2);

  map<PL,ll> ma;

  for(int i=0;i < n;i++)
  {
    ll a,b;cin>>a>>b;a--;b--;
    for(int j=-1;j <=1 ;j++)
    {
      for(int k=-1;k <=1 ;k++)
      {
        if(0>=a+j || a+j>=h-1 || 0>=b+k || b+k>=w-1)continue;

        ma[{a+j,b+k}]++;
      }
    }
  }

  for(auto i : ma)
  {
    ans.at(i.se)++;
  }

  for(int i=1;i < 10;i++)
  {
    ans[0]-=ans[i];
  }

  for(int i=0;i < 10;i++)
  {
    cout<<ans[i]<<endl;
  }
}

    

Measured memory_bytes: 56448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

int main() {
  int N; cin>>N;
  vector<ll> a(N);
  for(int i=0;i<N;i++) cin>>a[i];
  
  vector<ll> s(N+1,0);
  map<ll,ll> nums;
  for(int i=0;i<N;i++) s[i+1]=s[i]+a[i];
  for(int i=0;i<N+1;i++) nums[s[i]]++;
  
  ll res=0;
  for(auto it : nums){
      ll num=it.second;
      res+=num*(num-1)/2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 15872
import math
import itertools

n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))

x = 0
y = 1
d = 0

for p in itertools.permutations(range(n)):
    p = list(p)
    for i in range(n-1):
        d += ((xy[p[i]][x] - xy[p[i+1]][x])**2 + (xy[p[i]][y] - xy[p[i+1]][y])**2)**0.5
        # print(d)

print(d/math.factorial(n))

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

using namespace std;

bool p[200000];

int main()
{
	int n=0;
	cin >> n;
	for (int i=1; i<=200000; i++)
		p[i] = true;
	p[2] = true;
	for (int i=2; i<=200000; i++)
	{
		if (p[i])
		{
			for (int j=2; 1ll*i*j<=1ll*200000; j++)
			{
				p[i*j] = false;
			}
		}
	}
	
	for (int i=n; i<=200000; i++)
	{
		if (p[i])
		{
			cout << i;
			return 0;
		}	
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < k; i++) {
			set.add(sc.nextInt());
		}
		while (true) {
			if (check(n, set)) {
				System.out.println(n);
				return;
			}
			n++;
		}
	}
	
	static boolean check(int num, HashSet<Integer> set) {
		while (num > 0) {
			if (set.contains(num % 10)) {
				return false;
			}
			num /= 10;
		}
		return true;
	}
}


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

using namespace std;

int main(void){
	
	int n,temp;
	double p;
	scanf("%d",&n);
	for(int i = 0; i < n ;i++){
		scanf("%d", &temp);
		p+=temp;
	}
	
	printf("%.0lf\n",p/n);
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int Selection(int *,int);
void change(int *,int);

int main(){
  int N,i,j,cnt;
  int A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  cnt = Selection(A,N);
  change(A,N);
  printf("%d\n",cnt);
}

int Selection(int A[],int n){
  int i,j,change,cnt=0,min;
  
  for(i=0;i<n-1;i++){
    min = i;
    for(j=i;j<n;j++){
      if(A[j] < A[min]) min = j;
    }
    change = A[i];
    A[i] = A[min];
    A[min] = change;
    if(i != min) cnt++;
  }
  return cnt;
}

void change(int A[], int n){
  int i;
  for(i=0;i<n;i++){
    if( i>0 ) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}



Measured memory_bytes: 2128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var abc = ReadLine().Split().Select(long.Parse).ToArray();
        var a = abc[0];
        var b = abc[1];
        var c = abc[2];
        bool ans = false;
        if (c - a - b > 0)
        {
            if (4 * a * b < (c - a - b) * (c - a - b))
                ans = true;
        }
        WriteLine(ans?"Yes":"No");
        
    }
}


Measured memory_bytes: 28212
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


vector<set<int>> e;
string C;
vector<int> erased;

vector<int> usable;

int cost;
int longest;

int dfs(int now, int prv)
{
    int t = (C[now] != 'B') ^ (e[now].size() % 2);
    cost += 2 + t;
    vector<int> v{0};
    for (auto nxt : e[now]) if (nxt != prv) v.emplace_back(dfs(nxt, now));
    sort(v.rbegin(), v.rend());
    mmax(longest, t + v[0]);
    if ((int)v.size() > 1) mmax(longest, t + v[0] + v[1]);
    return v[0] + t;
}

int main()
{
    int N;
    cin >> N;
    e.resize(N);
    REP(_, N - 1)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        e[x].insert(y);
        e[y].insert(x);
    }
    cin >> C;
    erased.resize(N);
    queue<int> to_erase;
    REP(i, N) if (e[i].size() == 1 and C[i] == 'B') to_erase.push(i);

    while (!to_erase.empty())
    {
        int v = to_erase.front();
        to_erase.pop();
        erased[v] = 1;
        for (auto nxt : e[v])
        {
            e[nxt].erase(v);
            if (e[nxt].size() == 1 and C[nxt] == 'B')
            {
                to_erase.push(nxt);
            }
        }
        e[v].clear();
    }
    int r = 0;
    while (r < N and erased[r]) r++;
    if (r >= N)
    {
        puts("0");
        return 0;
    }
    if (e[r].empty())
    {
        cout << (C[r] == 'W') << endl;
        return 0;
    }
    dfs(r, -1);
    cout << cost - longest * 2 - 2 << endl;
}


Measured memory_bytes: 28748
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int cnt[N];

void NO(){
    cout << "No\n";
    exit(0);
}

int main(){
    fastIO;
    int n;
    cin >> n;
    int mn = n, mx = 0;
    int a;
    for(int i = 1; i <= n; i ++ ){
        cin >> a;
        cnt[a] ++ ;
        mn = min(mn, a);
        mx = max(mx, a);
    }
    if(mx - mn > 1){
        NO();
    }
    if(mx - mn == 1){
        if(mx > cnt[mn] && mx <= cnt[mn]+cnt[mx]/2)
            cout << "Yes\n";
        else
            NO();
    }
    else{
        if(mx * 2 <= n || mx == n-1){
            cout << "Yes\n";
        }
        else{
            NO();
        }
    }
    return 0;
}

Measured memory_bytes: 640
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        final int N = scan.nextInt();
        String[] array = new String[N];
        for (int i = 0; i < N; i++) {
            array[i] = scan.next();
        }

        BigInteger fraction = new BigInteger("1");
        for (int i = 0; i < N; i++) {
            fraction = fraction.multiply(new BigInteger(array[i]));
        }

        BigInteger denominator = new BigInteger("0");
        for (int i = 0; i < N; i++) {
            BigInteger tmp = new BigInteger("1");
            for (int j = 0; j < N; j++) {
                if (j != i) {
                    tmp = tmp.multiply(new BigInteger(array[j]));
                }
            }
            denominator = denominator.add(tmp);
        }

        BigDecimal fracDecimal = new BigDecimal(fraction);
        BigDecimal denomDecimal = new BigDecimal(denominator);
        double ans = fracDecimal.divide(denomDecimal, 10, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        System.out.println(ans);

    }

}


Measured memory_bytes: 24152
#include<iostream>
#include<cstring>
#include<string>

using namespace std;

bool dic[30000000];

void init(){
  memset(dic, false, sizeof(dic));
}

int _hash(string s){
  int ret=0;
  for(int i=0;i<s.length();i++){
    ret *= 5;
    if(s[i]=='A')ret += 1;
    else if(s[i]=='C')ret += 2;
    else if(s[i]=='G')ret += 3;
    else if(s[i]=='T')ret += 4;
  }
  return ret;
}

void insert(string s){
  dic[_hash(s)] = true;
}

bool find(string s){
  return dic[_hash(s)];
}

int main(){
  init();
  int n;cin >> n;
  for(int i=0;i<n;i++){
    string com, s; cin >> com >> s;
    if(com == "insert")insert(s);
    else if(com == "find"){
      cout << (find(s)?"yes": "no") << endl;
    }
  }
}


Measured memory_bytes: 32496
#include <stdio.h>

#define N 102
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,adj[N][N],color[N],d[N],f[N],S[N],time;

int Stacktop(){
  int i;
  for (i=1;i<=n+1;i++){
    if (S[i]==-1){
      return i;
    }
  }
}

int Stackempty(){
  int i;
  for (i=1;i<=n;i++){
    if (S[i]!=-1){
      return 0;
    }
  }
  return 1;
}

void Push(int r){
  S[Stacktop()] = r;
}

void DFS_Visit(int r){
  int i,u,v;
  Push(r);
  color[r] = GRAY;
  d[r] = ++time;
  while(Stackempty()==0){
    u = S[Stacktop()-1];
    v = Nextvertex(u);
    if (v != NULL){
      if (color[v] == WHITE){
	Push(v);
	color[v] = GRAY;
	d[v] = ++time;
      }
    } else {
      Pop();
      color[u] = BLACK;
      f[u] = ++time;
    }
  }
}

void DFS(){
  int u;
  for (u=1;u<=n;u++){
    color[u] = WHITE;
    time = 0;
  }
  for (u=1;u<=n;u++){
    if (color[u] == WHITE){
      DFS_Visit(u);
    }
  }
}

int Pop(){
  int i;
  S[Stacktop()-1]= -1;
  return Stacktop()-1;
}

int Nextvertex(int v){
  int i;
  for (i=1;i<=n;i++){
    if (adj[v][i]==1 && color[i]==WHITE){
      return i;
    }
  }
  return NULL;
}

int main() {
  int i,j,u,k,v;
  //ini
  for (i=1;i<=N;i++){
    for (j=1;j<=N;j++){
      adj[i][j]=0;
    }
    S[i]=-1;
    color[i]=WHITE;
    d[i]=f[i]=0;
  }

  scanf ("%d",&n);
  for (i=1;i<=n;i++){
    scanf ("%d%d",&u,&k);
    for (j=1;j<=k;j++){
      scanf("%d",&v);
      adj[u][v]=1;
    }
  }
  DFS();

  for (i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}

Measured memory_bytes: 640
def warshall_floyd(d):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

h,w = map(int,input().split())

d = [[10**4]*10 for i in range(10)] 
for i in range(10):
    a = list(map(int,input().split()))
    for j in range(10):
      d[i][j] = a[j]
for i in range(10):
    d[i][i] = 0
    
ans = 0
chk = tuple(warshall_floyd(d))
for _ in range(h):
  c = list(map(int,input().split()))
  for i in c:
    if i != 1 and i != -1:
      ans += chk[i][1]
      
print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e6 + 10;

char S[N], T[N];
int n, hd, tl, fans, posa, posb, Q[N];

int main()
{
	scanf("%d", &n);
	scanf("%s", S + 1);
	scanf("%s", T + 1);
	if (strcmp(S + 1, T + 1) == 0) {
		printf("0\n");
		return 0;
	}
	hd = tl = 0;
	posa = posb = n;
	while (posb >= 1) {
		int lst = posb;
		bool flag = true;
		while (posb > 1 && T[posb] == T[posb - 1]) --posb;
		while (posa >= 1 && (posa > posb || S[posa] != T[posb]) /*S[posa] != T[posb]*/) {
			if (S[posa] != T[posb]) flag = false;
			--posa;
		}
		if (S[posa] != T[posb]) flag = false;
		if (!posa) {
			printf("-1\n");
			return 0;
		}
	//	while (tl > hd && Q[hd + 1] - (tl - hd - 1 /* size - 1*/) > lst) ++hd;
	//	if (posa != posb)
	//		Q[++tl] = posa;
	//	printf("%d %d : %d %d %d\n", posa, posb, lst, hd, tl);
	//	if (posb != lst) {
	//		if (Q[hd + 1] - (tl - hd - 1) <= posb) fans = max(fans, tl - hd + 1);
	//		else fans = max(fans, tl - hd);
	//	}
	//	else fans = max(fans, tl - hd);
		while (tl > hd && Q[hd + 1] - (tl - hd - 1 /* size - 1 */) > lst) ++hd;
		if (posa != posb)
			Q[++tl] = posa;
	//	printf("%d %d : %d %d %d %d\n", posa, posb, lst, hd, tl, Q[hd]);
		if (posa != posb) fans = max(fans, tl - hd);
		else {
			if (tl - hd > 0) fans = max(fans, tl - hd + 1);
			else {
				/* fans = max(fans, tl - hd); */
				if (posb != lst && (!flag))
					fans = max(fans, 1);
			}
		}
		--posb;
	}
	printf("%d\n", fans);
	
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main(){
  map<char,int> kinds;
  int n,cnt = 0;
  char input;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> input;
    if(kinds[input] == 0) cnt++;
    kinds[input]++;
  }
  if(cnt == 4) cout << "Four" << endl;
  else cout << "Three" << endl;
}


Measured memory_bytes: 256
S = input()
#S = int(input())
#s = input().split()
#hw = [[int(i) for i in input().split()] for _ in range(N)]
#A = list(map(int, input().split()))

if (S[len(S) - 1] == "s"):
    print(S + "es")
else:
    print(S + "s")

Measured memory_bytes: 9028
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  int h,w;
  cin>>h>>w;
  rep(i,h) rep(j,w){
    string str;
    cin>>str;
    if(str=="snuke"){
      printf("%c%d\n", 'A'+j, i+1);
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int h,w,k,l,m,a,b,s,t,u,v,i,j,x[999][999];
int main(){
while(true){
memset(x,0,sizeof(x));v=0;
cin>>k;if(!k){break;}
cin>>w>>h;
for(i=0;i<k;i++){cin>>a>>b;x[a][b]=1;}
cin>>s>>t;
for(i=1;i<=w;i++){
for(j=1;j<=h;j++){
u=0;
for(l=0;l<s;l++){
for(m=0;m<t;m++){
if(x[i+l][j+m]){
u++;
}
}
}
v=max(v,u);
}
}
cout<<v<<endl;
}
}

Measured memory_bytes: 5064
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut xs = vec![];
	let mut ys = vec![];
	let mut vert = vec![];
	let mut horz = vec![];
	for _ in 0..n {
		let y0: i32 = s.next().unwrap().parse().unwrap();
		let y1: i32 = s.next().unwrap().parse().unwrap();
		let x: i32 = s.next().unwrap().parse().unwrap();
		vert.push((y0, y1, x));
		xs.push(x);
		ys.push(y0);
		ys.push(y1);
	}
	for _ in 0..m {
		let y: i32 = s.next().unwrap().parse().unwrap();
		let x0: i32 = s.next().unwrap().parse().unwrap();
		let x1: i32 = s.next().unwrap().parse().unwrap();
		horz.push((y, x0, x1));
		xs.push(x0);
		xs.push(x1);
		ys.push(y);
	}
	xs.sort();
	xs.dedup();
	ys.sort();
	ys.dedup();
	let mut field = vec![vec![false; xs.len() + 1]; ys.len() + 1];
	let mut fence = vec![vec![0u8; xs.len() + 1]; ys.len() + 1];
	for (y0, y1, x) in vert.iter() {
		let yl = ys.binary_search(y0).unwrap() + 1;
		let yr = ys.binary_search(y1).unwrap();
		let x = xs.binary_search(x).unwrap();
		for y in yl..=yr {
			fence[y][x] |= 2;
			fence[y][x + 1] |= 8;
		}
	}
	for (y, x0, x1) in horz.iter() {
		let xl = xs.binary_search(x0).unwrap() + 1;
		let xr = xs.binary_search(x1).unwrap();
		let y = ys.binary_search(y).unwrap();
		for x in xl..=xr {
			fence[y][x] |= 4;
			fence[y + 1][x] |= 1;
		}
	}

	let mut q = std::collections::VecDeque::new();
	let ystart = ys.binary_search(&0).unwrap_or_else(|i| i);
	let xstart = xs.binary_search(&0).unwrap_or_else(|i| i);

	q.push_back((ystart as i32, xstart as i32));
	field[ystart][xstart] = true;
	while let Some((y, x)) = q.pop_front() {
		for (i, (dy, dx)) in [(-1, 0), (0, 1), (1, 0), (0, -1)].iter().enumerate() {
			let ny = y + dy;
			let nx = x + dx;
			if ny >= 0
				&& ny <= ys.len() as i32
				&& nx >= 0 && nx <= xs.len() as i32
				&& fence[y as usize][x as usize] & (1 << i) == 0
				&& !field[ny as usize][nx as usize]
			{
				field[ny as usize][nx as usize] = true;
				q.push_back((ny, nx));
			}
		}
	}
	let mut ans = 0i64;
	for y in 0..=ys.len() {
		for x in 0..=xs.len() {
			if field[y][x] {
				ans = ans.saturating_add(if y == 0 || y == ys.len() || x == 0 || x == xs.len() {
					std::i64::MAX
				} else {
					let h = ys[y] as i64 - ys[y - 1] as i64;
					let w = xs[x] as i64 - xs[x - 1] as i64;
					h * w
				});
			}
		}
	}
	if ans == std::i64::MAX {
		println!("INF");
	} else {
		println!("{}", ans);
	}
}


Measured memory_bytes: 19944
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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


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

    int N;
    cin >> N;
    if(N == 1){
        cout << "Hello World" << endl;
    }else{
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> diff(n);
  for (int i = 0; i < n; i++) cin >> diff.at(i);
  sort(diff.begin(), diff.end());
  cout << diff.at(n / 2) - diff.at(n / 2 - 1) << endl;
}

Measured memory_bytes: 640
n= int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans=0

for i in range(0,n):
    ans += b[a[i]-1]


    if i>=1:
        if a[i]==a[i-1]+1:

            ans+=c[a[i]-2]


print(ans)


Measured memory_bytes: 9108
n = int(input())
l = list(map(int, input().split()))
count = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if l[i] == l[j]:
            continue
        for k in range(j+1,n):
            if l[i] != l[k] and l[j] != l[k]:
                if l[i]+l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                    count += 1
print(count)


Measured memory_bytes: 73608
/*
 * atcoder/abc089/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve();
int main() { solve(); return 0; }

void solve() {
  vector<string> S(3);
  vector<int> A(3);
  vector<vector<int> > B(3);
  vector<int> I(3, 0);
  loop(i,0,3) cin >> S[i];
  loop(i,0,3) A[i] = S[i].size();
  loop(i,0,3) {
    for (auto&&c: S[i]) {
      B[i].push_back(c-'a');
    }
    assert((int)B[i].size() == A[i]);
  }

  string C = "ABC";
  int cur = 0;
  while (true) {
    // cout << cur << " " << S[cur][I[cur]] << endl;
    cur = B[cur][I[cur]++];
    if (I[cur]==A[cur]) {
      cout << C[cur] << endl;
      return;
    }
  }

  cout << "D" << endl;
}


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

#define ll long long

int main(){
    string S;
    cin >> S;
    if(S[5] == '0' && (S[6] == '1' || S[6] == '2' || S[6] == '3' || S[6] == '4'))cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	ll n, k, x, y;
	cin >> n >> k >> x >> y;
	if (k >= n) {
		cout << x * n << endl;
	}
	else {
		cout << x * k + (n - k)*y << endl;
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    vector<ll> g(N+1);
    for (int i = 1; i <= N; i++)
    {
        ll Y = N/i;
        g[i]=(Y*(Y+1)*i)/2;
        ans += g[i];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 81384
from math import sqrt
def dist(x1, y1, x2, y2):
    return sqrt((x1-x2)**2 + (y1-y2)**2) + 10**(-7)

def max_dist(p, x, y):
    res = 0
    for i in range(len(p)):
        dis = dist(p[i][0], p[i][1], x, y)
        if res < dis:
            res = dis
    return res

def calc(p, x):
    yL, yR = 0, 1000
    while yL + 10**-7 < yR:
        yl, yr = (2*yL + yR)/3, (yL + 2*yR)/3
        ql, qr = max_dist(p, x, yl), max_dist(p, x, yr)
        if ql < qr:
            yR = yr
        else:
            yL = yl
    return qr, yR

def main():
    n = int(input())
    p = [list(map(int, input().split())) for _ in range(n)]
    xL, xR = 0, 1000
    while xL + 10**-7 < xR:
        xl, xr = (2*xL + xR)/3, (xL + 2*xR)/3
        ql, yl = calc(p, xl)
        qr, yr = calc(p, xr)
        if ql < qr:
            xR = xr
        else:
            xL = xl
    print(max_dist(p, xR, yr))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> score(n);
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> score[i];
        ans += score[i];
    }
    sort(score.begin(), score.end());

    if(ans % 10 != 0)
    {
        cout << ans << endl;
        return;
    }
    bool is_print = false;
    for(int i = 0; i < n; i++)
    {
        if(score[i] % 10 == 0) continue;
        ans -= score[i];
        is_print = true;
        break;
    }
    if(is_print) cout << ans << endl;
    else cout << 0 << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D
// Combinatorial - Longest Increasing Subsequence
// status:

#define SUBMIT

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int MAX_N = 100000;
int n;
int a[MAX_N + 1];
int L[MAX_N];

int compute_lis() {
    L[0] = a[0];
    int length = 1;

    for (int i = 1; i <= n; ++i) {
        if (L[length - 1] < a[i]) {
            L[length] = a[i];
            length++;
        } else {
            *lower_bound(L, L + length, a[i]) = a[i];
        }
    }

    return length;
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(5
5
1
3
2
4
)";
    stringstream stream(program_input_str);
#endif
    stream >> n;
    for (int i = 0; i < n; ++i) {
        stream >> a[i];
    }

    cout << compute_lis() << endl;
    return 0;
}



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

using namespace std;

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

typedef long long ll;

int main() {
  
  for(int n, w;cin >> n >> w && n&&w;) {
    int val[210] = {};
    int mx = 0;
    rep(i, n) {
      int x; cin >> x;
      val[x] ++;
      mx = max(mx, x);
    }
    
    int imax = 0;
    for(int i=0; i<=mx; i+=w) {
      int cnt = 0;
      REP(j, i, i+w) {
        cnt += val[j];
      }
      imax = max(imax, cnt);
    }
    
    double ink = 0.01;
    int hist = mx/w;
    for(int i=0; i<=mx; i+=w) {
      int cnt = 0;
      REP(j, i, i+w) {
        cnt += val[j];
      }
      ink += (double)(hist-i/w)/hist*cnt/imax;
    }
    printf("%.10f\n", ink);
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 1e9+7;
const int inv =  5e8+4;
int Pow(int a,int b){
	if(b==0) return 1;
	int ret = Pow(a,b>>1);
	ret=1ll*ret*ret%P;
	if(b&1) ret=1ll*ret*a%P;
	return ret;
}
int n,K,ans,q[100000];
map<int,int> POW,F; 
inline void add(int &x,int y ){x=(x+y)%P;}

int main(){
	cin>>n>>K;
	int t,l;
	for(int i=1;1ll*i*i<=n;i++) if(n%i==0){
		//cout<<i<<endl;
		POW[i] = Pow(K,(i+1)>>1);
		t = n/i;
		POW[t] = Pow(K,(t+1)>>1);
	}
	//cout<<POW[n]<<endl;
	int cnt = 0;
	for(int i=1;1ll*i*i<=n;i++) if(n%i==0){
		//cout<<i<<endl;
		t = i;
		l = n/t;
		add(F[t],POW[t]);
		for(int j=2;1ll*j*j<=l;j++) if(l%j==0){
			add(F[j*t],-F[t]);
			if(j*j!=l) add(F[t*(l/j)],-1ll*F[t]%P);
		}
		if(n!=t) add(F[n],-1ll*F[t]%P);
		if(t&1) add(ans,1ll*F[t]*t%P);
		else add(ans,1ll*t*F[t]%P*inv%P);
		
		if(i*i!=n)q[++cnt] = n/i;
	}
	//cout<<"YYY"<<endl;
	for(int i=cnt;i>0;i--){
		t = q[i];
		l = n/t;
		add(F[t],POW[t]);
		for(int j=2;1ll*j*j<=l;j++) if(l%j==0){
			add(F[j*t],-F[t]);
			if(j*j!=l) add(F[t*(l/j)],-1ll*F[t]%P);
		}
		if(n!=t) add(F[n],-1ll*F[t]%P);
		//add(ans,1ll*F[t]*t%P);
		//if(t!=n) add(ans,1ll*F[t]*t%P);
		//else {
		if(t&1) add(ans,1ll*F[t]*t%P);
		else add(ans,1ll*F[t]*t%P*inv%P);
		//}
	}
	
	ans =(ans+P)%P;
	cout<<ans<<endl;
	return 0;	
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

// worst 10^8なのでint
int dp[(int)1e3+1][(int)1e4+1];


int main(int argc, char const* argv[])
{
  int h, n;
  cin >> h >> n;

  for (int i = 0; i < (int)1e3+1; i++) {
    for (int j = 0; j < (int)1e4+1; j++) {
      // dp[i][j] = INT_MAX; // 一見妥当そうだが、dp[i][ja]+bしたときにoverflowする
      dp[i][j] = (int)1e8+1;
    }
  }

  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = 0; j <= h; j++) {
      int ja = j-a>=0 ? j-a : 0;
      dp[i][j] = min(dp[i-1][j], dp[i][ja]+b);
    }
  }

  cout << dp[n][h] << endl;

  return 0;
}

Measured memory_bytes: 39424