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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class UnionFind {
    private :
        std::vector<int> par;
    public :
        UnionFind(int n) {
            par.resize(n);
            for (int i=0; i<n; i++) par[i] = i;
        }
        void unite(int x, int y) {
            int xPar = find(x);
            int yPar = find(y);
            if (xPar == yPar) return;

            par[xPar] = yPar;
        }
        int find(int x) {
            if (par[x] == x) return x;
            else return par[x] = find(par[x]);
        }
        bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
    int T;
    cin >> T;

    vector<ll> res(T);
    for (int i=0; i<T; ++i) {
        int N;
        cin >> N;
        vector<tuple<int, int, int>> pl, mi, eq;
        for (int j=0; j<N; ++j) {
            int k, l, r;
            cin >> k >> l >> r;
            if (r - l > 0) pl.push_back({k, l, r});
            else if (r == l) eq.push_back({k, l, r});
            else mi.push_back({k, l, r});
        }

        auto cmp = [](auto p, auto q) {return abs(get<1>(p) - get<2>(p)) > abs(get<1>(q) - get<2>(q));};
        sort(pl.begin(), pl.end(), cmp);
        sort(mi.begin(), mi.end(), cmp);
        ll tmp = 0;
        for (auto p : eq) tmp += get<1>(p);
        UnionFind uf1(N+2);
        for (auto p : pl) {
            int k = get<0>(p), l = get<1>(p), r = get<2>(p);
            int par = uf1.find(k+1);
            if (par == N+1) {
                tmp += l;
            } else {
                tmp += r;
                uf1.unite(par, par+1);
            }
        }
        UnionFind uf2(N+1);
        for (auto p : mi) {
            int k = get<0>(p), l = get<1>(p), r = get<2>(p);
            int par = uf2.find(k);
            if (par == 0) {
                tmp += r;
            } else {
                tmp += l;
                uf2.unite(par, par-1);
            }
        }
        res[i] = tmp;
    }
    for (ll x : res) cout << x << '\n';
}

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

    solve();

    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int cal(int a, int b) {
  return (b - a) / 2;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (a > b) swap(a, b);
  int ans = 0;
  if ((b - a) % 2 == 0) ans = cal(a, b);
  else {
    int r = n - b + 1;
    ans = min(cal(1, b - a) + a, cal(a + r, n) + r);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3656
while True:
    n = int(input())
    if n == 0:break
    s = [input() for _ in range(n)]
    k = 1
    while True:
        a = set()
        f = True
        for j in range(n):
            c = s[j][0]
            for i in range(len(s[j]) - 1):
                if len(c) == k:
                    f = False
                    break
                if s[j][i] in "aiueo":c += s[j][i + 1]
            if c in a:break
            else:a.add(c)
        else:
            print(k)
            break
        k += 1
        if f:
            print(-1)
            break


Measured memory_bytes: 5624
import sys #追加
sys.setrecursionlimit(500*500) #追加

class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.size = [1] * n
    def find(self, x):
        if self.parent[x] == -1:
            return x
        else:
            a = self.find(self.parent[x])
            self.parent[x] = a
            return a
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.parent[x] = y
            self.size[y] += self.size[x]
    def get_size(self, x):
        return self.size[self.find(x)]
    def printout(self):
        print(self.parent)
        print(self.size)

N, M, K = map(int, input().split())
uf = UnionFind(N)

ab = [[int(i)-1 for i in input().split()] for j in range(M)]
cd = [[int(i)-1 for i in input().split()] for j in range(K)]

for a, b in ab:
    uf.union(a, b) #RE

ans =[uf.get_size(i)-1 for i in range(N)]

for a, b in ab:
    ans[a] -= 1
    ans[b] -= 1

for c, d in cd:
    if uf.find(c) == uf.find(d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)

Measured memory_bytes: 75248
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

int n;
vector<P> work; // b, a
ll now;

int main() {
    cin >> n;
    work.assign(n, P(0, 0));
    for(int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        work[i] = make_pair(b, a);
    }
    sort(work.begin(), work.end());

    bool ok = true;
    for(auto w : work) {
        ll b = w.first;
        ll a = w.second;
        now += a;
        if(b < now)
            ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

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

main(){
  int N,A,B;
  cin >> N >> A >> B;
  //cout << min(A,B) << to_string((A+B-N>=0)?A+B-N:0) << endl;//数字をstringjにも
                                                            //どす
  cout << min(A,B) << " " << (A+B-N>=0?A+B-N:0) << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := ReadInt()
	A := ReadInts(N)
	s := 0
	for i := 0; i < N; i++ {
		s += A[i]
		s %= Mod
	}
	ans := 0
	for i := 0; i < N; i++ {
		s = s + Mod - A[i]
		s %= Mod
		ans += A[i] * s % Mod
		ans %= Mod
	}
	fmt.Println(ans)
}

const Mod = int(1e9) + 7

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 5988
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N], B[MAX_N];
bool D[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
	}
	rep(i, 0, N) {
		cin >> B[i];
	}
	if(B[0] < A[0] || B[N - 1] > A[N - 1]) {
		cout << 0 << "\n"; return;
	}
	rep(i, 1, N - 1) {
		if(A[i] != A[i - 1]) {
			D[i] = true;
			if(A[i] > B[i]) {
				cout << 0 << "\n"; return;
			}
		}
	}
	rer(i, N - 1, 1) {
		if(B[i] != B[i + 1]) {
			if(D[i]) {
				if(A[i] != B[i]) {
					cout << 0 << "\n"; return;
				}
			}
			else {
				if(A[i] < B[i]) {
					cout << 0 << "\n"; return;
				}
			}
			D[i] = true;
		}
	}
	ll res = 1;
	rep(i, 1, N - 1) {
		MUL(res, D[i] ? 1 : min(A[i], B[i]));
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1920
#include<stdio.h>

int main(){
  int n,i,j,k,x,ans;

  while(1){
    scanf("%d %d",&n, &x);
	if(n == 0 && x == 0) break;
	  ans = 0;
	  for(i = 1; i <= n - 2; i++){
	    for(j = i + 1; j <= n - 1; j++){
		  for(k = j + 1; k <= n; k++){
		    if(x == i + j + k) ans++;
		  }
	    }
	  }
  	  printf("%d\n",ans);
    }
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main()
{
    int a,b,c=0;
    string s;
    cin >>a>>b;
    cin >>s;
    bool flag=false;
    if(s[a]=='-'){
            c++;
        for(int i=0;i<s.size();i++){
            if(s[i]>='0' && s[i]<='9'){
                //flag = true;
                c++;
            }
        }
        if(c==s.length()){
            flag = true;
        }
    }
    if(flag){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  string s; cin >> s;
  int a = s[0] == 'R', b = s[2] == 'R';
  cout << (s[1] == 'S' ? max(a, b) : 1 + a + b) << endl;

  return 0;
}


Measured memory_bytes: 3648
import operator as op

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b, c])
for a in A:
    BC.append([1, a])
BC_sort = sorted(BC, key=op.itemgetter(1), reverse=True)
rest = N
ans = 0
for i in range(len(BC_sort)):
    if rest >= BC_sort[i][0]:
        ans += BC_sort[i][0] * BC_sort[i][1]
        rest -= BC_sort[i][0]
    elif 0 <= rest < BC_sort[i][0]:
        ans += rest * BC_sort[i][1]
        break
print(ans)


Measured memory_bytes: 39240
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int   ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N;
        cin>>N;
        N%=10;
        if(N==2||N==4||N==5||N==7||N==9)
            cout<<"hon"<<endl;
        else if(N==0||N==1||N==6||N==8)
            cout<<"pon"<<endl;
        else
            cout<<"bon"<<endl;
    }
}

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int x,y;
	cin >> x >> y;
	cout << x + y/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m,tot;
vector<int> G[MAXN];
int val[MAXN];
int p[MAXN],r[MAXN];
void init(int n)
{
    for(int i=1;i<=n;i++)
    {
        p[i]=i;
        r[i]=0;
    }
}
int find(int x)
{
    if(p[x]==x) return x;
    else return p[x]=find(p[x]);
}
void unite(int x,int y)
{
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) p[x]=y;
    else
    {
        p[y]=x;
        if(r[x]==r[y]) r[x]++;
    }
}
bool same(int x,int y)
{
    return find(x)==find(y);
}
void add_edge(int u,int v)
{
    G[u].push_back(v);
    G[v].push_back(u);
}
struct node
{
    int x,y,z;
};
vector<node> ans;
int dfs(int v,int p)
{
    int last=0;
    for(auto to:G[v])
    {
        if(to==p) continue;
        int ret=dfs(to,v);
        if(ret==0)
        {
            if(last==0) last=to;
            else
            {
                ans.push_back((node){last,v,to});
                last=0;
            }
        }
        else ans.push_back((node){ret,to,v});
    }
    return last;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) val[i]=i;
    init(n);
    tot=n;
    for(int i=0;i<m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        if(same(u,v))
        {
            tot++;
            val[tot]=u;
            add_edge(tot,v);
        }
        else 
        {
            unite(u,v);
            add_edge(u,v);
        }
    }
    if(dfs(1,0)) {puts("-1"); return 0;}
    for(auto p:ans) printf("%d %d\n%d %d\n",val[p.y],val[p.x],val[p.y],val[p.z]);
    return 0;
}



Measured memory_bytes: 15352
//Volume5-0502
import java.util.*;

class Main {
	
	private static int[][][] t = {{{1,2,3},{2,3,4}},
		                          {{2,2,0},{5,4,2}},
		                          {{0,0,3},{1,3,5}}};
	
	private static int[] dice;
	private static int   sum;
	
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int n;
		String s;
		while((n=sc.nextInt())!=0){
			init();
			while(n-- > 0){
				s=sc.next();
				if     (s.equals("North")){change(0,0);}
				if     (s.equals("South")){change(0,1);}
				else if(s.equals("East")) {change(1,0);}
				else if(s.equals("West")) {change(1,1);}
				else if(s.equals("Right")){change(2,0);}
				else if(s.equals("Left")) {change(2,1);}
				sum+=dice[2];
			}
			System.out.println(sum);
		}
	}

	private static void init(){
		sum  = 1;
		dice = new int[6];
		int[] init = {4,5,1,2,6,3}; 
		for(int i=0;i<6;i++){
			dice[i] = init[i];
		}
	}

	private static void change(int a,int b){
		int init,limit,incr;
		if   (b==0){init=0; limit=3 ; incr= 1;}
		else       {init=2; limit=-1; incr=-1;}
		for(int i=init;i!=limit;i+=incr){
			swap(t[a][0][i],t[a][1][i]);
		}
	}
	
	private static void swap(int i,int j){
		dice[j]  = dice[i] - dice[j];
		dice[i] -= dice[j];
		dice[j] += dice[i];
	}
}

Measured memory_bytes: 25364
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;


int main() {
    int N;
    string S;
    cin >> N >> S;
    int c = 0;
    rep(i, N-2) {
        if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        class modMCalc
        {
            private const int M = 1000000007;       // 素数(int範囲)

            // 乗算結果 % Mを求める
            static public int Mul(int a, int b)
            {
                return (int)(Math.BigMul(a, b) % M);
            }

            // 冪乗(mod M)
            static public int Pow(int a, int m)
            {
                if (0 == m)
                {
                    return 1;
                }
                if (1 == m)
                {
                    return a;
                }

                int result = 1;
                int param = a;
                for (; m > 0; m >>= 1)
                {
                    if ((m & 0x01) == 1)
                    {
                        result = Mul(result, param);
                    }

                    param = Mul(param, param);
                }

                return result;
            }

            // 除算(mod M)
            static public int Div(int a, int b)
            {
                return Mul(a, Pow(b, M - 2));
            }
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int[] v = new int[(N + 1) / 2];

            bool isEven = true;
            if (1 == (N % 2))
            {
                v[0] = 1;
                isEven = false;
            }

            for (int i = 0; i < N; i++)
            {
                int v0 = int.Parse(s[i]);
                if (isEven)
                {
                    if (0 == (v0 % 2))
                    {
                        Console.WriteLine(0);
                        return;
                    }
                }
                else
                {
                    if (1 == (v0 % 2))
                    {
                        Console.WriteLine(0);
                        return;
                    }
                }

                v[v0 / 2]++;
            }

            for (int i = 0; i < N / 2; i++)
            {
                if (2 != v[i])
                {
                    Console.WriteLine(0);
                    return;
                }

            }

            Console.WriteLine(modMCalc.Pow(2, N / 2));
        }
    }
}


Measured memory_bytes: 18656
transpose :: [[Int]] -> [[Int]]
transpose ([]:_) = []
transpose m = (map head m):(transpose (map tail m))

calcCi :: [Int] -> [[Int]] -> [Int]
calcCi _ [] = []
calcCi x (y:ys) = (sumProduct x y):(calcCi x ys)
  where
      sumProduct :: [Int] -> [Int] -> Int
      sumProduct x y = sum $ zipWith (*) x y

mulAB :: [[Int]] -> [[Int]] -> [[Int]]
mulAB [] _ = []
mulAB (x:xs) y = (calcCi x yt):(mulAB xs y)
  where
      yt = transpose y

readMatrix :: Int -> Int -> IO [[Int]]
readMatrix 0 c = return []
readMatrix r c = do
    rows  <- getLine >>= return.(map $ \n -> read n :: Int).words
    rests <- readMatrix (r-1) c
    return $ rows:rests

printMatrix :: [[Int]] -> IO ()
printMatrix = mapM_ (\nums -> putStrLn $ unwords [show n | n <- nums])

main :: IO ()
main = do
    [n,m,l] <- getLine >>= return.(map $ \n -> read n :: Int).words
    a <- readMatrix n m
    b <- readMatrix m l
    printMatrix $ mulAB a b



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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  bool ok = true;

  cin >> n;
  map<ll,ll> a{};
  rep(i,n){
    ll m;
    cin >> m;
    if(a[m] == 0){
      a[m]++;
    }
    else{
      ok = false;
      break;
    }
  }
    
  
  
  if(ok)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

template <typename T>
struct cumsum{
    vector<T> V;
    ll L;
    cumsum(vector<T> &v) : V(v){     
        L = V.size();
        for(int i=1;i<L;i++) V[i] += V[i-1];
    } 
    T query(int a, int b){
        if(a == b) return 0;
        T ret = V[b-1];
        if(a > 0) ret -= V[a-1];
        return ret;
    }
};

int N;
string S;

int main(){
    cin >> N;
    cin >> S;
    vector<int> v(N,0);
    for(int i=0;i<N;i++) if(S[i] == '.') v[i]=1;
    cumsum<int> cs(v);
    int ans = 1e8;
    for(int i=0;i<=N;i++){
        int b = i - cs.query(0,i);
        int w = cs.query(i,N);
        ans = min(ans, b+w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

    int x, n, mx = 0;
    cin >> n;

    map<string, int> hsh;
    string s;

    for (int i = 0; i < n; ++i)
    {
        cin >> s;
        ++hsh[s];
        mx = max(mx, hsh[s]);
    }

    for (auto i : hsh)
    {
        if (i.second == mx)
            cout << i.first << endl;
    }
    return 0;
}

Measured memory_bytes: 25088
from sys import stdin

n, m = map(int, stdin.readline().split())
a = [int(num) for num in stdin.readline().split()]

cnt_list = [(a[i], 1) for i in range(n)]
for i in range(m):
    b, c = map(int, stdin.readline().split())
    cnt_list.append((c, b))

cnt_list.sort()
cnt_list.reverse()

cnt = n
ans = 0

for (k, v) in cnt_list:
    acc_v = min(v, cnt)
    ans += k * acc_v
    cnt -= acc_v


print(ans)


Measured memory_bytes: 29316
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<r;i++)
using namespace std;
ll dp[100001],n,h[100001];
ll solve(int i)
{
    if(dp[i]!=-1)
        return dp[i];
    if(i==n-1)
        return 0;
    if(i<n-2)
        return dp[i]=min(abs(h[i]-h[i+1])+solve(i+1),abs(h[i]-h[i+2])+solve(i+2));
    return dp[i]=abs(h[i]-h[i+1])+solve(i+1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    f(i,0,n){
        dp[i]=-1;
        cin>>h[i];
    }
    dp[n]=-1;
    ll ans=solve(0);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3328
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7


    def countZero(n):
        return len(str(n))-len(str(n).rstrip('0'))
    
    def f(n):
        if n < 2:
            return 1
        else:
            n2 = f(n-2)
            if n % 10 != 0 and countZero(n2) != countZero(n2*n):
                print(n,n2)
            return n * n2
    N = II()
    # fn = f(N)
    # print(fn)
    # print(countZero(fn))
    if N % 2 == 1:
        print(0)
        return
    else:
        ans = 0
        b = 10
        while (N-b)//b +1 > 0:
            ans += (N-b)//b +1
            b *= 5
        print(ans)
        # 10,20,30,40,50,100,110,200,1000,1010,1100,1200
        #50,150,250,950,1050,
        #250,750,1250
        #1250,2750
        return
if __name__ == '__main__':
    main()

Measured memory_bytes: 38448
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int main(){
    ll n;
    string a, b;
    cin>>n>>a>>b;
    //ll n = a.size();
    loop(n){
        cout<<a[i]<<b[i];
    }
    return 0;
}

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

int main(){
    int64_t T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if(A1 < B1){
        swap(A1, B1);
        swap(A2, B2);
    }
    int64_t d1 = T1*(A1-B1);
    int64_t d2 = T2*(A2-B2);
    int64_t d = d1 + d2;
    if(d > 0){
        cout << 0 << endl;
        return 0;
    }
    if(d == 0){
        cout << "infinity" << endl;
        return 0;
    }

    int64_t c1 = d1 / abs(d);
    int64_t ans = 2*c1 + (d1%abs(d) > 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
const ll  big =1e3+5;
pair <ll,ll> p1[big],p2[big];
ll a[big][big];
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

ll n;
cin>>n;
cout<<n+n*n+n*n*n;

    return 0;
}

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

void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main()
{
    c_p_c();
    int n;
    cin >> n;
    cout << n + pow(n, 2) + pow(n, 3) << endl;

    return 0;


}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string s;
    cin >> s;

    rep(idx, 19){
        if(idx == 5 || idx == 13) cout << " ";
        else cout << s[idx];
    }
    cout << endl;
}

Measured memory_bytes: 256
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heappushpop, heapreplace
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['NET', 'DA']
############# CODE STARTS HERE #############


test_case=1
while test_case:
    test_case-=1


    n=ii()
    print(n+n**2+n**3)

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




int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, K; cin >> N >> K;
  vector<int> A(N), B;
  int ans = 1;
  set<int> S;
  for (int i = 0; i < N; ++i) {
    cin >> A[i]; 
  }
  for (int i = 0; i < K; ++i) {
    S.insert(A[i]);
  }
  for (int i = K; i < N; ++i) {
    bool id = true;
    id &= A[i - K] == *S.begin();
    S.erase(A[i - K]);
    S.insert(A[i]);
    id &= A[i] == *S.rbegin();
    if (not id) ++ans;
  }
  vector<int> ok(N, 1);
  for (int i = 1; i < N; ++i) {
    if (A[i - 1] < A[i]) ok[i] = ok[i - 1] + 1;
    else ok[i] = 1;
  }
  bool first = 0;
  for (int i = K - 1; i < N; ++i) {
    if (first and ok[i] == K) --ans;
    first |= ok[i] >= K;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 11264
import sys
sys.setrecursionlimit(3000)
def d(i,j):
    global count
    c[i][j]=1
    for k in range(3):
        for l in range(3):
            if 0<=i+k-1 and i+k<=h and 0<=j+l-1 and j+l<=w:
                if c[i+k-1][j+l-1]==0 and ma[i+k-1][j+l-1]==1:
                    d(i+k-1,j+l-1)
while(1):
    w,h=map(int,input().split())
    if w!=0 or h!=0:
        ma=[]
        for z in range(h):
            r=list(map(int,input().split()))
            ma.append(r)
        c=[[0]*w for e in range(h)]
        count=0
        for x in range(h):
            for y in range(w):
                if c[x][y]==0 and ma[x][y]==1:
                    d(x,y)
                    count+=1
        print(count)
    else:
        break
        break


Measured memory_bytes: 8020
#include <cstdio>

int main()
{
    int i, j, n;
    char mark;
    char marks[4] = {'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13] = {false};

    scanf("%d ", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%c %d ", &mark, &num);
        for (j = 0; j < 4; j++)
        {
            if (mark == marks[j])
            {
                cards[j][num - 1] = true;
                break;
            }
        }
    }
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 13; j++)
        {
            if (cards[i][j] == false)
            {
                printf("%c %d\n", marks[i], j + 1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,c;
cin>>n>>m>>c;
int arr[m];
for(int i=0;i<m;i++) cin>>arr[i];
int cnt=0;
while(n--){
    int temp[m];
    int ans=0;
    for(int i=0;i<m;i++){
        cin>>temp[i];
        ans+=(arr[i]*temp[i]);
    }
    ans+=c;
    if(ans>0) cnt++;
}
cout<<cnt<<endl;
return 0;
}


Measured memory_bytes: 256
#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);

  ll n, a, b;
  cin >> n >> a >> b;

  if ((b - a) % 2 == 0)
    cout << (b - a) / 2 << endl;
  else {
    ll a1 = min(b - 1, a + (b - a - 1) / 2);
    ll t = n - b + 1;
    ll a2 = min(n - a, t + (n - (a + t)) / 2);
    cout << min(a1, a2) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll n,m,k,l,g,i,h,t,w,rev,f,q; char c;
    	string a,b,s;
    	cin>>s;
    	cin>>q;
    	rev=0;
    	rep(i,0,q)
    	{
    		cin>>t;
    		if(t==1)
    		rev++;
    		else
    		{
    			cin>>f>>c;
    			if(f==1)
    			{
    				if(rev%2==0)
    				a=c+a;
    				else
    				b+=c;
				}
				else
				{
					if(rev%2==0)
    				b+=c;
    				else
    				a=c+a;
				}
			}
		}
    	if(rev%2==0)
    	cout<<(a+s+b);
  		else
  		{
  			reverse(all(a));
  			reverse(all(s));
  			reverse(all(b));
  			cout<<(b+s+a);
		}
    	
	}
	return 0;
}

Measured memory_bytes: 1416
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;
    char ans[11];
    int idx = 0;
    rep (i, s.size())
    {
        if (s[i] == 'B')
        {
            if (idx > 0) --idx;
        }
        else
        {
            ans[idx++] = s[i];
        }
    }
    ans[idx] = '\0';

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    set<string> se;
    rep(i, N){
        string s;
        cin >> s;
        se.insert(s);
    }
    cout << se.size();
}

Measured memory_bytes: 19156
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int min = Math.min(a,b);
		int max = Math.max(a,b);
		
		String s = String.valueOf(min);
		String ans = s;
		
		for(int i =1; i<=max-1; i++){
		
		s += ans;
		}
		
		
		System.out.println(s);

	}
}

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

int main() {
    int N;
    cin >> N;
    long long name[5] = {0};
    string s;
    for(int i=0; i<N; ++i) {
        cin >> s;
        switch(s[0]){
            case 'M': name[0] += 1; continue;
            case 'A': name[1] += 1; continue;
            case 'R': name[2] += 1; continue;
            case 'C': name[3] += 1; continue;
            case 'H': name[4] += 1; continue;
            default: continue;
        }
    }
    long long ans = 0;
    for(int i=0; i<=2; ++i) {
        for(int j=i+1; j<=3; ++j) {
            for(int k=j+1; k<=4; ++k) {
                ans += name[i] * name[j] * name[k];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,i, count;
    cin >> N;
    string S;
    cin >> S;
    i = 0;
    count = 0;
    while(i < N){
        i = (int)S.find("ABC", i);
        if(i < 0) break;
        count++;
        i += 3;
    }
    cout << count << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int h[10];
	while (cin >> h[1], h[1]) {
		cin >> h[2] >> h[3] >> h[4] >> h[5];
		int g = 0, c = 0, p = 0;
		for (int i = 1; i <= 5; i++) {
			if (h[i] == 1)g = 1;
			else if (h[i] == 2)c = 1;
			else if (h[i] == 3)p = 1;
		}
		if ((g + c + p) % 2 != 0)for (int i = 0; i < 5; i++)cout << "3\n";
		else {
			int w;
			if (g == 0)w = 2;
			else if (c == 0)w = 3;
			else if (p == 0)w = 1;
			for (int i = 1; i <= 5; i++)if (h[i] == w)cout << 1 << endl; else cout << 2 << endl;
		}
	}return 0;
}


Measured memory_bytes: 3004
import math

n = int(input())
lst = [list(map(int, input().split())) for _ in range(n)]

def max_multi(a,b,d,c):
        length = b-a
        n = math.ceil((d-a)/2)
        if n < 0:
            n = 0
        elif n > length:
            n = length
        x = (a+n)*(d-n)
        n = math.floor((d-a)/2)
        if n < 0:
            n = 0
        elif n > length:
            n = length
        y = (a+n)*(d-n)
        return max(x,y)

def check(a, b, n):
    multi = a*b
    if n<a:
        return True
    else:
        if a<= n < b:
            #second_1 = [i for i in range(1, n+1)][::-1]
            second_1 = (n,1)
            second_2 = (0,0)
        else:
            #second_1 = [i for i in range(1, b)][::-1]
            second_1 = (b-1,1)
            #second_2 = [i for i in range(b+1, n+2)][::-1]  
            second_2 = (n+1, b+1)
        m = (second_2[0] - second_2[1])+1
        #print('m :', m)
        if second_2 == (0,0):
            a1,b1,c1,d1 = 1, a-1, second_1[0], second_1[0]-(a-2)
            a2,b2,c2,d2 = a+1, n+1, second_1[0]-(a-1), second_1[1]
            #print(a1,b1,c1,d1)
            #print(a2,b2,c2,d2)
            s = max(max_multi(a1,b1,c1,d1), max_multi(a2,b2,c2,d2))
        elif m == a-1:
            a1,b1,c1,d1 = 1, a-1, second_2[0], second_2[1]
            a2,b2,c2,d2 = a+1, n+1, second_1[0], second_1[1]
            #print(a1,b1,c1,d1)
            #print(a2,b2,c2,d2)
            #print(max_multi(a1,b1,c1,d1), max_multi(a2,b2,c2,d2))
            s = max(max_multi(a1,b1,c1,d1), max_multi(a2,b2,c2,d2))
        elif m > a-1:
            a1,b1,c1,d1 = 1, a-1, second_2[0], second_2[0]-(a-2)
            a2,b2,c2,d2 = a+1, m+1, second_2[0]-(a-1), second_2[1]
            a3,b3,c3,d3 = m+2, n+1, second_1[0], second_1[1]
            #print(a1,b1,c1,d1)
            #print(a2,b2,c2,d2)
            #print(a3,b3,c3,d3)
            s = max(max_multi(a1,b1,c1,d1), max_multi(a2,b2,c2,d2), max_multi(a3,b3,c3,d3))
        else:
            a1,b1,c1,d1 = 1,m,second_2[0], second_2[1]
            a2,b2,c2,d2 = m+1, a-1, second_1[0], second_1[0]-(a-m-2)
            a3,b3,c3,d3 = a+1, n+1, second_1[0]-(a-m-1), second_1[1]
            #print(a1,b1,c1,d1)
            #print(a2,b2,c2,d2)
            #print(a3,b3,c3,d3)
            s = max(max_multi(a1,b1,c1,d1), max_multi(a2,b2,c2,d2), max_multi(a3,b3,c3,d3))
        return True if s < multi else False

def search(a,b):
    a,b = min(a,b), max(a,b)
    low = 0
    high = 10**30
    while high - low > 1:
        if check(a,b,(low+high)//2):
            low = (low+high)//2
            #print('low :', low)
        else:
            high = (low+high)//2
            #print('high :', high)
    return high if check(a,b,high) else low

for i in lst:
    print(search(i[0], i[1]))

Measured memory_bytes: 3316
#include <stdio.h>

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

  return 0;
}

Measured memory_bytes: 600
while True:
    h,w = map(int, input().split())
    if (w + h) == 0:
        break

    for i in range(h):
        for j in range(w):
            if (j + i)%2 == 0:
                print("#",end="")
            else:
                print(".",end="")
        print()

    print("")



Measured memory_bytes: 7000
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for (int i = 1; i < 10; i++) {
      for (int j = 1; j < 10; j++) {
        if (n == i * j) {
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
    using namespace std;
    int main(){
        int n;
        cin>>n;
        int t;
        vector<int> fi(100001),se(100001);
        int fic=0,sec=0;
        for(int i = 0; i< n; i++){
            cin>>t;
            if(i%2==0){
                fi[t]++;
                fic++;
            }
            else{
                se[t]++;
                sec++;
            }
        }
        int a=0,b=0,at,bt;
        for(int i = 0; i < n; i++){
            if(fi[i] != 0){
                a++;
                at = i;
            }
            if(se[i] != 0){
                b++;
                bt = i;
            }
        }
        if(a == 1&& b ==1&&at!=bt){
            cout<<"0";
            return 0;
        }
        auto fi_max = max_element(fi.begin(),fi.end());
        auto se_max = max_element(se.begin(),se.end());
        if(fi_max-fi.begin()==se_max-se.begin()){
            if(*fi_max>*se_max){
                se.erase(se_max);
                se_max = max_element(se.begin(),se.end());
            }
            else if(*fi_max<*se_max){
                fi.erase(fi_max);
                fi_max = max_element(fi.begin(),fi.end());
            }
            else{
                auto bfm=*fi_max,bsm=*se_max;
                se.erase(se_max);
                se_max = max_element(se.begin(),se.end());
                fi.erase(fi_max);
                fi_max = max_element(fi.begin(),fi.end());
                if(*fi_max>*se_max)
                    *se_max =bsm;
                else
                    *fi_max =bfm;
            }
        }
        fic -= *fi_max;
        sec -= *se_max;
        cout<<fic+sec;
    }

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

int main()
{
    int N, M;
    cin >> N >> M;
    int cnt[M] = {0};

    for (int i = 0; i < N; i++)
    {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++)
        {
            int A;
            cin >> A;
            A--;
            cnt[A]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < M; i++)
    {
        if (cnt[i] == N)
        {
          ans++;
        }
    }
    cout << ans << endl;
}


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

int main() {

  int N;
  vector <char> S (100);
  string ans;

  cin >> N;

  for ( int i = 0; i < N; i++ ) cin >> S.at(i);
  

  ans = "Three";

  for ( int i = 0; i < N; i++ ) {
   if ( S.at(i) == 'Y' ) {
    ans = "Four";
    break;
   }
  
  }

  cout << ans << endl;

}



Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

use std::cmp::min;

fn main() {
    let (n, k) = get!(i64, i64);

    let m = n % k;
    let ans = min(m, (k - m).abs());
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int64_t N,A,B;
  cin>>N>>A>>B;
  if((A+B)%2==0){cout<<(B-A)/2<<endl;}
  else{if(N-A<B-1){cout<<(2*N-A-B+1)/2<<endl;}else{cout<<(A+B-1)/2<<endl;}}
}

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

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

int main() {
  int n;
  cin >> n;
  
  vector<string> s(n), S(n);
  string text;
  rep(i,n) {
    cin >> s[i];
    
    sort(s[i].begin(), s[i].end());
    
//    cout << s[i] << endl;
  }
  
  sort(s.begin(), s.end());
  
  
  long long ans = 0;
  string prevText = "";
  int cnt = 0;
  
  rep(i,n)
  {
    if(prevText == s[i]){
//      cout << "kita" << endl;
      ans += ++cnt;
//      cout << cnt << endl;
    }else{
      prevText = s[i];
      cnt = 0;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 8064
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<usize>();
    let k=read::<usize>();
    let s=read::<String>().chars().collect::<Vec<char>>();
    for i in 0..n{
        if i!=k-1{print!("{}",s[i])}else{for c in s[i].to_lowercase(){print!("{}",c)}}
    }
}


Measured memory_bytes: 4352
def main():
    l = input()
    n = len(l)
    mod = 10**9+7
    dp1 = [0 for i in range(n)]
    dp2 = [0 for i in range(n)]
    dp1[0] = 1
    dp2[0] = 2
    for i in range(1,n):
        if l[i] == '1':
            dp2[i] = (2 * dp2[i-1])%mod
            dp1[i] = (3 * dp1[i-1] + dp2[i-1])%mod
        else:
            dp2[i] = dp2[i-1]
            dp1[i] = (3 * dp1[i-1]) % mod
    print((dp1[-1]+dp2[-1])%mod)

if __name__ == "__main__":
    main()


Measured memory_bytes: 16788
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,k,sum,v,nxt[200005],i,dp[60][200005],j,a[200005],pq,pos;
const ll inf=1e18;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	for(i=0;i<n;i++)if(nxt[a[i]]==0)nxt[a[i]]=n+i;
	for(j=n-1;j>=0;j--)
	{
		dp[0][j]=nxt[a[j]]-j;
		nxt[a[j]]=j;	
	}	
	for(i=1;i<60;i++)
	{
		for(j=0;j<n;j++)
		{
			pq=dp[i-1][j]+1LL;
			pos=(j+pq)%n;
			pq+=dp[i-1][pos];
			if(pq>inf)dp[i][j]=inf;
			else dp[i][j]=pq;
		}
	}
	//printf("%lld\n",dp[1][0]);
	v=0;sum=n*k-1LL;
	if(sum==0)
	{
		printf("%lld\n",a[v]);
		return 0;
	}
	while(sum)
	{
		for(i=59;i>=0;i--)
		{
			if(dp[i][v]>sum)continue;
			sum-=dp[i][v];
			v=(v+dp[i][v])%n;
			if(sum==0)return 0;
			sum--;
			//printf("%lld %lld %lld\n",sum,v,dp[i][v]);
			v=(v+1LL)%n;
			if(sum==0)
			{
				printf("%lld ",a[v]);
				return 0;
			}
		}
		printf("%lld ",a[v]);
		sum--;
		v=(v+1)%n;
		if(sum==0)
		{
			printf("%lld ",a[v]);
			return 0;
		}
	}
	//printf("%lld ",a[v]);
	return 0;
} 

Measured memory_bytes: 98304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){


	int t = 1;
//	cin >> t;
	while(t--){
		int a, b, c, k;
		cin >> a >> b >> c;
		cin >> k;
		while(b <= a){
			b*=2;
			k--;
		}	
		while(c <= b){
			c*=2;
			k--;
		}
		if(k>=0){
			cout << "Yes\n";
		}
		else{
			cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3632