akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int mod(1000000007);

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    int x, y;
    cin >> x >> y;

    int t = (x + y) / 3;
    if ((x + y) % 3 || x < t || y < t) {
        cout << 0;
        return 0;
    }

    x -= t, y -= t;

    vector<ll> iv(y + 1);
    iv[1] = 1;
    for (int i = 2; i < sz(iv); i++) {
        iv[i] = (mod - mod / i * iv[mod % i] % mod) % mod;
    }

    ll ret = 1;
    for (int i = 1; i <= y; i++) {
        ret = ret * (x + y - i + 1) % mod * iv[i] % mod;
    }

    cout << ret;

    return 0;
}


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

using namespace std;

int a[200005];
int vis[22];

bool add(int j){
    int cnt = 0, tmp = a[j];
    while(tmp){
        int f = tmp % 2;
        tmp /= 2;
        if(vis[cnt] == 1 && f) return 0;
        cnt++;
    }
    cnt = 0, tmp = a[j];
    while(tmp){
        int f = tmp % 2;
        tmp /= 2;
        if(f) vis[cnt] = 1;
        cnt++;
    }
    return 1;
}

void sub(int j){
    int cnt = 0, tmp = a[j];
    while(tmp){
        int f = tmp % 2;
        if(f) vis[cnt] = 0;
        cnt++;
        tmp /= 2;
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    if(n == 1){
        printf("%d\n", 1);
        return 0;
    }
    long long mx = 0, cnt = 0;
    for(int i = 0; i < n; i++){
        while(add(cnt) && cnt < n) cnt++;
        mx += (cnt - i);
        sub(i);

    }
    printf("%lld\n", mx);
}


Measured memory_bytes: 1024
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1

heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))

print(-sum(a))


Measured memory_bytes: 14180
s=input()
a = []
for i in range(len(s)):
    if s[i] == "0":
        a.append("0")
    elif s[i] == "1":
        a.append("1")
    elif s[i] == "B":
        if len(a) == 0:
            continue
        else:
            a.pop(-1)
ans = ""
for i in range(len(a)):
    ans += a[i]
print(ans)

Measured memory_bytes: 38384
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String n = scan.next();
        String cnt;
        
        String n_top    = n.substring(0,1);
        String n_bottom = n.substring(2,3);
        
        if( n_top.charAt(0) == n_bottom.charAt(0) )cnt = "Yes";
        else cnt = "No";
            
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
typedef bitset<128> bset;

int main(){
	while(true){
		int N;
		cin >> N;
		if(N == 0){ break; }
		vector<bset> m(N);
		for(int i = 0; i < N; ++i){
			int M;
			cin >> M;
			while(M--){
				int p;
				cin >> p;
				m[i][--p] = true;
			}
		}
		int K;
		bset l;
		cin >> K;
		while(K--){
			int p;
			cin >> p;
			l[--p] = true;
		}
		int answer = -1, count = 0;
		for(int i = 0; i < N; ++i){
			if((m[i] & l) == l){
				answer = i + 1;
				++count;
			}
		}
		if(count >= 2){ answer = -1; }
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
package main

import (
	"sort"
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n,t := scanInt(), scanInt()

	ds := make(dishes, n)

	for i := 0; i < n; i++ {
		ds[i] = dish{scanInt(),scanInt()}
	}

	sort.Sort(ds)

	dp := [3001][6001]int{}

	for i := 0; i < n; i++ {
		for j := 0; j < 6001; j++ {
			dp[i+1][j] = dp[i][j]

			if j - ds[i].a < 0 || t-1 < j - ds[i].a {
				continue
			}

			dp[i+1][j] = max(dp[i+1][j], dp[i][j-ds[i].a]+ds[i].b)
		}
	}

	ans := 0
	for i := 0; i < 6001; i++ {
		ans = max(ans, dp[n][i])
	}

	fmt.Println(ans)
}

type dish struct {
	a int
	b int
}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}

type dishes []dish

func (a dishes) Len() int           { return len(a) }
func (a dishes) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a dishes) Less(i, j int) bool { 
	if a[i].a == a[j].a {
		return a[i].b < a[i].b
	}
	return a[i].a < a[j].a
}


Measured memory_bytes: 146048
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(){
   int i,n,m,x[100001],w[100001];
   long s;
    
   scanf("%d %d",&n,&m);
   for (i=0;i<m;i++)
      scanf("%d",&x[i]);
   if (m<=n) {
      puts("0");
      return 0;
   }
   qsort(x,m, sizeof(int),asc);
   m--;
   for (i=0;i<m;i++) w[i]=x[i+1]-x[i];
   qsort(w,m, sizeof(int),asc);
   s=0;
   for (i=m-n;i>=0;i--) s+=w[i];
   printf("%ld\n",s);
   return 0;
}


Measured memory_bytes: 1396
//With mercy of God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define mod 1000000007
#define mod2 998244353
#define ff first
#define ss second
#define pb push_back
#define endl "\n"

#define vi vector<int>
#define si set<int>
#define pii pair<int,int>
#define mii map<int,int>
#define vii vector<pii>
#define sii set<pii>
#define vvi vector<vi>
#define vvii vector<vii>
#define vsi vector<si>

#define in(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define tin(arr,n) int arr[n];in(arr,n)
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;
#define inn(arr,m,n) for(int i=m;i<n;i++)cin>>arr[i];
#define outt(arr,m,n) for(int i=m;i<n;i++)cout<<arr[i]<<" ";cout<<endl;

#define narr int arr[n];in(arr,n)
#define nbrr int brr[n];in(brr,n)

using namespace std;
void solve1();
int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

void solve()
{
    int t;cin>>t;
    while(t--)
    {
        solve1();
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve1();
    return 0;
}
int vis[100005]={0};
vi adj[100005];
void dfs(int a)
{
    if(vis[a]==1)return;
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        dfs(adj[a][i]);
    }
}
void solve1()
{
    int n,m;cin>>n>>m;int a,b;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);adj[b].pb(a);
    }
    a=-1;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            a++;dfs(i);
        }
    }
    cout<<a<<endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	cout<<180*(n-2)<<endl;

	return 0;
}

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,s,si;
vi a;

signed main(){
    I(n);
    a.resize(n);

    REP(i,n){
        I(a[i]);
        s += a[i];
    }

    int ret = 1145141919810LL;
    FOR(i,0,n-1){
        si += a[i];
        ret = min(ret, abs(si-(s-si)));
    }

    cout << ret << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int K, A, B;
    cin >> K >> A >> B;
    for(int i=A; i<=B; i++)
        if(i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,m,s,z,p=0;
    priority_queue<long long> q;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>s;
        q.push(s);
    }
    for(int i=0;i<m;i++){
        z=q.top();
        q.pop();
        z/=2;
        q.push(z);
    }
    for(int i=0;i<n;i++){
        p+=q.top();
        q.pop();
    }
    cout<<p<<'\n';
    return(0);
}

Measured memory_bytes: 4208
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

// 一行読み出し
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// 文字列リバース関数
func strReverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func judge(t int, x int, y int) bool {

	if (x+y) <= t && t%2 == (x+y)%2 {
		return true
	} else {
		return false
	}
}

func main() {
	var n int
	fmt.Scan(&n)

	ls := make([][3]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&ls[i][0], &ls[i][1], &ls[i][2])
	}

	for _, tri := range ls {
		t := tri[0]
		x := tri[1]
		y := tri[2]

		if !judge(t, x, y) {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")

}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	cin >> n;
	int cntOdd = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2 == 1) {
			cntOdd++;
		}
	}

	cout << (cntOdd % 2 == 0 ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }

int main(){

  ll n = in();
  ll k = in();
  ll ko = (n / k);
  ll ans = ko * ko * ko;
  if(k % 2 == 0){
    ko = (n + (k / 2)) / k;
    ans += ko * ko * ko;
  }
  cout << ans << endl;
  
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

struct UnionFind
{
private:
  vi data;
  int cnt;

public:
  UnionFind(int size) : data(size, -1), cnt(size) {}
  bool unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x != y){
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
      cnt -= 1;
    }
    return x != y;
  }
  bool same(int x, int y){ return root(x) == root(y); }
  int root(int x){ return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x){ return -data[root(x)]; }
  int group(){ return cnt; }
};

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

pair<Weight, Edges> Kruskal(const Graph &g)
{
  int n = g.size();
  UnionFind uf(n);
  priority_queue<Edge> Q;
  rep(u, n) vrep(e, g[u]) if (u < e->dst) Q.push(*e);

  Weight total = 0;
  Edges F;
  while (F.size() < n-1 && !Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (uf.unite(e.src, e.dst)) {
      F.push_back(e);
      total += e.weight;
    }
  }
  return pair<Weight, Edges>(total, F);
}

int V, E;
int s, t;
Weight w;

int main()
{
  cin >> V >> E;
  Graph g(V);
  rep(i, E){
    cin >> s >> t >> w;
    g[s].pb(Edge(s, t, w));
    g[t].pb(Edge(t, s, w));
  }

  cout << Kruskal(g).first << endl;

  return 0;
}

Measured memory_bytes: 6936
n = int(input()) 
words = [input() for i in range(n)] 


ans = 'Yes'
head = words[0][0]
memory = []
for w in words:
    if w[0] != head: 
        ans = 'No'
        break
    if w in memory:
        ans = 'No'
        break
    head = w[-1]
    memory.append(w)

print(ans)

Measured memory_bytes: 3060
N, K = map(int, input().split())
Ds = set(input().split())

i = N
while 1:
  S = str(i)
  flag = 1
  for s in S:
    if s in Ds:
      flag = 0
      break
  if flag == 1:
    print(i)
    exit()
  i += 1

Measured memory_bytes: 73200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        while (true) {
            int H = in.nextInt();
            int W = in.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            for (int i = 0; i < H; i++) {
                System.out.print("#");
                for (int j = 1; j < W - 1; j++) {
                    System.out.print(i == 0 || i == H - 1 ? "#" : ".");
                }
                System.out.print("#\n");
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 36740
#include <stdio.h>
#define N 100

int main(){
  int i,j,k,length,count=0;
  int A[N];
  
  scanf("%d",&length);
  for(i=0;i<length;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<length;i++){
    for(j=0;j<length;j++){
      if(A[j]<A[j-1]){
	k=A[j];
	A[j]=A[j-1];
	A[j-1]=k;
	count++;
      }
    }
  }
  
  for(i=0;i<length;i++){
    printf("%d",A[i]);
    if(i!=length-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

static std::string abWord = "AB";

static int countString(const std::string& s) {
  int count = 0;
  for (string::size_type pos = 0; (pos = s.find(abWord, pos)) != string::npos;
       pos += abWord.size()) {
    ++count;
  }
  return count;
}

static int solve(std::vector<std::string> ss) {
  int ret = 0;
  int ba = 0;
  int bx = 0;
  int xa = 0;
  for (const auto& s : ss) {
    ret += countString(s);
    bool const firstB = s[0] == 'B';
    bool const lastA = s[s.size() - 1] == 'A';
    if (firstB && lastA) {
      ba++;
    } else if (firstB && !lastA) {
      bx++;
    } else if (!firstB && lastA) {
      xa++;
    }
  }
  while (true) {
    bool anyChange = false;

    int addition = std::min(bx, ba);
    assert(addition >= 0);
    if (addition > 0) {
      anyChange = true;
      ret += addition;
      ba -= addition;
    }

    addition = std::min(xa, ba);
    assert(addition >= 0);
    if (addition > 0) {
      anyChange = true;
      ret += addition;
      ba -= addition;
    }

    addition = std::min(xa, bx);
    assert(addition >= 0);
    if (addition > 0) {
      anyChange = true;
      ret += addition;
      xa -= addition;
      bx -= addition;
      assert(xa >= 0);
      assert(bx >= 0);
    }
    if (!anyChange) {
      break;
    }
  }
  ret += std::max(ba - 1, 0);
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  std::vector<std::string> ss(n);
  for (int i = 0; i < n; i++) {
    std::cin >> ss[i];
  }
  auto const res = solve(std::move(ss));
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 768
/*
 * main.c
 *
 *  Created on: 2020/07/28
 *      Author: 113896
 */
#include <stdio.h>

#define BSIZE 2000

int main() {

	char ring[BSIZE];
	char target[BSIZE];
	fgets(ring, BSIZE, stdin);
	fgets(target, BSIZE, stdin);

	int length = 0;
	while (ring[length] != '\0') {
		length++;
	}

	int t_length = 0;
	while (target[t_length] != '\0') {
		t_length++;
	}

	int ans = 0;
	int i = 0;
	int j, k;
	while (ring[i] != '\0') {
		k = i;
		j = 0;
		while (target[j] != '\n') {
			if (ring[k] != target[j]) {
				break;
			}
			j++;
			k++;
			if (k >= length-1) k = 0;
		}
		if (j == t_length-1) {
			ans = 1;
			break;
		}
		i++;
	}

	if (ans) printf("Yes\n");
	else printf("No\n");

	return 0;
}



Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], n;
int rmq[N][22];
inline void chkmin(int& a, int b){
	if(a > b) a = b;
}
int toid[N];
int get(int l, int r){
	int m = 31 - __builtin_clz(r - l + 1);
	return min(rmq[l][m], rmq[r - (1 << m) + 1][m]);
}
struct Node{
	int l, r;
	int v1, v2;
	Node(int l = 0, int r = 0) : l(l), r(r){}
	void setminv(){
		v1 = get(l, r);
		v2 = get(toid[v1] + 1, r + 1);
	}
	bool operator<(const Node& an) const{
		return v1 > an.v1;
	}
};
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i], toid[a[i]] = i;
	for(int i = 1; i <= n; i++) rmq[i][0] = rmq[i][1] = a[i];
	for(int j = 2; j < 22; j++)
		for(int i = 1; i <= n; i++){
			int ni = i + (1 << (j - 1));
			rmq[i][j] = rmq[i][j - 1];
			if(ni <= n) chkmin(rmq[i][j], rmq[ni][j - 1]);
		}
	priority_queue<Node> pq;
	Node st(1, n); st.setminv();
	pq.push(st);
	vector<int> sol;
	while(!pq.empty()){
		Node top = pq.top(); pq.pop();
		sol.push_back(top.v1), sol.push_back(top.v2);
		int id1 = toid[top.v1], id2 = toid[top.v2];
		int l = top.l, r = top.r;
		if(l < id1){
			Node psh(l, id1 - 1); psh.setminv();
			pq.push(psh);
		}
		if(id2 - id1 > 1){
			Node psh(id1 + 1, id2 - 1); psh.setminv();
			pq.push(psh);
		}
		if(id2 < r){
			Node psh(id2 + 1, r); psh.setminv();
			pq.push(psh);
		}
	}
	for(int i = 0; i < sol.size(); i++)
		cout << sol[i] << " \n"[i == sol.size() - 1];
	return 0;
}

Measured memory_bytes: 21876
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	//cout << fixed << setprecision(10);
	int a,b; cin>>a>>b;
	if(a>b)cout<<"a > b"<<endl;
	else if(a==b)cout<<"a == b"<<endl;
	else cout<<"a < b"<<endl;

	return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int n,m; cin >> n >> m;
  vector<ll> a(n),b(n),c(m),d(m);
  rep(i,n) cin >> a[i] >> b[i];
  rep(i,m) cin >> c[i] >> d[i];
  rep(i,n){
    ll mn = INF;
    int ans = 0;
    rep(j,m) if(chmin(mn,abs(a[i]-c[j])+abs(b[i]-d[j]))) ans = j+1;
    cout << ans << endl;
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 101
#define MIN -100001
#define _MAX 8


int main(void)
{
	char roman[102];
	char fig[8] = { "IVXLCDM" };
	int value[7] = { 1,5,10,50,100,500,1000 };
	int  sum = 0, b = _MAX;
	while (scanf_s("%s", &roman, MAX) != EOF) {
		for (int i = 0; roman[i] != '\0'; ++i) {
			for (int j = 0; j < 8; ++j) {
				if (roman[i] == fig[j]) {
					if (b >= j) sum += value[j];
					else { sum -= value[b]; sum += value[j] - value[b]; }
					b = j;
				}
			}
		}
		printf("%d\n", sum);
		sum = 0; b = _MAX;
	}
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

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

int main()
{
    int t, x;
    ci >> t >> x;
    
    co << (double)t / x << en;
    
    return 0;
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf8').rstrip()
se = set(S)

print('yes' if len(S) == len(se) else 'no')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
using namespace std;
 
int n,s[50],dp[55][2005],book[55][2005];
 
int solve(int i,int m)
{
    if(book[i][m]){
        return dp[i][m];
    }
    if(m==0){
        book[i][m]=1;
        dp[i][m]=1;
        return dp[i][m];
    }else if(i>=n){
        book[i][m]=1;
        dp[i][m]=0;
        return dp[i][m];
    }
    if(solve(i+1,m)){
        book[i][m]=1;
        dp[i][m]=1;
    }else if(solve(i+1,m-s[i])){
        book[i][m]=1;
        dp[i][m]=1;
    }else{
        book[i][m]=1;
        dp[i][m]=0;
    }
    return dp[i][m];
}
 
int main()
{
    int q,m;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&m);
        if(solve(0,m)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
    return 0;
}



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

int main() {
  string N;
  cin >> N;
  
  int A = N.at(0);
  int B = N.at(1);
  int C = N.at(2);
  int D = N.at(3);
  
  if ((A == B && B == C) || (B == C && C == D)) {
    cout << "Yes" << endl;
  }
  else if ((A == B && B == C) && (B == C && C == D)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string c,b;
    cin >> c;
    cin >> b;
    if(c.at(2)==b.at(0)){
        if(c.at(1)==b.at(1)){
            if(c.at(0)==b.at(2)){
        cout << "YES" << endl;
            }else{cout << "NO" << endl;}
        }else{cout << "NO" << endl;}
    }else{cout << "NO" << endl;}
    }


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

namespace Math_Functions
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var input_x = Console.ReadLine().Split(' ');
            var input_y = Console.ReadLine().Split(' ');
            Int64[] x = new Int64[n];
            Int64[] y = new Int64[n];
            for (int i = 0; i < input_x.Length; ++i) x[i] = int.Parse(input_x[i]);
            for (int i = 0; i < input_y.Length; ++i) y[i] = int.Parse(input_y[i]);
            Int64 p1 = 0, p2 = 0, p3 = 0, ngo = 0;
            for (int i = 0; i < n; ++i)
            {
                Int64 work = Math.Abs(x[i] - y[i]);
                p1 += work;
                p2 += (int)Math.Pow(work, 2);
                p3 += (int)Math.Pow(work, 3);
                if (ngo < work) ngo = work;
            }
            Console.WriteLine(p1);
            Console.WriteLine(Math.Pow(p2, 1 / 2.0));
            Console.WriteLine(Math.Pow(p3, 1 / 3.0));
            Console.WriteLine(ngo);
        }
    }
}


Measured memory_bytes: 9376
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	string s;
	string ans;
	cin >> s;
	ans = s[0];
	int n = s.size() - 2;
	ans += to_string(n);
	ans += s[s.size() - 1];
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  long double x = n / 1.08;
  if (x == (int)x) cout << (int)x << endl;
  else if (n <= ((int)x + 1) * 1.08
           && ((int)x + 1) * 1.08 < n + 1)
    cout << (int)x + 1 << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		int[][] table = new int[10][10];

		Scanner sc = new Scanner(System.in);

		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				table[i][j] = sc.nextInt();
			}
		}

		int result = 0;
		int[] original = new int[5];
		int[] copy = new int[5];
loop:		for(int i = 0; i <= 9999; i++){
			for(int j = 0; j < 4; j++){
				int tmp = (int)Math.pow(10, j + 1);
				original[3 - j] = (i % tmp)/(tmp/10);
				copy[3 - j] = original[3 - j];
			}

//			printArray(original);
//			if(i == 2016){
			original[4] = calcCheckDigit(original, table);
			copy[4] = original[4];
			//debug
//			if(i == 2016){
//				System.out.println(cd);
//			}
			//特定の一桁だけを変える
			int tmpcd;
			for(int j = 0; j < 4; j++){
				for(int k = 1; k <= 9; k++){
					copy[j] = (copy[j] + 1) % 10;
					tmpcd = calcCheckDigit(copy, table);

//					if(i == 2016){
//						printArray(copy);
//						System.out.println("cd "+tmpcd);
//					}
					if(table[tmpcd][copy[4]] == 0){// tmpcd == original[4]){
//						if(i == 2016){
//							printArray(copy);
//						}
//						System.out.println("cont 1");
						continue loop;
					}
				}
				copy[j] = original[j];
			}

			//最後の一桁だけ違う数字の場合
			tmpcd = calcCheckDigit(copy, table);
			for(int j = 1; j <= 9; j++){
				int tmp = (original[4] + j) % 10;

				if(table[tmpcd][tmp] == 0){
//					System.out.println("cont 2");

					continue loop;
				}
			}



			//特定の一桁だけを入れ替える
			for(int j = 0; j < 4; j++){
				if(copy[j] == copy[j + 1]){
					continue;
				}
				swap(copy, j, j + 1);

				tmpcd = calcCheckDigit(copy, table);
//				if(i == 2016){
//					printArray(copy);
//					System.out.println("cd "+tmpcd);
//				}
				if(table[tmpcd][copy[4]] == 0){//tmpcd == copy[4]){
//					if(i == 2016){
//						printArray(copy);
//					}
//					System.out.println("cont 3");

					continue loop;
				}

				swap(copy, j, j + 1);
			}


			result++;
		}

		System.out.println(10000 - result);
	}

	static void printArray(int array[]){
		for(int i = 0; i < array.length; i++){
			System.out.print(array[i]+" ");
		}
		System.out.println();
	}

	static int calcCheckDigit(int[] array, int[][] table){
		int result = table[0][array[0]];

		for(int i = 1; i < 4; i++){
//			System.out.println("result "+result);
			result = table[result][array[i]];
		}

		return result;
	}

	static void swap(int[] array, int a, int b){
		int tmp = array[a];
		array[a] = array[b];
		array[b] = tmp;
	}


}



Measured memory_bytes: 29344
use std::io::prelude::*;

const MOD : u64 = 1_000_000_007;

enum State {
  X(u64),
  Y1(u64),
  Y2(u64),
}

impl State {
  fn value(&self) -> u64 {
    use State::*;
    match &self {
      X(v) => *v,
      Y1(v) => *v,
      Y2(v) => *v,
    }
  }
}

fn main(){
  use State::*;
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).expect("fail to read");
  let mut lines = buf.lines();
  let n : usize = lines.next().unwrap().parse().unwrap();
  
  let S : Vec<&[u8]> = lines.map(|s| s.as_bytes()).collect();
  
  let s0 = if S[0][0] == S[1][0] { 
    X(3) 
  } else { 
    Y1(6) 
  };
  
  let ans = (1 .. n).fold(s0, |s, i| {
    match s {
      Y1(v) => Y2(v),
      X(v) => if S[0][i] == S[1][i] {
          X(v * 2 % MOD)
        } else {
          Y1(v * 2 % MOD)
        },
      Y2(v) => if S[0][i] == S[1][i] {
          X(v)
        } else {
          Y1(v * 3 % MOD)
        },
    }
  });
  println!("{}", ans.value());
    
}

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

int main() {
	int64_t n, k;
	cin >> n >> k;
	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}
	int64_t ans = 0;
	for (int64_t b = k + 1; b <= n; b++) {
		ans += n / b * (b - k);
		if (k <= n % b) {
			ans += n % b - k + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a, v = map (int, input().split())
b, w = map (int, input().split())
t = int(input())
if b > a:
    if  v <= w:
        print("NO")
    elif v > w:
        if a+v*t >= b + w*t:
            print("YES")
        else:
            print("NO")
else:
    if  v <= w:
        print("NO")
    elif v > w:
        if a+(-v)*t <= b + (-w)*t:
            print("YES")
        else:
            print("NO")

Measured memory_bytes: 9196
#include <iostream>
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main(){
	int n;
	int a[60],b[60];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		b[i]=a[i];
	}
	sort(b,b+n);
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]!=b[i]){
			cnt++;
		}
	}
	if(cnt==0||cnt==2){
		puts("YES");
	}
	else
		puts("NO");
	return 0;
}

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

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int mod = 1e9 + 7;

struct matrix{ LL mat[5][5]; }g, g0, ans;
matrix operator*(matrix a, matrix b)
{
    matrix tmp; memset(tmp.mat, 0, sizeof(tmp.mat));
    Rep0(i, 3) Rep0(j, 3) Rep0(k, 3) tmp.mat[i][j] = (tmp.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % mod;
    return tmp;
}
void qpow(matrix &a, int k)
{
    matrix tmp; memset(tmp.mat, 0, sizeof(tmp.mat));
    Rep0(i, 3) tmp.mat[i][i] = 1;
    while (k){
        if (k & 1) tmp = tmp * a;
        a = a * a, k >>= 1;
    }
    a = tmp;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int la = 0;
	ans.mat[0][3] = 1;
	g0.mat[0][0] = 1;
	g0.mat[1][0] = 1, g0.mat[1][1] = 1;
	g0.mat[2][0] = 1, g0.mat[2][2] = 1;
	g0.mat[3][0] = 1, g0.mat[3][1] = 1, g0.mat[3][2] = 1, g0.mat[3][3] = 1;
	Rep(i, m + 1) {
		int x;
		if (i <= m) scanf("%d", &x);
		else x = n + 1;
		memset(g.mat, 0, sizeof(g.mat));
		g.mat[0][0] = 1, g.mat[0][3] = 1;
		g.mat[1][0] = 1, g.mat[1][1] = 1, g.mat[1][3] = 1;
		g.mat[2][0] = 1, g.mat[2][2] = 1, g.mat[2][3] = 1;
		g.mat[3][0] = 1, g.mat[3][1] = 1, g.mat[3][2] = 1, g.mat[3][3] = 2;
		qpow(g, x - la - 1);
		ans = ans * g;
		if (i <= m) ans = ans * g0; 
		la = x;
	}
	
	printf("%d\n", ans.mat[0][0]);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
			System.out.println("Bad");
		} else {
			System.out.println("Good");
		}
	}
}


Measured memory_bytes: 23764
table= [[ [ 0 for i in range(10) ] for j in range(3) ] for k in range(4)]


n = int(input())

for i in range(n):
    b,f,r,v = map(int,input().split())
    table[b-1][f-1][r-1] += v
    
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(' ',end='')
            print(table[i][j][k],end='')
        print()
    if i < 3:
        print('####################',end='\n')




Measured memory_bytes: 5640
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
d=lnii()

mod=998244353

c=Counter(d)
max_key=max(d)

if d[0]!=0 or c[0]!=1:
  print(0)
  exit()

ans=1
patterns=1
for i in range(max_key+1):
  p_num=c[i]
  ans*=patterns**p_num
  ans%=mod
  patterns=p_num

print(ans)

Measured memory_bytes: 24316
#include<stdio.h>
#include<string.h>
#include<math.h>

char wa[]={"WA"};
char ac[]={"AC"};

int main(){
   int n,m;
   scanf("%d %d", &n,&m);
   int aa,ok[n],wa[n];
   for(int i=0;i<n;i++){
   		ok[i] = 0;  //1 is ok
     	wa[i] =0 ; // waの数
   }
   char str[4];
   for(int i=0;i<m;i++){
   	scanf("%d %s", &aa, str);
    if(strcmp(str,ac)==0){
    	ok[aa-1] = 1;
    } 
    if(ok[aa-1]==0){
        wa[aa-1]++ ;
    }
   }
   for(int i=0;i<n;i++){
    	if(wa[i]>0 && ok[i]==0){
        	wa[i] = 0;
        }
   }
   int co=0,cp=0;
   for(int i=0;i<n;i++){
    	if(ok[i]==1){
        	co++ ;
        }
     	if(wa[i]>0){
         	cp = cp + wa[i] ;
        }
   }
	printf("%d %d", co,cp);
   return 0;
 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN 100005
#if !testing
#define cerr if(0)cout
#endif
pi sum1[MAXN],sum2[MAXN];
int32_t main() {
	IAMSPEED
	// set testing to 0 when submitting to judge
	string S,T;cin>>S>>T;
	int n = S.size();
	int m = T.size();
	S.insert(S.begin(),'0');
	T.insert(T.begin(),'0');
	FOR(i,1,n) {
		sum1[i]=sum1[i-1];
		if(S[i]=='A')sum1[i].f++;
		else sum1[i].s++;
	}
	FOR(i,1,m) {
		sum2[i]=sum2[i-1];
		if(T[i]=='A')sum2[i].f++;
		else sum2[i].s++;
	}
	int Q;cin>>Q;
	while(Q--) {
		int a,b,c,d;cin>>a>>b>>c>>d;
		cerr << sum1[b].f-sum1[a-1].f << ' ' << sum1[b].s-sum1[a-1].s << ' ' << sum2[d].f-sum2[c-1].f << ' ' << sum2[d].s-sum2[c-1].s << endl;
		int s1=sum1[b].f-sum1[a-1].f, s2=sum1[b].s-sum1[a-1].s, s3=sum2[d].f-sum2[c-1].f, s4=sum2[d].s-sum2[c-1].s;
		int m1 = (s1-s3);
		int m2 = (s2-s4);
		if(m1<m2)swap(m1,m2);
		m1%=3;
		m2%=3;
		if(m1>0&&m2>0) {
			m2-=3;
		}
		if(m1<0&&m2<0){
			m1+=3;
		}
		if(m1>=0&&m2<=0){
			if((abs(m1)+abs(m2))%3==0)cout << "YES\n";
			else cout << "NO\n";
		} else cout << "NO\n";
	}
}


Measured memory_bytes: 2512
n = int(input())
a = input()
b = input()
c = input()
count = 0
for i in range(n):
  if a[i] == b[i] and b[i] == c[i]:
    count += 0
  elif a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
    count += 1
  else:
    count += 2
print(count)

Measured memory_bytes: 3064
#include<stdio.h>

#define LIMIT 101


int main(){
	int n,u,k,v;
  int i;
	scanf("%d",&n);

  int g[LIMIT][LIMIT] = {};

	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
 		while(k--){
			scanf("%d",&v);
			g[u][v]=1;
		}
	}
	for(i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(j>1)printf(" ");
			printf("%d",g[i][j]);
 		}
		printf("\n");
	}
}



Measured memory_bytes: 2112
# n, k = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
# b = list(map(int, input().split()))
# print(r + max(0, 100*(10-n)))
# print("Yes" if 500*n >= k else "No") 
# s = input()
# a = int(input())
# b = int(input())
# c = int(input())
s = input()
print("Yes" if all( i == '' for i in s.split("hi")) else "No")

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

int main() {
  int N;
    cin >> N;
  int i = 0;
  string S;
  
  while(i < N){
    cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
      break;
    }
    
    else{
      i++;
    }
    
    if(i == N){
      cout << "Three" << endl;
    }
  }
  
}


Measured memory_bytes: 256
T = int(input())
for i in range(T) :
    H, W = map(int, input().split())
    Map = []
    for h in range(H) :
        tmp = list(input())
        Map.append(tmp)
        if "^" in tmp :
            Me_h = h
            Me_w = tmp.index("^")
        if ">" in tmp :
            Me_h = h
            Me_w = tmp.index(">")
        if "v" in tmp :
            Me_h = h
            Me_w = tmp.index("v")
        if "<" in tmp :
            Me_h = h
            Me_w = tmp.index("<")
    N = int(input())
    Meirei = list(input())
    
    for m in range(N) :
        if Meirei[m] == "U" :
            if Me_h > 0 and Map[Me_h - 1][Me_w] == "." :
                Map[Me_h - 1][Me_w] = "^"
                Map[Me_h][Me_w] = "."
                Me_h -= 1
            else :
                Map[Me_h][Me_w] = "^"
        elif Meirei[m] == "D" :
            if Me_h < H-1 and Map[Me_h + 1][Me_w] == "." :
                Map[Me_h + 1][Me_w] = "v"
                Map[Me_h][Me_w] = "."
                Me_h += 1
            else :
                Map[Me_h][Me_w] = "v"
        elif Meirei[m] == "L" :
            if Me_w > 0 and Map[Me_h][Me_w - 1] == "." :
                Map[Me_h][Me_w - 1] = "<"
                Map[Me_h][Me_w] = "."
                Me_w -= 1
            else :
                Map[Me_h][Me_w] = "<"
        elif Meirei[m] == "R" :
            if Me_w < W-1 and Map[Me_h][Me_w + 1] == "." :
                Map[Me_h][Me_w + 1] = ">"
                Map[Me_h][Me_w] = "."
                Me_w += 1
            else :
                Map[Me_h][Me_w] = ">"
        else :
            if Map[Me_h][Me_w] == "^" :
                h = Me_h
                w = Me_w
                while Map[h][w] != "*" and Map[h][w] != "#" and 0 < h :
                    h -= 1
                if Map[h][w] == "*" :
                    Map[h][w] = "."
            elif Map[Me_h][Me_w] == "v" :
                h = Me_h
                w = Me_w
                while Map[h][w] != "*" and Map[h][w] != "#" and h < H -1 :
                    h += 1
                if Map[h][w] == "*" :
                    Map[h][w] = "."
            elif Map[Me_h][Me_w] == ">" :
                h = Me_h
                w = Me_w
                while Map[h][w] != "*" and Map[h][w] != "#" and w < W -1 :
                    w += 1
                if Map[h][w] == "*" :
                    Map[h][w] = "."
            elif Map[Me_h][Me_w] == "<" :
                h = Me_h
                w = Me_w
                while Map[h][w] != "*" and Map[h][w] != "#" and w > 0 :
                    w -= 1
                if Map[h][w] == "*" :
                    Map[h][w] = "."
                    
    for h in range(H) :
        for w in range(W) :
            print(Map[h][w], sep="", end="")
        print()
    if i != T -1 :
        print()
                    
            


Measured memory_bytes: 5688
N=int(input())
S=input().split()
NS = [int(i) for i in S]
def minL():
  ml=[NS[0]]
  for i in range(1,N):
     ml+=[min(ml[i-1],NS[i])]
  return ml  

MINL=minL()
def exist():
    s=0
    for i in range(N):
      if MINL[i]>=NS[i]:
         s+=1
    return s
if __name__=='__main__':
   print(exist())

Measured memory_bytes: 26536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9




int num[26]; // 文字列をxにするのに必要な回数
const char a = 'a';

bool isIn(const char x, string S) {
	bool res = false;
	for (int i = 0; i < S.size() && res == false; i++) res = (S[i] == x);
	return res;
}

string make_next(char x, string S) { // 次の世代はxをなるべく多く残す
	string T;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] != x && S[i + 1] != x) T.push_back(S[i]);
		else T.push_back(x);
	}
	return T;
}

bool isSingle(string S) {
	bool res = true;
	char topc = S[0];
	for (int i = 1; i < S.size() && res; i++) {
		if (S[i] != topc) res = false;
	}
	return res;
}

int main() {
	string S; cin >> S;
	
	for (int i = 0; i < 26; i++) {
		char alpha = char(a + i);
		if (isIn(alpha, S)) {
			string T = S;

			while (!isSingle(T)) {
				T = make_next(alpha, T);
				num[i]++;
			}

		}
		else num[i] = INF;
	}
	
	int ans = INF;
	for (int i = 0; i < 26; i++) ans = min(ans, num[i]);

	cout << ans << endl;

	return 0;
}

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

int box[101];

int main(){
    int n,a,ans=0;;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        a=i;
        for(int j=2;j<=n;j++){
            while(a%j==0){
                box[j]++;
                a/=j;
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(box[i]>=74){
            ans++;
        }
        for(int j=i+1;j<=n;j++){
            if(box[i]>=14&&box[j]>=4){
                ans++;
            }
            if(box[i]>4&&box[j]>=14){
                ans++;
            }
            if(box[i]>=24&&box[j]>=2){
                ans++;
            }
            if(box[i]>=2&&box[j]>=24){
                ans++;
            }
            for(int k=j+1;k<=n;k++){
                if(box[i]>=4&&box[j]>=4&&box[k]>=2){
                    ans++;
                }
                if(box[i]>=4&&box[j]>=2&&box[k]>=4){
                    ans++;
                }
                if(box[i]>=2&&box[j]>=4&&box[k]>=4){
                    ans++;
                }
            }
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
n=int(input())
X=[]
for i in range(n):
    X.append(input())
    
for i in range(n-1):
    if n!=len(set(X)):
        print('No')
        break
    
    if X[i][len(X[i])-1]!= X[i+1][0]:
        print('No')
        break
    
    if i==n-2:
        print('Yes')

Measured memory_bytes: 3060