akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  rep1(i,3){
    if(s[i] == s[i-1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout  << "Good" << endl;
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    string S,T;
    cin >> S >> T;
    cout << T << S << endl;
}

Measured memory_bytes: 3528
m, k = gets.chomp.split.map(&:to_i)

case m
when 0
  if k == 0
    puts('0 0')
  else
    puts('-1')
  end
when 1
  if k == 0
    puts('0 0 1 1')
  else
    puts('-1')
  end
else
  if k >= 2**m
    puts('-1')
  else
    (0...2**m).each do |i|
      printf("#{i} ") if i != k
    end

    printf("#{k} ")

    (0...2**m).reverse_each do |i|
      printf("#{i} ") if i != k
    end

    printf("#{k}\n")
  end
end

Measured memory_bytes: 4476
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
using namespace std;
#define MAX 1000000

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;
    int a[101];
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }

    int left_cost = 0, right_cost = 0;
    for (int i = x; i >= 0; i--) {
        for (int j = 0; j < m; j++) {
            if (i == a[j]) left_cost++;
        }
    }
    for (int i = x; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i == a[j]) right_cost++;
        }
    }
    int ans = min(left_cost, right_cost);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (ll i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const ll INF = 1e10;
const ll MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vl vector<ll>


ll N, A[302020];
vi G[302020];

vl V;
int ans[302020];

void dfs(int idx = 0, int par = -1, int MAX = 0) {
    auto it = lower_bound(all(V), A[idx]);
    int len = it - V.begin();

    ll tmp = V[len];
    V[len] = A[idx];


    ans[idx] = max(MAX, len);
    chmax(MAX, len);
    /*
    cerr << idx + 1 << " " << len << endl;
    FOR (i, 0, 10) {
        cout << V[i] << " ";
    }
    cout << endl;
    */

    for (auto& nxt : G[idx]) {
        if (nxt == par)
            continue;
        dfs(nxt, idx, MAX);
    }
    V[len] = tmp;
    return;
}

void solve() {
    V.resize(N + 10);
    for (auto& a : V)
        a = INF;
    V[0] = 0;
    dfs();

    FOR (N)
        cout << ans[i] << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N;
    FOR (N)
        cin >> A[i];
    FOR (N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    solve();
    return 0;
}


Measured memory_bytes: 34840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int k; std::cin >> k;
    std::string s; std::cin >> s;
    if (s.size() <= k) std::cout << s << std::endl;
    else std::cout << s.substr(0, k) << "..." << std::endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S,P;
    cin>>S>>P;
    string T=S+S;
    int c=0;
    for(int i=0;i<S.size();i++){
        if(T.substr(i,P.size())==P) c++;
    }
    if(c==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int N, M;
vector<vector<int>> E;
vector<int> memo;

int dfs(int on){
    if(memo[on]!=-1) return memo[on];
    memo[on] = 0;
    for(int &to:E[on]){
        memo[on] = max(memo[on], dfs(to)+1);
    }
    return memo[on];
}


int main() {
    cin >> N >> M;
    E.resize(N);
    memo.resize(N, -1);
    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        a--;
        b--;
        E[a].push_back(b);
    }
    
    int res = 0;
    for(int i=0; i<N; i++){
        res = max(res, dfs(i));
    }
    
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 8192
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;
    List<int>[] es;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();
        es = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<int>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;
            es[a].Add(b);
            es[b].Add(a);
        }

        int ans = 0;

        for (int i = 0; i < N; i++)
        {
            List<int> over = new List<int>();
            List<int> under = new List<int>();
            foreach (var item in es[i])
            {
                over.Add(dfs(item, i, (K + 1) / 2));
                under.Add(dfs(item, i, (K) / 2));
            }

            int sum = under.Sum();
            for (int j = 0; j < over.Count; j++)
            {
                ans = Math.Max(ans, sum - under[j] + over[j] + 1);
            }
        }

        ans = N - ans;

        Console.WriteLine(ans);
    }
    
    int dfs(int a, int pre, int dep)
    {
        if (dep <= 0) return 0;
        int ans = 1;
        foreach (var next in es[a])
        {
            if (next == pre) continue;
            ans += dfs(next, a, dep - 1);
        }
        return ans;
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int N, M, Q;
vector<int> a(50), b(50), c(50), d(50);
vector<int> suuretu(10);
int tot;

void dfs(int now, int num){
  if(now==N){
    int sum = 0;
    for(int i = 0; i < Q; i++){
      if(suuretu.at(b.at(i))-suuretu.at(a.at(i))==c.at(i)){
        sum += d.at(i);
      }
    }
    if(tot<=sum){
      tot = sum;
    }
    return;
  }
  else{
    for(num; num<M+1; num++){
      suuretu.at(now)=num;
      dfs(now+1, num);
    }
  }
}
  
int main() {
  cin >> N >> M >> Q;
  tot = 0;
  
  for(int i = 0; i < Q; i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    a.at(i)--; b.at(i)--;
  }
  dfs(0, 1);
  cout << tot;
}



Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=input()
    for i in range(-(-len(S)//2)-1,0,-1):
        if S[:i]*2==S[:i*2]:
            print(i*2)
            exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n, x, y;
        cin >> n >> x >> y;

        map<int, int> mp;
        for(int i = 1; i < n; i++)
            mp[i] = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                int dist = min({abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - j) + 1 + abs(x - j)});
                mp[dist]++;
            }
        }

        for(auto x : mp)
            cout << x.second << '\n';
        
    }
    
    return 0;
}



Measured memory_bytes: 3688
def main():
    from sys import stdin
    input = stdin.readline
    from time import time
    from random import randint
    start = time()
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in [0]*D]
    ans = [randint(0, 25) for _ in [0]*D]

    def calc_score(ans):
        score = 0
        last = [-1]*26
        for d in range(D):
            ct = ans[d]
            score += s[d][ct]
            last[ct] = d
            for j in range(26):
                score -= c[j]*(d-last[j])
        return score

    score = calc_score(ans)

    while True:
        d = randint(0, D-1)
        new_ct = randint(0, 25)
        past_ct = ans[d]
        ans[d] = new_ct
        new_score = calc_score(ans)
        if new_score > score:
            score = new_score
        else:
            ans[d] = past_ct
        if time() > start+1.8:
            break

    for i in ans:
        print(i+1)


main()


Measured memory_bytes: 9732
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <math.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const int inf = 1000000000;
const double eps = 1e-7;

void solve() {
	int n, sum = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	
	int l = sum / n;
	int r = l + 1;
	
	ll ansl = 0;
	for (int i = 0; i < n; ++i)
		ansl += (a[i] - l) * (a[i] - l);
	ll ansr = 0;
	for (int i = 0; i < n; ++i)
		ansr += (a[i] - r) * (a[i] - r);
	
	cout << min(ansl, ansr) << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	for (int i = 0; i < t; ++i)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int h,i,j,k;
  int m;
  cin>>m;
  for(h=0;h<m;++h){
    int n;
    cin>>n;
    int a[100];
    for(i=0;i<n;++i)
      cin>>a[i];
    int b[100][100]={};
    for(i=1;i<n;++i)
      for(j=0;j<n;++j)
	for(k=0;k<i;++k)
	  b[j][(j+i)%n]=max(b[j][(j+i)%n],b[j][(j+k)%n]+b[(j+k+1)%n][(j+i)%n]+abs(a[j]-a[(j+k+1)%n]));
    int mx=0;
    for(i=0;i<n;++i)
      mx=max(mx,b[i][(i+n-1)%n]);
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int N, P;

vector<int> prime;
bool is_prime[1000000];
void init() {
    memset(is_prime, 1, sizeof(is_prime));
    for (int i = 2; i < 1000000; i++) 
        if (is_prime[i]) {
            prime.push_back(i);
            for (int j = i + i; j < 1000000; j += i) 
                is_prime[j] = false;
        }
}

bool input() {
    cin >> N >> P;
    if (N == -1 && P == -1) return false;
    return true;
}

int M(int n, int p) {
    vector<int>::iterator pos = upper_bound(prime.begin(), prime.end(), n);

    vector<int> cand;
    for (int i = 0; i < p; i++) 
        for (int j = i; j < p; j++) 
            cand.push_back(*(pos+i) + *(pos+j));
    sort(cand.begin(), cand.end());
    return cand[p-1];
}

int main() {
    init();
    while (input()) {
        cout << M(N, P) << endl;
    }
    return 0;
}

Measured memory_bytes: 2572
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define For(i, a, b) for (i = a; i <= b; i++)
using namespace std;
inline int read() {
	int res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	return bo ? ~res + 1 : res;
}
const int N = 5e6 + 5, PYZ = 998244353;
int n, K, fac[N], inv[N], ans;
int C(int n, int m) {return n < m ? 0 : 1ll * fac[n] * inv[m] % PYZ * inv[n - m] % PYZ;}
int main() {
	int i; n = read(); K = read(); fac[0] = inv[0] = inv[1] = 1; For (i, 1, 5000000)
		fac[i] = 1ll * fac[i - 1] * i % PYZ;
	For (i, 2, 5000000) inv[i] = 1ll * (PYZ - PYZ / i) * inv[PYZ % i] % PYZ;
	For (i, 2, 5000000) inv[i] = 1ll * inv[i] * inv[i - 1] % PYZ; For (i, n, K) {
		int res = (C(K, i) - C(K, (i << 1) - n + 1) + PYZ) % PYZ;
		ans = (ans + res) % PYZ;
	}
	cout << ans << endl; return 0;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,m;cin>> n>>m;
	vector<P> a(n);
	vector<P> d(m);
	ll p,q;
	for(int i = 0; i < n; i++) {
		cin >> p >> q;
		a[i] = mp(p,q);
	}
	for(int i = 0; i < m; i++) {
		cin>> p >> q;
		d[i] = mp(p,q);
	}
	vector<P> ans(n,mp(INF,0LL));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			ll x = abs(a[i].fs - d[j].fs) + abs(a[i].sc - d[j].sc);
			if (x < ans[i].fs){
				ans[i].fs = x;
				ans[i].sc = j+1; 
			}
		}
	}
	for(int i = 0; i < n; i++) {
		cout << ans[i].sc << endl;
	}
	return 0;
}

Measured memory_bytes: 764
def main():
    N = int(input())
    A = list(map(int, input().split()))
    R = [None]*N
    twox = 0
    for i in range(N):
        twox += A[i] * (-1)**i
    R[0] = int(twox)
    for i in range(1, N):
        R[i] = int((A[i-1] - R[i-1]/2)*2)
    print(' '.join(map(str, R)))
main()

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

int main(){
    string s; cin>>s;
    
    int count = 0;
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<s.size(); j++){
            if(s[i]==s[j]) count++;
        }
    }
    
    if(count==8) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a==b && c==d || a==d && b==c){
		printf("yes\n");
	}
	else{
		printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2112
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    coin_map = [[0 for i in range(W)] for j in range(H)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            coin_map[i][j] = int(input_raw[j])

    is_done = [[False for i in range(W)] for j in range(H)]
    count= 0
    next_point = (0, 0)
    ope_list = []
    move_list = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    is_next_exist = True
    while is_next_exist == True:
        is_next_exist = False
        y = next_point[0]
        x = next_point[1]
        is_done[y][x] = True
        for move in move_list:
            new_y = y + move[0]
            new_x = x + move[1]
            if y>= 0 and new_y < H and new_x >= 0 and new_x < W and is_done[new_y][new_x] == False:
                next_point = (new_y, new_x)
                is_next_exist = True
                break
        if is_next_exist == False:
            break
        if coin_map[y][x] > 0 and coin_map[y][x] % 2 == 1:
            coin_map[y][x] -= 1
            coin_map[new_y][new_x] += 1
            ope_list.append((y + 1, x + 1, new_y + 1, new_x + 1))
            count += 1
    print len(ope_list)
    for ope in ope_list:
        print ope[0], ope[1], ope[2], ope[3]

if __name__ == '__main__':
    main()

Measured memory_bytes: 26736
N = int(input())
a_list = list(map(int, input().split()))
dic_a = {}
for i in range(N-1):
    if a_list[i]-1 in dic_a:
        dic_a[a_list[i]-1] += 1
    else:
        dic_a[a_list[i]-1] = 1
ans = [0 for i in range(N)]
for k,v in dic_a.items():
    ans[k] = v
for i in ans:
    print(i)

Measured memory_bytes: 38800
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> c[i];
    }

    sort(begin(a), end(a));
    sort(begin(b), end(b));
    sort(begin(c), end(c));

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (lower_bound(begin(a), end(a), b[i]) - begin(a)) * (end(c) - upper_bound(begin(c), end(c), b[i]));
    }

    cout << ans << endl;
}

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

void dict_sort(vector<string> &S, int N, int L){
    string temp;
    for(int i = 0; i < N-1; i++){
        for(int j = 0; j < N - 1 - i; j++){
            if(S.at(j) > S.at(j+1)){
                temp = S.at(j);
                S.at(j) = S.at(j+1);
                S.at(j+1) = temp;
            }
        }
    }
    return;
}

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

    vector<string> S(N);

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

    dict_sort(S, N, L);

    for(int i = 0; i < N; i++){
        cout << S.at(i);
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int n;
int a[20][20];
int b[20];
int check(int mask)
{
    int cnt = 0;
    Forn(i, n)
    {
        if(mask&1)
        {
            b[i] = 1;
            cnt++;
        }
        else b[i] = 2;
        mask>>=1;
    }
    Forn(i, n) Forn(j, n)
    {
        if(b[i] == 1 && a[i][j] == 1 && b[j] == 2) return -1;
        if(b[i] == 1 && a[i][j] == 2 && b[j] == 1) return -1;
    }
    return cnt;
}

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> n;
    Forn(i, n)
    {
        int k;
        cin >> k;
        forn(j, k)
        {
            int x, y;
            cin >> x >> y;
            if(y==1) a[i][x] = 1;
            else a[i][x] = 2;
        }
    }
    /*Forn(i, n)
    {
        Forn(j, n) cout << a[i][j];
        cout << endl;
    }*/
    int ans = 0;
    forn(i, 1<<n) ans = max(ans, check(i));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pll pair<double,ll>

string s;
ll xs, ys, xt, yt;
int N;
priority_queue<pll, vector<pll>, std::greater<pll>> q;
vector<pll> g[2000];
ll x[2000];
ll y[2000];
ll r[2000];
bool visit[2000];

int main()
{
    string s;
    cin >> s;
    if(s.length() % 2 == 0)
    {
        if(s.front() == s.back())
        {
            cout << "First" << endl;
            return 0;
        }
        cout << "Second" << endl;
        return 0;
    }
    if(s.front() == s.back())
    {
        cout << "Second" << endl;
        return 0;
    }
    cout << "First" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	long long int  a, b = 0, c = 0, count = 0, ans = 0, n = 0;
	string s;
	vector<int> x;
	cin >> s;
	if (s == "a")cout << "b" << endl;
	if (s == "b")cout << "c" << endl;
	if (s == "c")cout << "d" << endl;
	if (s == "d")cout << "e" << endl;
	if (s == "e")cout << "f" << endl;
	if (s == "f")cout << "g" << endl;
	if (s == "g")cout << "h" << endl;
	if (s == "h")cout << "i" << endl;
	if (s == "i")cout << "j" << endl;
	if (s == "j")cout << "k" << endl;
	if (s == "k")cout << "l" << endl;
	if (s == "l")cout << "m" << endl;
	if (s == "m")cout << "n" << endl;
	if (s == "n")cout << "o" << endl;
	if (s == "o")cout << "p" << endl;
	if (s == "p")cout << "q" << endl;
	if (s == "q")cout << "r" << endl;
	if (s == "r")cout << "s" << endl;
	if (s == "s")cout << "t" << endl;
	if (s == "t")cout << "u" << endl;
	if (s == "u")cout << "v" << endl;
	if (s == "v")cout << "w" << endl;
	if (s == "w")cout << "x" << endl;
	if (s == "x")cout << "y" << endl;
	if (s == "y")cout << "z" << endl;

	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MOD 1000000007
int main() {
	ll h, w;
	cin >> h >> w;
	vector<vector<ll>> grid(h, vector<ll>(w, -1)); 
	for (ll i = 0; i < h; ++i) {
		for (ll j = 0; j < w; ++j) {
			char x;
			cin >> x;
			grid[i][j] = (x == '.' ? 1 : 0);
		}
	}
	vector<vector<ll>> dp(h, vector<ll>(w, 0)); 
	dp[0][0] = grid[0][0];
	for (ll i = 1; i < w; ++i) {
		dp[0][i] = grid[0][i] ? dp[0][i-1] : 0;
	}
	for (ll j = 1; j < h; ++j) {
		dp[j][0] = grid[j][0] ? dp[j-1][0] : 0;
	}
	for (ll i = 1; i < h; ++i) {
		for (ll j = 1; j < w; ++j) {
			if (grid[i][j]) dp[i][j] = dp[i-1][j] + dp[i][j-1];
			else dp[i][j] = 0;
			dp[i][j] = dp[i][j]%MOD;
		}
	}
	cout << dp[h-1][w-1] << " ";
	return 0;
} 


Measured memory_bytes: 16000
package main

import (
	"math/rand"
	"time"
	"os"
	"bufio"
	"fmt"
	"strconv"
	"strings"
)

var(
	inf = 10000000071000000
	sc = bufio.NewScanner(os.Stdin)
	stdin = bufio.NewReader(os.Stdin)
	mod = 1000000007
	mod9 = 1000000009
)

func init()  {
	rand.Seed(time.Now().UnixNano())
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)
}


func main() {
	n := goint();m := goint()
	uni := &UnionFind{}
	uni.uniInit(n+m)
	for i:=0;i<n;i++{
		k := goint()
		for j:=0;j<k;j++{
			l := goint()
			uni.connect(i,l+n-1)
		}
	}
	num := uni.size(0)
	c := 0
	for i:=n;i<n+m;i++{
		if uni.root(0) != uni.root(i){
			c ++
		}
	}
	if num - (m - c) == n{
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

//Union-Find
type UnionFind struct {
	par []int
}

func (u *UnionFind) uniInit(n int)  {
	u.par = make([]int,n)
	for i:=0;i<n;i++{
		u.par[i] = -1
	}
}

//aがどのグループに属しているか
func (u *UnionFind) root (a int) int {
	if u.par[a] < 0{
		return a
	}
	u.par[a] = u.root(u.par[a])
	return u.par[a]
}

//自分のグループの頂点数
func (u *UnionFind) size (a int) int {
	return -u.par[u.root(a)]
}

//つなげる
func (u *UnionFind) connect(a,b int) bool {
	a = u.root(a)
	b = u.root(b)
	if a == b {
		return false
	}
	if u.size(a) < u.size(b) {a,b = b,a}
	u.par[a] += u.par[b]
	u.par[b] = a
	return true
}

//||||||||||||||||||||||||||入力|||||||||||||||||||||||||||||||||||||||\
//数字一文字入力
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

//文字列を一行入力
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

//空白区切りの文字列の入力
func spaceLine() []string {
	sc.Scan()
	return strings.Split(sc.Text()," ")
}

//数字を一行入力
func intLine() []int {
	str := spaceLine()
	buf := make([]int,len(str))
	for i,s:=range str{
		buf[i],_ = strconv.Atoi(s)
	}
	return buf
}

//次のスペースか改行まで読み込む
func gostring() string {
	byte_ls := make([]byte,0)
	for  {
		b, _ := stdin.ReadByte()
		if b == 32 || b == 10 || b == 0{
			return string(byte_ls)
		} else if b == 13 {
			continue
		} else {
			byte_ls = append(byte_ls,b)
		}
	}
}

//上の関数のintバージョン
func goint() int {
	n,_ := strconv.Atoi(gostring())
	return n
}

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

func sum(a ...int) int {
	ans := 0
	for i:=0;i<len(a);i++{
		ans += a[i]
	}
	return ans
}

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

func abs(n int) int {
	if n >= 0{
		return n
	} else {
		return -n
	}
}

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

Measured memory_bytes: 4736
from collections import deque
readline = open(0).readline
writelines = open(1, 'w').writelines
N, Q = map(int, readline().split())
ans = []
A = [deque() for i in range(N)]
def push(t, x):
    A[t].append(x)
def top(t):
    A[t] and ans.append("%d\n" % A[t][0])
def pop(t):
    A[t] and A[t].popleft()

C = [push, top, pop].__getitem__
for i in range(Q):
    t, *a=map(int, readline().split())
    C(t)(*a)
writelines(ans)



Measured memory_bytes: 14468
a,b = gets.chomp.split(' ').map(&:to_i)
# |a-n| == |b-n| =>  a-n == b-n  :  a-b ==   0
#                   -a+n == b-n  : -a-b == -2n
#                    a-n == -b+n :  a+b ==  2n
#                   -a+n == -b+n : -a+b ==   0
n = (a+b)/2.to_f
if n.ceil == n.floor
  puts n.to_i
else
  puts "IMPOSSIBLE"
end

Measured memory_bytes: 14260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    int n = s.length()-2;
    cout << s[0] << n << s[n+1] << endl;
    return 0;   
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;
typedef pair<int, int> p;

int main()
{
    int h, w, d;
    p a[90001];
    cin >> h >> w >> d;
    rep(i, h) {
        rep(j, w) {
            int num;
            cin >> num;
            a[num].first = i;
            a[num].second = j;
        }
    }

    int dist[90001];
    for (int i = 1; i <= d; i++) {
        dist[i] = 0;
    }
    for (int i = d + 1; i <= h * w; i++) {
        dist[i] = dist[i - d] + abs(a[i].first - a[i - d].first)
            + abs(a[i].second - a[i - d].second);
    }
    int q;
    cin >> q;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << dist[r] - dist[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
s = gets.chomp.chars
aaa = s.map.with_index(1) do |ss,i|
  if i.odd?
    ss == 'R' ||ss == 'U' ||ss == 'D'
  else
    ss == 'L' ||ss == 'U' ||ss == 'D'
  end
end.all?{|a|a == true}
puts aaa ? 'Yes' : 'No'


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static enum CardDesign {
		S(0), H(1), C(2), D(3);
		private int id;
		public int getId() {
			return this.id;
		}
		private CardDesign (int id) {
			this.id = id;
		}
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		//
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		boolean[][] checkInput = new boolean[4][13];
		int inputCards = Integer.parseInt(input.readLine());
		int inputNumberOfCards;

		for (int i = 0; i < inputCards; i++) {
			String[] inputCardsArray = (input.readLine()).split("\\s");
			inputNumberOfCards = Integer.parseInt(inputCardsArray[1]);
			switch(CardDesign.valueOf(inputCardsArray[0])) {
			case S:
				checkInput[0][(inputNumberOfCards -1)] = true;
				break;
			case H:
				checkInput[1][(inputNumberOfCards -1)] = true;
				break;
			case C:
				checkInput[2][(inputNumberOfCards -1)] = true;
				break;
			case D:
				checkInput[3][(inputNumberOfCards -1)] = true;
				break;
			}
		}

		for (int i = 0; i < CardDesign.values().length; i++) {
			for (int j = 0; j < checkInput[1].length; j++) {
				if (!checkInput[i][j]) {
					System.out.println(CardDesign.values()[i] + " " + (j +1));
				}
			}
		}
	}

}



Measured memory_bytes: 24700
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;
const int MAX_N = 200010;

int a[MAX_N];
int f[MAX_N];
ll n, k;

bool C(ll x){
    ll sm = 0;
    rep(i, n){
        sm += max((ll)0, a[i] - x / f[i]);
    }
    // cout << sm << endl;
    return sm <= k;
}

int main(){
    
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(a, a + n);
    sort(f, f + n, greater<int>());
    ll l = -1, r = 1001001001001001001;
    while(l + 1 < r){
        ll mid = (l + r) / 2;
        if(C(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 5096
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
#define Maxn 100005
int n,id[Maxn],par[Maxn],sz[Maxn];
long long a[Maxn];
map <long long,int> mp;
int main()	
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
		mp[a[i]]=i;
		id[i]=i;
		sz[i]=1;
	}
	sort(id+1,id+n+1,[&](const int &x,const int &y)->bool{return a[x]>a[y];});
	for (int i=1;i<n;++i)
	{
		int x=id[i];
		par[x]=mp[a[x]-n+2*sz[x]];
		if (!par[x]) return (int)puts("-1")*0;
		sz[par[x]]+=sz[x];
	}
	for (int i=1;i<n;++i) a[id[n]]-=sz[id[i]];
	if (a[id[n]]) return (int)puts("-1")*0;
	for (int i=1;i<n;++i) printf("%d %d\n",id[i],par[id[i]]);
	return 0;
}


Measured memory_bytes: 10112
//
//  main.cpp
//  ABC156F
//
#define rep(i,n) for(int i=0;i<(n);++i)
#include <iostream>
#include<vector>
using namespace std;
using ll= long long;

int main(int argc, const char * argv[]) {
    int k,q;
    cin>>k>>q;
    vector<int> d(k);
    rep(i,k) cin>>d.at(i);
    rep(qi,q){
        int n,x,m;
        cin>>n>>x>>m;
        ll last=x;
        ll eq=0;
        rep(i,k){
            ll num=(n-1-i+k-1)/k;
            last += (d.at(i)%m)*num;
            if(d.at(i)%m==0) eq +=num;
        }
        ll ans=n-1-last/m+x/m-eq;
        cout << ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vec = vector<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)

int _stack[1000], sp;

void push(int x)
{
	_stack[sp++] = x;
}

int pop(void)
{
	return _stack[--sp];
}

int main()
{
	char buf[100];
	int x, y;

	while (scanf("%s", buf) != EOF) {
		switch (buf[0]) {
		case '+':
			push(pop() + pop());
			break;
		case '-':
			y = pop();
			x = pop();
			push(x - y);
			break;
		case '*':
			push(pop() * pop());
			break;
		default:
			push(atoi(buf));
			break;
		}
	}
	cout << pop() << endl;
}



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

int main() {
    int N;
    cin >> N;
    int minA = 1000000000;
    int maxA = 0;
    for (int i = 0; i < N; i++){
        int A;
        cin >> A;
        minA = min(A, minA);
        maxA = max(A, maxA);
    }
    cout << maxA - minA << endl;


}

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

public class Main {

	public static void main(String[] args)throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int i=0,x;

		do{
			s= buf.readLine();
			x= Integer.parseInt(s);
			i=i+1;
		if(x!=0){
			System.out.println("Case "+i+": "+x);
		}
		else{}
		}while(x!=0);
	}
}

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

// 約数列挙
vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    long long N, M;
    cin >> N;
    vector<long long> div = calc_divisor(N);
    
    // M の約数 d であって、d * N <= M となる最大の d を求める
    long long res = 1;
    res=1000000000005;
	//printf("res=%lld\n",res);
	for (auto d : div) {
        //printf("d=%lld\n",d);
		//printf("d+N/d-2=%lld\n",d+N/d-2);
		res = min(res, d+N/d-2);
		//printf("res=%lld\n",res);
    }

    cout << res << endl;
}

Measured memory_bytes: 384
N,M = map(int,input().split())
k=dict.fromkeys(range(1,31),0)
count=0
for i in range(N):
    x=list( map( int,input().split() ) )[1:]

    for j in x:

        k[j]+=1


for value,key in k.items():
    if key==N :
        count += 1

        
    
        
print(count)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
		String s = sc.next();
		List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		int zero = 0;
		int one = 0;
		for(int i=0;list.size()>i;i++) {
			if(list.get(i).equals("0"))
				zero++;
			else
				one++;
		}
		if(zero>=one)
			System.out.println(one*2);
		else
			System.out.println(zero*2);
	}
}

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

typedef long long int lli;
const int SIZE = 100001;
vector<int> adj[SIZE];
vector<int> path;
int mid, p;
int N;

void dfs(int here, int parent)
{
	path.push_back(here);
	if (here == N) {
		p = path[(path.size()-1) / 2];
		mid = path[(path.size() + 1) / 2];
	}
	for (int i = 0; i < adj[here].size(); i++) {
		int next = adj[here][i];
		if (next == parent)
			continue;
		dfs(next, here);
	}
	path.pop_back();
}

int dfs2(int here, int parent)
{
	int ret = 1;
	for (int i = 0; i < adj[here].size(); i++) {
		int next = adj[here][i];
		if (next == parent)
			continue;
		ret += dfs2(next, here);
	}
	return ret;
}

int main()
{
	int a, b;
	scanf("%d", &N);
	for (int i = 0; i < N - 1; i++) {
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1, 0);
	if (2 * dfs2(mid, p) >= N)
		printf("Snuke\n");
	else
		printf("Fennec\n");
}

Measured memory_bytes: 10872
#include <iostream>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n, t = 0;
int color[MAX+1];
int m[MAX+1][MAX+1];
int d[MAX+1], f[MAX+1];

void visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++t;
    for(v = 1; v <= n; v++){
        if(m[u][v] == 0) continue;
        if(color[v] == WHITE) visit(v);
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs(){
    int u, i;
    for(u = 1; u <= n; u++) color[u] = WHITE;
    for(u = 1; u <= n; u++){
        if(color[u] == WHITE) visit(u);
    }
}

int main(){
    int k, u, v, i, j;
    
    cin >> n;

    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++) m[i][j] = 0;
    }

    for(i = 1; i <= n; i++){
        cin >> u >> k;
        for(j = 1; j <= k; j++){
            cin >> v;
            m[u][v] = 1;
        }
    }

    dfs();
    
    for(i = 1; i <= n; i++) cout << i << " " << d[i] << " " << f[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> p(n+1);
    rep(i,n){
        cin >> a[i];
        p[a[i]]++;
    }
    ll sm = 0;
    rep(i,n+1){
        sm += p[i]*(p[i]-1)/2;
    }
    rep(i,n){
        cout << sm - p[a[i]]*(p[a[i]]-1)/2 + (p[a[i]]-1)*(p[a[i]]-2)/2 << "\n";
    }
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define INF 1e4

int main() {
    st s, t;
    cin >> s >> t;
    int sz_s = s.size();
    int sz_t = t.size();
    int ans = sz_t;
    rep(i, sz_s - sz_t + 1){
        int cnt = 0;
        rep(j, sz_t){
            if(t.at(j) != s.at(i + j)) cnt++;
        }
        chmin(ans, cnt);
    }
    /*rep(i, sz_t){
        rep(j, sz_s){
            if(s.at(j) == t.at(i)){
                int cnt = 0;
                rep(k, sz_t){
                    if(j - i + k < 0 || j - i + k >= sz_s) break;
                    if(t.at(k) != s.at(j - i + k)){
                        cnt++;
                    }      
                }
                chmin(ans, cnt);
            }
        }     
    }*/
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    bool flag = false;
    for(int i = 0; i < s.size()-2; i++)
    {
        if(s[i] != s[i+2])
        {
            flag = true;
            break;
        }
    }
    if(!flag)
    {
        cout << "Second" << endl;
    }
    else
    {
        if(s[0] == s[s.size()-1] ^ s.size() % 2 == 1)
        {
            cout << "First" << endl;
        }
        else cout << "Second" << endl;
    }
}


Measured memory_bytes: 512
class BIT:
  def __init__(s, n):
    s._n = n
    s.data = [0] * n
  def add(s, p, x):
    p += 1
    while p <= s._n:
      s.data[p - 1] += x
      p += p & -p
  def sum(s, l, r):
    return s.zum(r) - s.zum(l)
  def zum(s, r):
    ans = 0
    while r > 0:
      ans += s.data[r - 1]
      r -= r & -r
    return ans

N, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
Query = [list(map(int, input().split())) for _ in range(Q)]
  
bit = BIT(N)
for i in range(N):
  bit.add(i, a[i])
 
for q in Query:
  if q[0] == 0:
    _, p, x = q
    bit.add(p, x)
  else:
    _, l, r = q
    print(bit.sum(l, r))

Measured memory_bytes: 175000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
const ll INF = 1e16;

void solver(string &s, vector<char> &ans){

    for(auto iter = s.begin(); iter != s.end(); ++iter){
        if(*iter != 'B') ans.push_back(*iter);
        else if(ans.size() != (size_t)0) ans.pop_back();
    }

    return;
}

int main(){

    string s;
    cin >> s;

    vector<char> ans;
    solver(s, ans);

    for(auto iter = ans.begin(); iter != ans.end(); ++iter) cout << *iter;

    return 0;
}

Measured memory_bytes: 3560
import functools
import operator
N = input()
flag = 1
count = 0
ans_list = [0] * len(N)
res = 0
N = N + "R"
for i in range(len(N)):
    if N[i] == "R":
        if flag == 1:
            count +=1
        else:
            flag = 1
            ans_list[res-1] += count//2
            ans_list[res] += count//2
            if count%2 ==1:
                ans_list[res] += 1
            count = 1
    else:
        if flag == 1:
            flag = 0
            ans_list[i-1] += count//2
            ans_list[i] += count//2
            if count%2 ==1:
                ans_list[i-1] += 1
            count = 1
            res = i
        else:
            count += 1

print(*ans_list)


Measured memory_bytes: 48060
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2-x1, dy = y2-y1;
    cout << x2-dy << " " << y2+dx << " " << x2-dy-dx << " " << y2+dx-dy << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,y;
    cin >> n >> y;
    for(int i = 0; i <= n; i ++) {
      for(int j = 0; j <= n; j ++) {
      	if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y && n - i - j>= 0) {
      	  cout << i << ' ' << j << ' ' << n - i - j << endl;
      	  return 0;
		  }
	  }
	}
    cout<<"-1 -1 -1"<<endl;
    return 0;
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

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

	int n; read(n);
	vector<int> a(n), b(n);
	rep(i, 0, n) read(a[i]);
	rep(i, 0, n) read(b[i]);

	{
		bool g = true;
		rep(i, 0, n) if (a[i] < b[i]) g = false;
		if (g) die(0);
	}

	{
		ll sa = 0, sb = 0;
		rep(i, 0, n) sa += a[i], sb += b[i];
		if (sa < sb)
			die(-1);
	}

	ll s = 0; int c = 0;
	priority_queue<ll> pq;
	rep(i, 0, n) 
		if (a[i] < b[i])
			s += b[i] - a[i], c++;
		else if (a[i] > b[i])
			pq.push(a[i] - b[i]);
	while (s > 0)
		s -= pq.top(), pq.pop(), c++;
	write(c);
}


Measured memory_bytes: 4632
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll A1 = t1 * a1;
    ll A12 = A1 + t2 * a2;
    ll B1 = t1 * b1;
    ll B12 = B1 + t2 * b2;

    //無限に続く
    if(A12 == B12){
        cout << "infinity" << endl;
        return 0;
    }

    if(A12 < B12){
        swap(A12, B12);
        swap(A1, B1);
    }

    ll ans = 0;
    if(A1 > B1){
        //永遠に交わらない
        cout << "0" << endl;
    }else if(A1 < B1){
        //何回BがAを追い越してAがBを追い越しての周期が繰り返せるか
        //1周期で2回の交点が生まれる
        ans = (B1-A1) / (A12-B12)  * 2 + 1;

        if((B1-A1) % (A12-B12) == 0){
             //ちょうど0になって終わるとその周期は1回しか交点が生まれないので
            ans--;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256