akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    string s[10001];
    int cnt=0;
    int ca=0, cb=0, cba=0;
    for(int i=0; i<n; i++){
        cin>>s[i];
        for(int j=0; j<s[i].size()-1; j++){
            if(s[i][j]=='A' && s[i][j+1]=='B') cnt++;
        }
        if(s[i][0]=='B' && s[i].back()=='A') cba++;
        else if(s[i][0]=='B') cb++;
        else if(s[i].back()=='A') ca++;
    }
    if(ca==0 && cb==0) cnt+=max(0, (cba-1));
    else cnt+=min(ca, cb)+cba;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "-1" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------


//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    vector<P> B(N);
    rep(i,N) B[i].first=A[i],B[i].second=i;
    SORT(B);
    ll ans=0;
    rep(i,N){
        if(i%2!=B[i].second%2) ++ans;
    }
    cout<< ans/2 <<"\n";

    
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct node {
    double alpha;
    struct node *next;
} node;

int main()
{
    int i;

    node *head = NULL, *cur = NULL;
    while( 1 ){
        //入力
        int n;
        scanf("%d", &n);
        if( n == 0 ) break;
        int s[n];
        for( i = 0; i < n; ++i )
            scanf("%d", &s[i]);

        //平均得点
        double m = 0;
        for( i = 0; i < n; ++i )
            m += s[i];
        m = (double)(m / n);

        //メモリ確保
        node *new = (node *)malloc(sizeof(node));
        if( new == NULL ) exit(-1);
        new->alpha = (double)0;
        new->next = NULL;

        //標準偏差を計算
        for( i = 0; i < n; ++i )
            new->alpha += pow(s[i]-m, 2);
        new->alpha = (double)(new->alpha / n);
        new->alpha = sqrt(new->alpha);

        //ノードを連結
        if( head == NULL ) head = new;
        else cur->next = new;
        cur = new;
    }

    //出力
    cur = head;
    while( cur ){
        printf("%lf\n", cur->alpha);
        cur = cur->next;
    }

    return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
//#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
const int N=5000+5,M=2e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,m,bin[30]={1};
int val[N],st[N];vector<int>e[N];
void dfs(int x,int f){
	re(i,0,e[x].size()){
		int y=e[x][i];if(y!=f){
			dfs(y,x);
			if(st[y]==0&&val[y]<val[x])st[x]=1;
		}
	}
}
int main(){
	read(n);rep(i,1,n)read(val[i]);
	re(i,1,n){int a,b;read(a,b);e[a].pb(b);e[b].pb(a);}
	rep(i,1,n){
		rep(j,1,n)st[j]=0;
		dfs(i,0);
		if(st[i])printf("%d ",i);
	}
}

Measured memory_bytes: 768
#include <stdio.h>

using namespace std;

int final_board[8][8] = {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};

void deletePossibility(int tmp_board[8][8],int row,int column){
	tmp_board[row][column] = 1;
	for(int i = 0; i < 8; i++){
		if(i != column){
			tmp_board[row][i] = -1;
		}
	}
	for(int i = 0; i < 8; i++){
		if(i != row){
			tmp_board[i][column] = -1;
		}
	}

	for(int r = row-1,c = column+1;r >= 0 && c <= 7; r--,c++){
		tmp_board[r][c] = -1;
	}
	for(int r = row+1,c = column+1;r <= 7 && c <= 7; r++,c++){
		tmp_board[r][c] = -1;
	}
	for(int r = row-1,c = column-1;r >= 0 && c >= 0; r--,c--){
		tmp_board[r][c] = -1;
	}
	for(int r = row+1,c = column-1;r <= 7 && c >= 0; r++,c--){
		tmp_board[r][c] = -1;
	}
}



void func(int tmp_board[8][8],int num_of_putQ){
	if(num_of_putQ == 8){
		for(int i = 0; i < 8; i++){
			for(int k = 0; k < 8; k++){
				final_board[i][k] = tmp_board[i][k];
			}
		}
	}else{

		int row,column,count = 0;
		for(row = 0; row < 8; row++){
			for(column = 0; column < 8; column++){
				if(tmp_board[row][column] == 0){
					count++;
				}
			}
			if(count > 0) break;
		}
		if(row == 8 && column == 8){
			//Do nothing
		}else{
			int tri_board[count][8][8];
			int index = 0;

			for(int a = 0; a < count; a++){
				for(int b = 0; b < 8; b++){
					for(int c = 0; c < 8; c++){
						tri_board[a][b][c] = tmp_board[b][c];
					}
				}
			}

			for(int i = 0; i < 8; i++){
				if(tmp_board[row][i] == 0){
					deletePossibility(tri_board[index],row,i);
					func(tri_board[index++],num_of_putQ+1);
				}
			}
		}

	}
}




int main(){

	int k,row,colum;
	int tmp_board[8][8];

	for(int i = 0; i < 8; i++){
		for(int k = 0; k < 8; k++){
			tmp_board[i][k] = 0;
		}
	}

	scanf("%d",&k);

	for(int i = 0; i < k; i++){
		scanf("%d %d",&row,&colum);
		deletePossibility(tmp_board,row,colum);
	}

	func(tmp_board,k);

	for(int i = 0; i < 8; i++){
		for(int p = 0; p < 8; p++){
			if(final_board[i][p] == 1){
				printf("Q");
			}else{
				printf(".");
			}
		}
		printf("\n");
	}

    return 0;
}


Measured memory_bytes: 2692
#ABC135_C
#紙に書いて考える。具体例を考える。

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

ans=0
rem=A[0]

for i in range(N):
    if B[i]<=(rem+A[i+1]):
        ans+=B[i]
        if rem>=B[i]:
            rem=A[i+1]
        else:
            rem=A[i+1]+rem-B[i]
    else:
        ans+=rem+A[i+1]
        rem=0       
print(ans)

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

int word_length = 10;
int main() {
  int n, m;
  cin >> n;
  string tmp;
  map<string, int> nss;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    nss[tmp]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> tmp;
    nss[tmp]--;
  }
  int ans = 0;
  for (auto e : nss) ans = max(ans, e.second);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll bin_pow(ll base,ll deg)
{
    if (deg==0)
        return 1;
    ll t=bin_pow(base,deg/2);
    if (deg&1)
        return t*t%mod1*base%mod1;
    else
        return t*t%mod1;
}
void solve()
{
    ll inv=bin_pow(2,mod1-2);
    ll n;
    cin>>n;
    ll sum=0;
    ll sum_sq=0;
    for (int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        sum+=x;
        if (sum>=mod1)
            sum-=mod1;
        sum_sq+=(x*x)%mod1;
        if (sum_sq>=mod1)
            sum_sq-=mod1;
    }
    sum*=sum;
    sum%=mod1;
    sum-=sum_sq;
    if (sum<0)
        sum+=mod1;
    sum=(sum*inv)%mod1;
    cout<<sum;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
//    cin>>_t;
    _t=1;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3636
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..3 {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

# define REP(i, a, b) for(int i = a; i <= b; ++ i)
# define CLR(i, a) memset(i, a, sizeof(i))
# define REPD(i, a, b) for(int i = a; i >= b; -- i)

typedef long long LL;

const int N = (1 << 16) + 5, B = 16, MOD = 1e9 + 7;

# define gc getchar
inline int rd() {
	char ch = gc(); int ret = 0, sgn = 1;
	while(ch < '0' || ch > '9') { 
		if(ch == '-') sgn = -1;
		ch = gc();
	}
	while(ch >= '0' && ch <= '9') 
		ret = ret * 10 + ch - '0', ch = gc();
	return sgn * ret;
}

int a[4];
int main() {
	a[0] = rd(), a[1] = rd(), a[2] = rd();
	sort(a, a + 3);
	int ans = 0;
	ans += a[2] - a[1];
	a[0] += a[2] - a[1], a[1] = a[2];
	ans += (a[2] - a[0]) >> 1;
	if((a[2] - a[0]) & 1) ans += 2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
S = gets.chomp
N = S.length
MOD = 10**9+7
dp = [1,0,0,0] # 3^count("?"),A,AB,ABC
N.times do |i|
	prev = dp.dup
	c = S[i]
	if c == "A"
		dp[1] += prev[0]
	elsif c == "B"
		dp[2] += prev[1]
	elsif c == "C"
		dp[3] += prev[2]
	else
		dp[1] += prev[1]*2 + prev[0]
		dp[2] += prev[2]*2 + prev[1]
		dp[3] += prev[3]*2 + prev[2]
		dp[0] *= 3
	end
	dp[0] %= MOD
	dp[1] %= MOD
	dp[2] %= MOD
	dp[3] %= MOD
end

p dp[3]


Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}


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

	ll  c, d, n, m, k, ans = 0, ret = M;
	bool flag = false;
	string s, t;
	ll h, w;
	ll a, b;
	cin >> n >> a >> b;
	ll np;
	cin >> np;
	rep(i, n - 1) {
		ll x;
		cin >> x;
		ans += min((x - np) * a, b);
		np = x;
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  map<char, int>m;
  for(char c: s)m[c]++;
  if((m['N']*m['S']==0 && m['N']!=m['S']) || m['E']*m['W']==0 && m['E']!=m['W'])cout << "No";
  else cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC108
{
    class B
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = input[2] - input[0];
            int y = input[3] - input[1];

            Console.WriteLine("{0} {1} {2} {3}", input[2] - y, input[3] + x, input[0] - y, input[1] + x);

        }
    }
}

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

using namespace std;

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
    return 0;
}


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

int main (){
  int m, nmin, nmax;
  while (cin >> m >> nmin >> nmax, m) {
    vector<int> P(m);
    int ans = 0;
    int score = 0;
    for (int i = 0; i < m; i++) cin >> P[i];
    for (int n = nmax; n >= nmin; n--) {
      if (score < P[n - 1] - P[n]) {
	score = P[n - 1] - P[n];
	ans = n;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String strCheck = sc.nextLine();

		Pattern p = Pattern.compile(strCheck, Pattern.CASE_INSENSITIVE);


		int Count = 0;
		while(sc.hasNext()) {

			String strS = sc.next();
			Matcher m = p.matcher(strS);

			if(m.matches()) {
				//System.out.println("????????????????????????");
				Count++;
			}
			if(strS.equals("END_OF_TEXT")) {
				//System.out.println("??????????????????");
				break;
			}
		}
		System.out.println(Count);
	}
}

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

int main()
{
	double x[4], y[4];

	while (cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3]) {
		if ( (y[0]-y[1])*(y[2]-y[3]) == (x[0]-x[1])*(x[3]-x[2]) ) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
	}
	return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n;
    string s1, s2, s3;
    cin >> n >> s1 >> s2 >> s3;

    int ans = 0;
    rep(i, 0, n) {
        set<char> s;
        s.insert(s1[i]); s.insert(s2[i]); s.insert(s3[i]);
        ans += s.size() - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

//positionbit目が立っているか判定
bool contain(int mask, int position){
    if((mask & (1 << position)) != 0) return true;
    else return false;
}

int main(void){
	string s; cin >> s;
	int n = s.size() - 1;
	
	ll sum = 0;
	for(int mask = 0; mask < (1 << n); ++mask){
		int l = 0;//左端
		ll tmp = 0;
		int r;//右端
        for (r = 0; r < n; ++r){
            if(contain(mask, r)){
            	string t = s.substr(l, r - l + 1);
            	ll num = stoll(t);
            	tmp += num;
            	l = r + 1;
            }
        }
        string t = s.substr(l, r - l + 1);
        ll num = stoll(t);
        tmp += num;
        sum += tmp;
    }
    printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Pair>[] g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            int d = sc.nextInt();
            g[l].add(new Pair(r, d));
            g[r].add(new Pair(l, -d));
        }
        int[] p = new int[n];
        boolean[] used = new boolean[n];
        boolean ans = true;
        for (int i = 0; i < n; i++) {
            if(used[i]) continue;
            ArrayDeque<Integer> q = new ArrayDeque<>();
            q.add(i);
            used[i] = true;
            while(!q.isEmpty()){
                int v = q.poll();
                for(Pair na : g[v]){
                    int nv = na.x, nd = na.y;
                    if(used[nv]){
                        if(p[nv] != p[v] + nd){
                            ans = false;
                            break;
                        }
                    }else{
                        p[nv] = p[v] + nd;
                        used[nv] = true;
                        q.add(nv);
                    }
                }
                if(!ans)break;
            }
            if(!ans)break;
        }
        System.out.println(ans ? "Yes" : "No");
        sc.close();

    }

    static class Pair{
        final int x;
        final int y;
        Pair(int x, int y){
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 172196
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;
template<typename T> using VP = vector<pair<T, T>>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion


LL tosa(LL x, LL n) {
	LL y = n / x;
	return x * y * (y + 1) / 2;
}

signed main() {
	LL n;
	cin >> n;

	LL k = 1, ans = 0;
	while (k <= n) {
		ans += tosa(k, n);
		k++;
	}
	
	col(ans);
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> worth(N);
    for (int i = 0; i < N; i++) {
    cin >> worth.at(i);
  }
  vector<int> cost(N);
    for (int i = 0; i < N; i++) {
    cin >> cost.at(i);
  }
  int m = 0;
  for(int i = 0; i < N; i++){
   
    if( (worth.at(i)-cost.at(i)) > 0){
       m = m + worth.at(i)-cost.at(i);
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;


public class Main {
	private static final String df = "deleteFirst";
	private static final String dl = "deleteLast";
	private static final String is = "insert";
	private static final String de = "delete";

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//１行目は命令数
		int n = Integer.valueOf(br.readLine());
		String [] a = new String[2];
		ArrayDeque<Integer> strings = new ArrayDeque<Integer>();

		for(int i=0; i < n; i++){
			a = br.readLine().split("\\s+");
        	if(is.equals(a[0])){
        		//先頭からInsert
        		strings.offerFirst(Integer.parseInt(a[1]));
        	} else if(df.equals(a[0])){
        		strings.pollFirst();
        	} else if(dl.equals(a[0])){
    		    strings.pollLast();
        	} else if(de.equals(a[0])){
        		strings.removeFirstOccurrence(Integer.parseInt(a[1]));
        	}
		}
		System.out.println(strings.toString().replace(",", "").replace("[", "").replace("]", ""));
    }
}



Measured memory_bytes: 569080
import sys
sys.setrecursionlimit(1000000)
from bisect import bisect, bisect_left
def longest_subsequence(sequence):
  subsequence = [float("inf") for _ in range(len(sequence)+1)]
  subsequence[0] = float("-inf")
  for value in sequence:
    j = bisect(subsequence, value)
    if subsequence[j-1] != value: # strict increasing
      subsequence[j] = value
  return bisect_left(dp, float("inf"))-1
# print(longest_subsequence([9, 13, 2, 10, 4, 13, 11, 13]))
# sys.exit()
def dfs(vertex):
  visited[vertex] = True
  value = a[vertex]
  j = bisect(subsequence, value)
  previous = subsequence[j]
  if subsequence[j-1] != value: # strict increasing
    subsequence[j] = value
  ans[vertex] = bisect_left(subsequence, float("inf"))-1
  for node in adjacent[vertex]:
    if not visited[node]:
      dfs(node)
  subsequence[j] = previous
  return
n = int(input())
a = list(map(int, input().split()))
adjacent = {i: [] for i in range(n)}
for _ in range(n-1):
  node1, node2 = map(int, input().split())
  node1 -= 1
  node2 -= 1
  adjacent[node1].append(node2)
  adjacent[node2].append(node1)
visited = [False]*n
ans = [0]*n
subsequence = [float("inf") for _ in range(n+1)]
subsequence[0] = float("-inf")
dfs(0)
[print(value) for value in ans]

Measured memory_bytes: 247396
#include <iostream>
#include <vector>
#define ll long long int

using namespace std;

int main()
{
    int n, d;
    cin >> d >> n;
    if(n== 100)cout << n +1;
    else cout << n;
    for(int i = 0 ; i < d ; i++){
        cout << "00";
    }
    return 0;
}











Measured memory_bytes: 256
#include<iostream>
#include <malloc.h>
#include <vector>
#include<queue>
#include <algorithm>
#include<map>

using namespace std;


int main(){
  map<string,int> map;
  int n,m;
  cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >>s;
    map[s] += 1;
  }
  cin >> m;
  for(int i=0;i<m;i++){
    string s;
    cin >>s;
    map[s] -= 1;
  }
  int max = 0;
  for(auto it = map.begin(); it != map.end(); ++it ){
    if(max<it->second) max = it->second;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
# frequency
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
seq = []
freq = [0 for i in range(N+1)]
D = defaultdict(list)
minD = defaultdict(int)
for i, v in enumerate(A):
    D[v].append(i+1)
for key in D.keys():
    minD[key] = min(D[key])
for cnt in D.keys():
    seq.append((cnt, len(D[cnt]), minD[cnt]))
seq.append((0, 0, 0))
seq.sort(key=lambda x: -x[0])
now_height, now_size, now_min = seq[0]
# howmany,group_size,minimum
for i in range(1, len(seq)):
    freq[now_min] += (now_height-seq[i][0]) * now_size
    now_min = min(now_min, seq[i][2])
    now_size += seq[i][1]
    now_height = seq[i][0]
for i in range(1, N+1):
    print(freq[i])

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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d = a / b;
    int r = a % b;
    double f = double(a) / double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int i=0,ngaymua=0;
	cin>>s;
    if (s[i+1]=='R'){ngaymua=ngaymua+1;}
	else ngaymua=ngaymua;
	if (ngaymua==1 and(s[i]=='R' or s[i+2]=='R')){ngaymua=2;}
	if (s=="RRR"){ngaymua=3;}
	if (s[i+1]=='S' and (s[i]=='R' or s[i+2]=='R' or (s[i]=='R' and s[i+2]=='R'))){ngaymua=1;}
	if (s=="SSS"){ngaymua=0;}
	cout<<ngaymua;
	
	
	return 0;
}


Measured memory_bytes: 3608
def main():
    
    deck = set()
    for item in range(1,14):
        deck = deck | {('H ' + str(item))}
        deck = deck | {('D ' + str(item))}
        deck = deck | {('C ' + str(item))}
        deck = deck | {('S ' + str(item))}
    suits_order = ['S', 'H', 'C', 'D']
    
    n = int(input())
    cards = [input() for i in range(n)]
    remains = sorted(sorted(list(deck - set(cards)), key = lambda x: int(x[2:])), key = lambda x: suits_order.index(x[:1]))
    for item in remains:
        print(item)


main()

Measured memory_bytes: 7720
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<double> T(N), V(N);
    vector< pair< double,double > > P;
    
    for ( int i = 0; i < N; i++ ) {
        cin >> T[i];
    }
    for ( int i = 0; i < N; i++ ) {
        cin >> V[i];
    }
    double t = 0;    
    for ( int i = 0; i < N; i++ ) {
        P.push_back( make_pair( t+0.5, V[i] ) );
        t += T[i];
    }
    P.push_back( make_pair( t+0.5, 0 ) );
    
    double ans = 0;
    double v = 0;
    for ( double time = 0.5; time <= t; time += 0.5 ) {
        
        double v_limit = 1000000;
        for ( int i = 0; i <= N; i++ ) {
            if ( P[i].first > time ) { v_limit = min( v_limit, P[i].first - time - 0.5 + P[i].second );  continue; }
            v_limit = P[i].second;
        }
        
        double v_new;
        if ( v+0.5 <= v_limit ) { v_new = v + 0.5; } 
        else if ( v > v_limit ) { v_new = v - 0.5; }
        
        ans += v*0.5;
        if ( v != v_new ) { ans += v < v_new ? (0.5*0.5)/2.0 : -(0.5*0.5)/2.0; }
        
        v = v_new;
        
        // cout << time << " " << v << endl;
    }
    
    
    printf( "%.7f", ans );
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int n,k,c,t;
int a[10];
bool y(int x)
{
    for(;x;x/=10)
    if(a[x%10])
        return false;
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<k;i++)
      {
         scanf("%d",&t);
         a[t]=1;
      }
    while(!y(n))
    {
        n++;

    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,T;
  cin >> N >> T;
  int A[N],B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  int DP[N][T+1];
  int invDP[N][T+1];
  for (int i = 0; i <= T; i++) {
    if (A[0] <= i) {
      DP[0][i] = B[0];
    } else {
      DP[0][i] = 0;
    }
  }
  for (int i = 0; i <= T; i++) {
    if (A[N-1] <= i) {
      invDP[N-1][i] = B[N-1];
    } else {
      invDP[N-1][i] = 0;
    }
  }

  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= T; j++) {
      if (A[i] > j) {
        DP[i][j] = DP[i-1][j];
      } else {
        DP[i][j] = max(DP[i-1][j],DP[i-1][j-A[i]] + B[i]);
      }
    }
  }

  for (int i = N-2; i >= 0; i--) {
    for (int j = 0; j <= T; j++) {
      if (A[i] > j) {
        invDP[i][j] = invDP[i+1][j];
      } else {
        invDP[i][j] = max(invDP[i+1][j],invDP[i+1][j-A[i]] + B[i]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < N-1; i++) {
    int res = 0;
    for (int j = 0; j <= T-1; j++) {
      res = max(res,DP[i-1][j] + invDP[i+1][T-1-j]);
    }
    ans = max(ans,res+B[i]);
  }
  ans = max(ans,B[0] + invDP[1][T-1]);
  ans = max(ans,B[N-1] + DP[N-2][T-1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 73932
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define SZ(x) (int)(x.size())
#define F0(i,n) for(int i=0;i<n;i++)
#define F1(i,n) for(int i=1;i<=n;i++)
const int MOD = 1000002013;
const double pi = atan(1.0)*4.0;
const double eps = 1e-8;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
int bc(int n) { return n ? bc((n - 1)&n) + 1 : 0; }

const int N = 100001;
int i, j, k, m, n, l;
int a[N];

int main() {
	//freopen("x.in", "r", stdin);
	string s;
	while (cin >> s) {
		if (s == "zyxwvutsrqponmlkjihgfedcba") cout << -1 << endl; else {
			if (SZ(s) < 26) {
				F0(k, 26) if (count(s.begin(), s.end(), k + 'a') == 0) {
					cout << s + string(1, k + 'a') << endl; break;
				}
			}
			else {
				string p = s;
				next_permutation(s.begin(), s.end());
				while (s.substr(0, SZ(s) - 1) > p) s.pop_back();
				cout << s << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using 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 pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int n, ans = 0;
  map<string, int> gacha;
  cin >> n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s.at(i);
    gacha[s.at(i)]++;
  }
  cout << gacha.size() << endl;
}

Measured memory_bytes: 25020
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vli vector<li>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pi pair<int,int>
#define FOR(i,s,n) for(auto i=s;i<n;++i)
#define FORN(i,s,n) for(auto i=s;i<=n;++i)
#define FORR(i,s,n) for(auto i=s;i>=n;--i)
#define FORE(i,a) for(auto i : a)
#define mp make_pair
const int MOD = 1e9+7;

void solve(int t) {
    int n,k;
    cin >> n >> k;
    vll a(n);
    FOR(i,0,n) {
        cin >> a[i];
    }
    FOR(i,k,n) {
        if(a[i]<=a[i-k]) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }
}

int32_t main()
{
    hyperspeed
    int test=1;
    int t = 1;
    while(test--) {
        solve(t);
        t++;
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 4780
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;

    ll ans = 0;
    RANGE(i, 1, n) {
        if (to_string(i).size() & 1) {
            ans++;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    string S;
    ll res = 0;
    ll b = 0, w = 0;
    cin >> S;
    for (ll i = 0; i < (ll)S.length(); i++)
    {
        if (S[i] == 'W')
        {
            res += b;
        }
        else
        {
            b++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 640
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int n,m;
  cin >> n >> m;
  int light[m][n];
  rep(i,m){
    rep(j,n){
      light[i][j] = 0;
    }
  }
  int k,s;
  rep(i,m){
    cin >> k;
    rep(j,k){
      cin >> s;
      s--;
      light[i][s]++;
    }
  }

  int x;
  int p[m];
  rep(i,m){
    cin >> p[i];
  }

  int cheak[m];
  int cnt = 0;
  for(int i = 0; i < (1 << n); i++){
    rep(j,m) cheak[j] = 0;
    rep(j,n){
      if(i & (1 << j)){
        for(int k = 0; k < m; k++){
          cheak[k] += light[k][j];
        }
      }
    }
    bool flag = true;
    // printf("\n");
    rep(j,m){
      // printf("%d\n", cheak[j]);
      if(cheak[j]%2!=p[j]) flag = false;
    }
    if(flag) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
dp = [0]*(N+1)

for a in A:
    dp[a] += dp[a-1]+1
print(N-max(dp))


Measured memory_bytes: 18860
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int y, m, d;
  scanf("%d/%d/%d", &y, &m, &d);
  if (y > 2019 || y == 2019 && m >= 5)
    cout << "TBD" << endl;
  else
    cout << "Heisei" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define MAX  999999
bool prime[MAX];
using namespace std;

int main(void){
  int n ;
  
  vector<int> dp(0,0);
  //isPrime();

  fill(prime,prime+MAX,true);
  int cnt = 0;
  prime[0]=prime[1]=false;
  for(int i = 2 ; i < MAX ; i ++){
    if(prime[i]){
      cnt += i;
      for(int j = 2 ; j * i < MAX ; j ++){
        prime[i*j] = false;
      }
    dp.push_back(cnt);
    }
  }  
  
  
  while(cin>>n,n)
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 2564
N = int(input())

X = N % 10
a = "pon"
if X ==2 or X ==4 or X ==5 or X ==7 or X ==9:
	a = "hon"
elif X ==0 or X ==1 or X ==6 or X ==8:
	a = "pon"
else:
	a = "bon"
print(a)

Measured memory_bytes: 9108
import array
import collections
import heapq

AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1
 
# Prim?????§??????0?????????????°???¨?????¨????±???????
def compute_mst_prim(max_v, adj_list):
    # pred[u]?????????u???????????¨???????????????????????¨???
    pred = collections.defaultdict(lambda: NO_VERTEX)
    # u??¨pred[u]????????¶???????????????key[u]?????\???
    key = collections.defaultdict(lambda: INF)
    key[0] = 0
    # ??????????????????????????????????????\?????¨????????¨??????
    pq = [(key[v], v) for v in range(max_v)]
    heapq.heapify(pq)
    # ????????????????????\?????????????????\??£???????????????????????????
    in_pq = array.array("B", (True for _ in range(max_v)))
    while pq:
        _, u = heapq.heappop(pq)
        in_pq[u] = False
        for v, v_cost in adj_list[u]:
            if in_pq[v]:
                weight = v_cost
                if weight < key[v]:
                    pred[v] = u
                    key[v] = weight
                    heapq.heappush(pq, (weight, v))
                    in_pq[v] = True
    return (pred, key)

max_v, max_e = map(int, input().split())
adjacency_list = collections.defaultdict(set)
for _ in range(max_e):
    s, t, w = map(int, input().split())
    adjacency_list[s].add(AdjacentVertex(t, w))
    adjacency_list[t].add(AdjacentVertex(s, w))
(_, key) = compute_mst_prim(max_v, adjacency_list)

print(sum(key.values()))

Measured memory_bytes: 50000
use std::io;
use std::cmp;


fn main() {
    let (n, a, b) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };

    let xn = read::<usize>();
    let mut ans = 0;
    for i in 1..n {
        ans += cmp::min(b, (xn[i] - xn[i - 1]) * a);
    }

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


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 6396
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	string S;
	cin >> S;

	stringstream ss;
	int tmp;
	bool flag = true;
	ss << S;
	ss >> tmp;
	if (tmp > 2019)flag = false;
	else if (tmp == 2019) {
		ss.ignore();
		ss >> tmp;
		if (tmp > 4)flag = false;
		else if (tmp == 4) {
			ss.ignore();
			ss >> tmp;
			if (tmp > 30)flag = false;
		}
	}

	if (flag) cout << "Heisei";
	else cout << "TBD";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=200005;
int n,s1,s2,tim,ans;
int win[N],dep[N],in[N],out[N],fa[N],vis[N],dis[N],que[N];
struct edge{int x,y;}e1[N];
struct tree{
	int h[N],ne[N<<1],to[N<<1],tot;
	void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
}T1,T2;
void dfs(int x,int las) {
	dep[x]=dep[las]+1,in[x]=++tim,fa[x]=las;
	for(RI i=T2.h[x];i;i=T2.ne[i])
		if(T2.to[i]!=las) dfs(T2.to[i],x);
	out[x]=tim;
}
int check(int x,int y) {
	if(in[x]>in[y]) swap(x,y);
	if(in[x]<=in[y]&&out[x]>=in[y]) return dep[y]-dep[x]>2;
	if(fa[x]==fa[y]) return 0;
	return 1;
}
void bfs() {
	int he=1,ta=1;
	vis[s1]=1,dis[s1]=0,que[1]=s1;
	while(he<=ta) {
		int x=que[he];++he;
		for(RI i=T1.h[x];i;i=T1.ne[i])
			if(dis[x]+1<dep[T1.to[i]]&&!vis[T1.to[i]])
				vis[T1.to[i]]=1,dis[T1.to[i]]=dis[x]+1,que[++ta]=T1.to[i];
	}
}
int main()
{
	int x,y;
	n=read(),s1=read(),s2=read();
	if(s1==s2) {puts("0");return 0;}
	for(RI i=1;i<n;++i) e1[i].x=read(),e1[i].y=read();
	for(RI i=1;i<n;++i) x=read(),y=read(),T2.add(x,y),T2.add(y,x);
	dep[0]=-1,dfs(s2,0);
	for(RI i=1;i<n;++i) {
		if(check(e1[i].x,e1[i].y)) win[e1[i].x]=win[e1[i].y]=1;
		else T1.add(e1[i].x,e1[i].y),T1.add(e1[i].y,e1[i].x);
	}
	bfs();
	for(RI i=1;i<=n;++i)
		if(win[i]&&vis[i]) {puts("-1");return 0;}
		else if(vis[i]) ans=max(ans,dep[i]+dep[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    string s;
    cin >>s;
    string ans = "No";
    if(s.substr(0,4)=="YAKI") ans="Yes";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define usi unsigned short int
#define F first
#define S second
#define mp make_pair
#define pb push_back

using namespace std;

const int MIN = 1e3 + 2;
const int MXN = 1e6 + 3;
const int INF = 1e9 + 7;
const ll LINF = 1e18 + 15;
const double EPS = 1e-9;

ll x;
ll ans;

int main(){
	cin >> x;
	x--;                     
	ans += (x / 11 * 2);
	if (x % 11 > 5){
		ans += 2;
	}
	else {
	   	ans++;
	}
	cout << ans;
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int ans = S.size();
  
  for(int i = 0;i<2;i++){
    int cnt = 0;
    //(char)(0+'0') = '0'
    //(char)(1+'0') = '1'
    for(int j = 0;j < S.size();j++){
      if(j % 2 == 0 && S[j] != (char)(i+'0')) cnt++;
      if(j % 2 == 1 && S[j] == (char)(i+'0')) cnt++;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import sys
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]

N = int(input())
AB = [inpl() for _ in range(N)]
ABS = [(i+j, num) for num, (i, j) in enumerate(AB)]
ABS.sort(reverse = True)
ans = 0
ctr = True
for _, i in ABS:
    ans += (2*ctr -1)*AB[i][not ctr]
    ctr = not ctr
print(ans)


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

struct Pross 
{
    char pross[11];
    int t;
};

int main() {
    using namespace std;

    int n, q, pre_t, result=0;
    scanf("%d %d", &n, &q);
    Pross pre_pross;
    queue<Pross> Q;

    rep(i, n) {
        scanf("%s %d", pre_pross.pross, &pre_pross.t);
        Q.push(pre_pross);
    }

    while (!Q.empty()) {
        pre_pross = Q.front();
        pre_t = pre_pross.t;
        pre_pross.t -= q;
        if (pre_pross.t < 1) {
            result += pre_t;
            Q.pop();
            printf("%s %d\n", pre_pross.pross, result);
        } else {
            Q.pop();
            Q.push(pre_pross);
            result += q;
        }
        
    }

    return 0;

}


Measured memory_bytes: 3256
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n;
  scanf("%d",&n);
  int num = n/111;
  if(n%111!=0)num++;
  int ans = num * 111;

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 500100;

char s[N];
string w = "";

int main() {

	scanf("%s", s);

	int n = strlen(s);

	for (int i = 0; i < n;) {
		if (s[i] == 'A') {
			w += 'A';
			i += 1;
		} else if (i + 1 < n && s[i] == 'B' && s[i + 1] == 'C') {
			w += 'D';
			i += 2;
		} else {
			w += s[i];
			i++;
		}
	}

	long long res = 0;

	for (int i = w.size() - 1, cnt = 0; i >= 0; i--) {
		if (w[i] == 'A') {
			res += cnt;
		} else if (w[i] == 'D') {
			cnt++;
		} else {
			cnt = 0;
		}
	}

	printf("%lld\n", res);

	return 0;

}

Measured memory_bytes: 3660