akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
vi f(const vi& v) {
  int n = v.size();
  vi cnt(n + 1, 0);
  REP(i, n) {
    cnt[max(0ll, i - v[i])]++;
    cnt[min(n - 1ll, i + v[i]) + 1]--;
  }
  REP(i, n)cnt[i + 1] += cnt[i];
  vi ret(n);
  REP(i, n)ret[i] = cnt[i];
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vi v(n);
  REP(i, n)cin >> v[i];
  REP(i, k) {
    auto c = f(v);
    if (c == v)break;
    v = c;
  }
  REP(i, n)cout << v[i] << " ";
  cout << endl;
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
	if(ch=='A') {return 1;}
	else if(ch=='C') {return 2;}
	else if(ch=='G') {return 3;}
	else if(ch=='T') {return 4;}
}
long long getKey(char str[]){
	long long sum=0, p= 1, i;
	for(i=0;i<strlen(str);i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
	long long key, i, h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0){return 1;}
		else if(strlen(H[h])==0){return 0;}
	}
	return 0;
}

int insert(char str[])
{
	long long key;
	long long i, h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0){return 1;}
		else if(strlen(H[h])==0){strcpy(H[h], str);return 0;}
	}

	return 0;
}
	
int main(void)
{
	int i, n, h;
	char str[L], com[9];
	for(i=0; i<M; i++){
		H[i][0]='\0';
	}
	
	scanf("%d", &n);
	
	for ( i = 0; i < n; i++ ){
		scanf("%s %s", com, str);
		
		if ( com[0] == 'i' ){
	    	insert(str);
		}
		else
		{
	    	if (find(str)){
				printf("yes\n");
	    	} 
			else
			{
				printf("no\n");
	    	}
		}
    }

    return 0;
}


Measured memory_bytes: 16100
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll c[1234], a[N], b[N], used[N];
ll dp[1234][3][5000];
int n, m;
ll f(int id, int t, int mask)
{
	if(id == m + 1)
	{
		if(mask == (1 << n) - 1)
		{
			return 0;
		}
		return 1e12;
	}
	ll ans = 1e12;
	if(dp[id][t][mask] != -1)
		return dp[id][t][mask];
	ans = min(ans, f(id + 1, 0, mask));
	ans = min(ans, f(id + 1, 1, mask | c[id])+a[id]);
	return dp[id][t][mask] = ans;
}
int main()
{
ios::sync_with_stdio(false);
	cin.tie(0);
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
	{
		cin >> a[i] >> b[i];
		for(int j = 1; j <= b[i]; j ++)
		{
			int x;
			cin >> x;
			x--;
			c[i] |= (1 << x);
		}
	}
	ll res =  min(f(1, 1, 0), f(1, 0, 0));
	if(res >= 1e11)
		res = -1;
	cout << res;





	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 149760
// https://atcoder.jp/contests/abc112/tasks/abc112_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

// 約数の列挙
vector<int64_t> divisor(int64_t n) {
    vector<int64_t> ret;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<int64_t> v = divisor(m);
    ll ans = 0, sum = 0;
    sort(ALLR(v));
    for (auto x : v) {
        sum = n * x;
        if (sum <= m) {
            cout << x << endl;
            return 0;
        }
    }
    cout << "1\n";

    return 0;
}


Measured memory_bytes: 256
/* ex5_3.c Grid Compression
    dada__              */
#include<stdio.h>
//配列の初期化を行わないとWAになった(なぜかわからない)
int main(void){
    int row, col, i, j;
    scanf("%d %d", &row, &col); //行と列の数の入力
    int judge_row[row], judge_col[col];
    char grid[row][col];

    for(i=0;i<row;i++){
        judge_row[i]=0;
    }
    for(j=0;j<col;j++){
        judge_col[j]=0;
    }

    //各マス目の記号の入力
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf(" %c", &grid[i][j]);
            if(grid[i][j]=='#'){
                judge_row[i]=1;
                judge_col[j]=1;
            }
        }
    }

    //各判定に基づいた出力
    for(i=0;i<row;i++){
        int count = 0;
        for(j=0;j<col;j++){
            if(judge_row[i]==1 && judge_col[j]==1){
                    printf("%c", grid[i][j]);
                    count++;
            }
        }
        if(count != 0){
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    string s, t;
    cin >> s >> t;

    int len = s.length() + t.length();
    string ans;
    for (int i = 0; i < len; i++) {
        ans.push_back(i % 2 == 0 ? s[i / 2] : t[i / 2]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
def resolve():
    N = input()
    n = len(N)
    ans = 0
    if n % 2 == 0:
        for i in range(1, n):
            if i % 2 == 1:
                ans += 9*(10**(i-1))
        print(ans)
    else:
        for i in range(1, n-1):
            if i % 2 == 1:
                ans += 9*(10**(i-1))
        print(ans + int(N) + 1 - 10**(n-1))
resolve()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------
void solve(){
    long long n, k, r, s, p;
    string t;
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    long long num;
    char memo;
    num = n / k;
    long long ans;
    ans = 0;
    bool ck = false;
    for(long long i = 0; i < k; i++){//kで割ったあまりによって場合分け
    memo = 'M';
    for(long long j = 0; j <= num; j++){
        if(k * j + i >= n){
            continue;
        }
        else{
            if(t.at(k * j + i) != memo || !(ck)){
                memo = t.at(k * j + i);
                if(t.at(k * j + i) == 'r'){
                    ans += p;
                }
                else if(t.at(k * j + i) == 's'){
                    ans += r;
                }
                else if(t.at(k * j + i) == 'p'){
                    ans += s;
                }
                ck = true;
            }
            else{
                ck = false;
            }
        }

    }
    }
    cout << ans << endl;
}

int main(){
    dbg = true;
    solve();
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; ll count = 0; bool flag = true;
  vl num(n);
  
  rep(i,n){
    ll x; cin >> x; num.at(i) = x;
  }
  
  while(flag){
    rep(i,n){
      if(num.at(i) % 2 == 0){
        count++;
        num.at(i) /= 2;
      }
      else flag = false;
    }
  }
        
  cout << count / n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll e[105];
int main()
{
    ll n,cnt=0;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>e[i];
        if(i%2==1&&e[i]%2==1)
            cnt++;
    }
    cout<<cnt;
    return 0;

}


Measured memory_bytes: 3592
//smtb2019_f.cpp
//Sun Dec  1 22:04:19 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll t1,t2,a1,a2,b1,b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	ll firstdif = b1*t1-a1*t1;
	ll seconddif = b2*t2-a2*t2;
	ll ans = 0;
	if (firstdif>0 && seconddif>0){
		cout << 0 << endl;
		return 0;
	}else if (firstdif<0 && seconddif<0){
		cout << 0 << endl;
		return 0;
	}else if (abs(firstdif) == abs(seconddif)){
		cout << "infinity" << endl;
		return 0;
	}else if (abs(firstdif)>abs(seconddif)){
		cout << 0 << endl;
		return 0;
	}else {
		if (firstdif < 0){
			firstdif = firstdif * (-1);
			seconddif = seconddif * (-1);
		}
		if (abs(firstdif)%abs(firstdif+seconddif)==0){
			cout << abs(firstdif)/abs(firstdif+seconddif)*2 << endl;
		}else {
			cout << abs(firstdif)/abs(firstdif+seconddif)*2+1 << endl;
		}
	}
//	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
def dt(t,t1,t2):
	dt = 60*(10*(int(t2[0]) - int(t1[0])) + (int(t2[1]) - int(t1[1]))) + 10*(int(t2[3]) - int(t1[3])) + (int(t2[4]) - int(t1[4]))
	return dt if dt >= t else False
	
n,t = map(int,raw_input().split())
datas = [raw_input().split() for i in range(n)]
ans = []
for i in range(1,n):
	a = dt(t,datas[i-1][2],datas[i][0])
	if a:
		ans.append([datas[i][1], a])
print len(ans)
for i in range(len(ans)):
	print " ".join(map(str,ans[i]))

Measured memory_bytes: 4260
# frozen_string_literal: true

s = gets.chomp
n = s.size
ss = s[0..((n - 1)/2 - 1)]

sss = s[((n + 3)/2 - 1)..-1]

if s == s.reverse && ss == ss.reverse && sss == sss.reverse
  puts 'Yes'
else
  puts 'No'
end


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

vec_p p;

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

    ll N;
    string S;
    cin >> N;

    vector<ll> a(N);

    REP(i, N)
        cin >> a.at(i);

    sort(a.begin(), a.end());

    ll tmp = 1;
        REP(i, N)
        {
            if(i==N-1){
                p.push_back(make_pair(a.at(i), tmp));
                tmp = 1;
            }
            else{
                if (a.at(i) == a.at(i + 1))
                {
                    tmp++;
                }
                else
                {
                    p.push_back(make_pair(a.at(i), tmp));
                    tmp = 1;
                }
            }
        }

        ll ans = 0;
        REP(i, p.size())
        {
            ll tmp1 = p.at(i).first;
            ll tmp2 = p.at(i).second;

            if(tmp1>tmp2){
                ans += tmp2;
            }
            else if(tmp1<tmp2){
                ans += (tmp2 - tmp1);
            }
        }
        cout << ans << endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/03  Problem: ABC 048 D / Link: http://abc048.contest.atcoder.jp/tasks/abc048_d  ----- */

const int sz = 1000;
const int WIN = 1, LOSE = 2;
map<string, int>gamedp;
int f(string s) {
	if (SZ(s) <= 2) {
		return LOSE;
	}
	if (gamedp[s])return gamedp[s];

	bool gotolose = 0;
	FOR(i, 1, SZ(s) - 1) {
		string t = "";
		FOR(k, 0, SZ(s)) {
			if (k == i)continue;
			t += string(1, s[k]);
		}
		bool ok = 1;
		FOR(k, 0, SZ(t) - 1) {
			if (t[k] == t[k + 1])ok = 0;
		}
		if (ok)
			gotolose |= f(t) == LOSE;
	}
	return gamedp[s] = (gotolose ? WIN : LOSE);
}


#include<chrono>
#include<random>
struct randgen {
	mt19937_64 rng;
	randgen() :rng((int)std::chrono::steady_clock::now().time_since_epoch().count()) {}
	LL getrand(LL s, LL t) {
		return rng() % (t - s) + s;
	}
};


void test(int n) {
	string s; {
		randgen rnd;
		FOR(i, 0, n) {
			while (true) {
				string t = string(1, 'a' + rnd.getrand(0, 4));
				if (SZ(s) && s.back() == t.front())continue;
				else {
					s += t;
					break;
				}
			}
		}
	}
	DD(de(s, SZ(s), s.front() == s.back(), "WL"[f(s) == LOSE]))
}

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

	//FOR(i, 0, 10) {
	//	test(10);
	//}
	//FOR(i, 0, 10) {
	//	test(11);
	//}
	//cout << "WL"[f("aba") == LOSE] << endl;
	//cout << "WL"[f("abc") == LOSE] << endl;
	//cout << "WL"[f("abcab") == LOSE] << endl;

	string s; cin >> s;

	cout << ((s.front()==s.back())^(SZ(s)%2)? "First" : "Second") << endl;


	return 0;
}


Measured memory_bytes: 512
/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b, c;
	
	cin>>a>>b>>c;
	
	if(a==b && b!=c)
	{
		cout<<"Yes"<<endl;
		
		return 0;
	}
	
	if(b==c && b!=a)
	{
		cout<<"Yes"<<endl;
		
		return 0;
	}
	
	if(a==c && a!=b)
	{
		cout<<"Yes"<<endl;
		
		return 0;
	}
	
	cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
class Graph{
private:
  int n;// 頂点数
  int m;// 辺の数
  vector<vector<int>> edge;// 辺
  vector<int> d;
  int start;
  vector<int> rev;
  vector<int> loop;
public:
  // 頂点数_nのグラフを作成
  Graph(int _n){ n = _n; edge.resize(n);  }
  // 辺コストありのグラフ作成、_n頂点、_m辺、a[i]->b[i]の辺がある。
  Graph(int _n,int _m,vector<int> a,vector<int> b){
    n = _n;m = _m;edge.resize(n);
    rep(i,m){
      add_edge(a[i], b[i]);
      add_edge(b[i], a[i]); //無向辺
    }
  }  

  // 辺の追加 コストなし
  void add_edge(int from,int to){ edge[from].push_back(to);}

  void dfs(int v) {
    int w = edge[v][0];
    if(d[w] >= 0) {
      start = w;
      return ;
    }
    else {
      d[w] = d[v] + 1;
      rev[d[w]] = w;
      dfs(w);
    }
  }

  void dfs_loop(int v) {
    loop.push_back(v);
    int w = edge[v][0];
    if(w == start) return;
    dfs_loop(w);
  }

  
  void solve(int s,ll k){
    rev.resize(n+1);
    d.resize(n, -1);
    d[s] = 0;
    dfs(s);
    if(d[start] >= k) {
      cout << rev[k]+1 << "\n";
      return ;
    }
    dfs_loop(start);
    int num = loop.size();
    cout << loop[ (k - d[start]) % num] + 1 << "\n";
  }

  
};
int main()
{
  int n;cin >> n;
  ll k; cin >> k;
  vector<int> b(n);
  rep(i,n) {
    cin >> b[i];
    b[i]--;
  }

  
  Graph gp(n);
  rep(i,n) gp.add_edge(i, b[i]);
  gp.solve(0, k);
  
  return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int A, B, Q;
ll S[int(1e5 + 5)], T[int(1e5 + 5)];
ll X;
int SL, SR, TL, TR;

int Binary(){
  SL = 0; SR = A + 1;
  while (SR - SL > 1){
    int now = (SL + SR) / 2;
    if (S[now] < X) SL = now;
    else SR = now; 
  }

  TL = 0; TR = B + 1;
  while (TR - TL > 1){
    int now = (TL + TR) / 2;
    if (T[now] < X) TL = now;
    else TR = now;
  }
  return 0;
}

int main(){
  cin >> A >> B >> Q;
  S[0] = -1e16; T[0] = -1e16;
  for (int i = 1; i <= A; i++) cin >> S[i];
  for (int i = 1; i <= B; i++) cin >> T[i];
  S[A + 1] = 1e16; T[B + 1] = 1e16;


  for (int i = 0; i < Q; i++){
    cin >> X;
    Binary();

    ll ans = max(T[TR] - X, S[SR] - X);
    ans = min(ans, max(X - T[TL], X - S[SL]));

    ans = min(ans, (T[TR] - S[SL]) + min(T[TR] - X, X - S[SL]));
    ans = min(ans, (S[SR] - T[TL]) + min(S[SR] - X, X - T[TL]));

    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 5160
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S,T;
    cin >> S >> T;
    sort(S.begin(),S.end());
    sort(T.begin(),T.end(),greater<char>());
    cout << (S<T ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int K = sc.nextInt();
	    String S = sc.next();
	    
	    if (K < S.length()) {
	      System.out.println(S.substring(0, K) + "...");
	    } else {
	      System.out.println(S);
	    }
	    
	  }
}

Measured memory_bytes: 27076
#include <cstdio>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <utility>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define sci(x) scanf("%d", &x)
#define scd(x) scanf("%lf", &x)
#define scs(x) scanf("%s", x)
#define pri(x) printf("%d\n", x)
#define prd(x) printf("%f\n", x)
#define prs(x) printf("%s\n", x)

#define modp(x, y) (((y) + (x) % (y)) % (y))

int x[100], y[100], a[100];
bool t[100][100];

int main(int argc, char* argv[])
{
	int W, H, N;
	sci(W); sci(H); sci(N);
	for(int i = 0; i < N; i++)
	{
		sci(x[i]);
		sci(y[i]);
		sci(a[i]);
	}

	for(int i = 0; i < N; i++)
	{
		int left = 0, right = W, bottom = 0, top = H;
		switch(a[i])
		{
			case 1:
				right = x[i];
				break;
			case 2:
				left = x[i];
				break;
			case 3:
				top = y[i];
				break;
			case 4:
				bottom = y[i];
				break;
		}
		for(int x = left; x < right; x++)
			for(int y = bottom; y < top; y++)
				t[x][y] = true;
	}
	int ans = 0;
	for(int x = 0; x < W; x++)
		for(int y = 0; y < H; y++)
			if(!t[x][y]) ans++;
	pri(ans);

	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    abc155ProblemA()
}

fun abc155ProblemA() {
    val (a, b, c) = readLine()!!.split(" ").map(String:: toInt)
    if ((a == b && b == c) ||
        (a != b && b != c && a != c)) {
        println("No")
    } else {
        println("Yes")
    }
}

Measured memory_bytes: 36136
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a,b;
  int max=-10001;

  scanf("%d %d",&a,&b );

  if( a + b > max)max = a + b;
  if( a - b > max)max = a-b;
  if( a * b > max)max = a*b;
  printf("%d\n",max );
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m,l;
    cin>>n>>m>>l;
     long long ue[101][101] = {};
     long long sit[101][101] = {};
     long long kam[101][101] = {};
     for(int i = 0;i<n;i++){
         for(int j = 0;j<m;j++){
             cin>>ue[i][j];
         }
     }
     for(int i = 0;i<m;i++){
         for(int j = 0;j<l;j++){
             cin>>sit[i][j];
         }
     }
     for(int i = 0;i<n;i++){
         for(int j = 0;j<l;j++){
             for(int k = 0;k<m;k++){
                 kam[i][j] += ue[i][k]*sit[k][j];
             }
         }
     }
     for(int i = 0;i<n;i++){
         for(int j = 0;j<l;j++){
             cout<<kam[i][j];if(j !=l -1)cout<<" ";
         }cout<<endl;
     }
     return 0;
}



Measured memory_bytes: 3352
n,y = map(int,input().split())
y //= 1000
c = y%5 - 5
while c <= n:
    c += 5
    nc = n-c
    x = y-c
    a = (x-5*nc)//5
    if a < 0 : continue
    b = nc - a
    if b < 0 : continue
    if 10*a+5*b+c == y:
        print(a,b,c)
        break

else:
    print("-1 -1 -1")


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    int n, q, l, r; string s;
    cin>>n>>q>>s;
    vector<int> a(n);
    for(int i = 0; i<n-1; i++){
        if(s[i]=='A' && s[i+1]=='C') a[i+1] = 1;
    }

    for(int i = 1; i<n; i++) a[i] += a[i-1];
    while(q--){
        cin>>l>>r;
        l--;
        r--;
        cout<<a[r]-a[l]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, a[100],cnt=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int i = 1; i < n; i++) {
			if (a[i] < a[i - 1]) {
				swap(a[i], a[i - 1]);
				flag = 1;
				cnt++;
			}
		}
	}
	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;
	cout << cnt << endl;
}


Measured memory_bytes: 3092
def main
  n = gets.chomp.to_i

  frames = gets.split.map(&:to_i)
  ave = frames.inject(:+).to_f / n

  min_dist = 100
  min_idx = 1000
  frames.each_with_index do |f, idx|
    dist = (f - ave).abs
    if dist == 0.0
      puts idx
      return
    elsif dist < min_dist
      min_dist = dist
      min_idx = idx
    end
  end
  puts min_idx
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int temp = sqrt(n);
    cout << temp * temp << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  rep(i, 0, 3001) {
    rep(j, 0, 3001) {
      if(r * i + g * j > n) continue;
      if((i * r + j * g) == n || (n - (i * r + j * g)) % b == 0) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())

totalAmount = 0
first = 300000
second = 200000
third = 100000
extraPrice = 400000


if X == 1:
    totalAmount = first
    pass
elif X == 2:
    totalAmount = second
    pass
elif X == 3:
    totalAmount = third
    pass
elif X < 1 or X > 3:
    totalAmount = 0
    pass

if Y == 1:
    totalAmount = totalAmount + first
    pass
elif Y == 2:
    totalAmount = totalAmount + second
    pass
elif Y == 3:
    totalAmount = totalAmount + third
    pass
elif Y < 1 or Y > 3:
    totalAmount = totalAmount + 0
    pass

if X == 1 and Y == 1:
    totalAmount = totalAmount + extraPrice

print(totalAmount)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define EPS 1e-12
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //result %= MOD;
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------PRIYANSHU RAJPUT----------------------------------------------------------------  //


void solve(){
	string a, b;
	cin>>a>>b;
	int ans = 0;
	for(int i = 0; i < a.length(); ++i) ans += (a[i] != b[i]);
	cout<<ans;
}



int main() {
	fast_io;
    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}



Measured memory_bytes: 3780
import numpy as np
from itertools import product

H,W,K=map(int,input().split(' '))
arr = np.vstack([[int(i) for i in input()] for j in range(H)])
ans = H+W-2
for p in product([0,1],repeat=H-1):
    if sum(p)>ans:
        continue
    sp=np.zeros((sum(p)+1,W),int)
    row=0
    sp[0]+=arr[0]
    for j in range(H-1):
        if p[j]:
            row+=1
        sp[row]+=arr[j+1]
    if np.max(sp)>K:
        continue
    sum_arr = np.zeros(len(sp),int)
    cut_cnt = sum(p)
    for c in range(W):
        sum_arr += sp[:,c]
        if max(sum_arr)>K:
            cut_cnt+=1
            sum_arr=sp[:,c]
            if cut_cnt > ans:
                break
    ans = min(cut_cnt,ans)
print(ans)

Measured memory_bytes: 12676
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int moji[26];
string S;

int main(){
    cin>>S;
    rep(i,S.length())moji[S[i]-'a']++;
    rep(i,26){
        if(moji[i]%2==1){
            out("No");
            return 0;
        }
    }
    out("Yes");
}


Measured memory_bytes: 256
import sys
import math
#sys.stdin=open('input.txt','r')
#sys.stdout=open('output.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

a=ii1()
print(int(a+a*a+a*(a*a)))


Measured memory_bytes: 9348
n = int(input())
p = [int(zz) for zz in input().split()]

ans = 0
for i in range(n-2):
    z = [p[i],p[i+1],p[i+2]]
    if min(z) != z[1] and max(z) != z[1]:
        ans += 1

print(ans)


Measured memory_bytes: 38384
a,b = [int(x) for x in input().split()]

a,b = a-1,b-1

H,W = 100,100


masu = [["." for i in range(100)] for _ in range(100)]
for h in range(100):
    for i in range(100):
        if i < 50:
            masu[h][i] = "#"

def white(masu):
    count = 0
    for i in range(500):
        for h in range(50):
            if a <= count:
                return masu
            count+=1
            masu[2*h][2*i] = "."
            

def black(masu):
    count = 0
    for i in range(500):
        for h in range(50):
            if b <= count:
                return masu
            count+=1
            masu[2*h][99 - 2*i] = "#"
            

def output(masu):
    for line in masu:
       print("".join(line))

print(str(H)+" "+str(W))

masu = white(masu)
masu = black(masu)
output(masu)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B, C;
	cin >> A >> B >> C;
	// A = Bq + r
	int q = A / B;
	int r = A % B;
	int possible = 0;
	for(int s=0; s < B; s++){
		if((r*s - C) % B == 0){
			possible = 1;
			break;
		}
	}
	if(possible == 1){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

typedef long long int lint;

int calc(int year, int month, int day);

int main()
{
	int nCase = 0, year = 0, month = 0, day = 0;
	scanf("%d", &nCase);
	while(nCase-- > 0)
	{
		scanf("%d %d %d", &year, &month, &day);
		printf("%d\n", calc(1000, 1, 1) - calc(year, month, day));
	}
	return 0;
}

int calc(int year, int month, int day)
{
	int ans = 0;
	ans += (year - 1) / 3 * 590;
	int tmp = (year - 1) % 3;
	ans += tmp * 195;
	if(tmp < 2)
		ans += (month - 1) / 2 * 39 + (month - 1) % 2 * 20 + day;
	else
		ans += (month - 1) * 20 + day;
	return ans;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>

using namespace std;

const long long int MOD=1e9+7;

int main() {
    int N;
    cin >> N;
    map<int, long long int> mp;
    bool flag=true;
    for(int n=0; n<N; n++) {
        long long int a;
        cin >> a;
        mp[a]++;
        if(a%2==N%2 || mp[a]>2) {
            flag=false;
        }
    }
    if(flag) {
        long long int ans=1;
        for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
            if(itr->first==0) {
                if(itr->second!=1) {
                    cout << 0 << endl;
                    return 0;
                }
            } else {
                if(itr->second!=2) {
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
        
        for(int i=0; i<N/2; i++) {
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
    
    
    return 0;
    
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int h; cin >> h;
        if (h >= k) sum++;
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ld ans = 0;
    rep(i, n) {
        ld a; string s;
        cin >> a >> s;
        if(s == "JPY") ans += a;
        else ans += a * 380000;
    }
    printf("%.10Lf", ans);
}

Measured memory_bytes: 3812
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;

  REP(i, s.length()) {
    cout << 'x';
  }

  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[n][m], b[m], c[n]={0};
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; i++)  cin>>b[i];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            c[i]+=a[i][j]*b[j];
        }
    }
    for(int i=0; i<n; i++)  cout<<c[i]<<endl;
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll N;
  cin>>N;
  vector<string> S(N);
  ll BA=0,XA=0,BX=0,XX=0,num=0;
  FORi(N){
    cin>>S[i];
    if(S[i][0]=='B'&&S[i][S[i].size()-1]=='A'){
      BA++;
    }else if(S[i][0]=='B'&&S[i][S[i].size()-1]!='A'){
      BX++;
    }else if(S[i][0]!='B'&&S[i][S[i].size()-1]=='A'){
      XA++;
    }else{
      XX++;
    }
    FORj(S[i].size()-1){
     if(S[i][j]=='A'&&S[i][j+1]=='B')num++;
    }
  }
  if(XA>0){
    XA--;
  }else if(BA>0){
    BA--;
  }else{
    cout<<num<<endl;
    return 0;
  }
  if(BX>0){
    BX--;
    num++;
  }else if(BA>0){
    BA--;
    num++;
  }else{
    cout<<num<<endl;
    return 0;
  }
  num+=BA;
  num+=min(XA,BX);
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solve(const vector<vector<int>>& g){
    const int N = g.size();
    vector<int> degree;
    for(int i=0;i<N;i++){
        if(g[i].size() == 1) continue;
        vector<int> visit(N, 0);
        visit[i] = 1;
        degree.push_back(g[i].size());
        vector<int> start;
        for(auto& t : g[i]){
            if(g[t].size() != 1) start.push_back(t);
        }
        if(start.size() > 2) return vector<int>();
        for(auto& s : start){
            int cur = s;
            while(cur != -1){
                degree.push_back(g[cur].size());
                visit[cur] = 1;
                int next = -1;
                for(auto& t : g[cur]){
                    if(g[t].size() == 1) continue;
                    if(visit[t]) continue;
                    if(next != -1) return vector<int>();
                    next = t;
                }
                cur = next;
            }
            reverse(degree.begin(), degree.end());
        }
        bool need_rev = false;
        for(int i=0;i<degree.size();i++){
            if(degree[i] == degree[degree.size()-i-1]) continue;
            need_rev = (degree[i] > degree[degree.size()-i-1]);
            break;
        }
        if(need_rev) reverse(degree.begin(), degree.end());
        break;
    }
    vector<int> res(N);
    for(int i=0;i<N;i++) res[i] = i+1;
    int idx = 1;
    for(auto& d : degree){
        for(int i=0;i<d-2;i++){
            swap(res[idx], res[idx+1]);
            ++idx;
        }
        ++idx;
    }
    return res;
}

int main(){
    int n;
    while(cin >> n){
        vector<vector<int>> g(n);
        for(int i=0;i<n-1;i++){
            int u, v; cin >> u >> v;
            --u; --v;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        auto res = solve(g);
        if(res.empty()){
            cout << -1 << endl;
        } else {
            cout << res[0];
            for(int i=1;i<n;i++) cout << " " << res[i];
            cout << endl;
        }
    }
}

Measured memory_bytes: 8560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
ll dp[1010][4100];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, M;
    cin >> N >> M;
    vector<int> a(M), c(M);
    rep(i,M){
        int b;
        cin >> a[i] >> b;
        rep(_, b){
            int d;
            cin >> d;
            c[i] |= bit(d-1);
        }
    }
    rep(i,M+1)rep(j,bit(N))dp[i][j] = INFLL;
    dp[0][0] = 0;
    rep(i,M){
        rep(j, bit(N)){
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j | c[i]], dp[i][j] + a[i]);
        }
    }
    cout <<  ((dp[M][bit(N) - 1] == INFLL) ?  -1: dp[M][bit(N)-1]) << endl;
}

Measured memory_bytes: 32384
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	vector <int> a(3);
	rep(i,3) {cin >>a[i];}
	sort(a.begin(), a.end());
	if (a[0] == 5 && a[1] == 5 && a[2] == 7) YES
	else NO
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	long long A[114514] = {}; 
	for(int i = 0; i < N; i++) cin >> A[i]; 
	long long absmin = 1145141919; 
	int negcnt = 0; 
	long long abssum = 0; 
	for(int i = 0; i < N; i++){
		abssum += abs(A[i]); 
		absmin = min(absmin, abs(A[i])); 
		if(A[i] <= 0) negcnt ++;
	}
	if(negcnt % 2 == 0) cout << abssum << endl; 
	else cout << abssum - 2 * absmin << endl; 
}

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

int main()
{
    string str;
    map<char,string> m1;
    m1[' '] = "101";
    m1['\''] = "000000";  
    m1[','] = "000011";
    m1['-'] = "10010001";
    m1['.'] = "010001";
    m1['?'] = "000001";        
    m1['A'] = "100101";
    m1['B'] = "10011010";
    m1['C'] = "0101";
    m1['D'] = "0001";
    m1['E'] = "110";
    m1['F'] = "01001";
    m1['G'] = "10011011";
    m1['H'] = "010000";
    m1['I'] = "0111";
    m1['J'] = "10011000";
    m1['K'] = "0110";
    m1['L'] = "00100";
    m1['M'] = "10011001";
    m1['N'] = "10011110";
    m1['O'] = "00101";
    m1['P'] = "111";
    m1['Q'] = "10011111";
    m1['R'] = "1000";
    m1['S'] = "00110";
    m1['T'] = "00111";
    m1['U'] = "10011100";
    m1['V'] = "10011101";
    m1['W'] = "000010";
    m1['X'] = "10010010";
    m1['Y'] = "10010011";
    m1['Z'] = "10010000";

    map<string,char> m2;
    m2["00000"] = 'A';
    m2["00001"] = 'B';
    m2["00010"] = 'C';
    m2["00011"] = 'D';
    m2["00100"] = 'E';
    m2["00101"] = 'F';
    m2["00110"] = 'G';
    m2["00111"] = 'H';
    m2["01000"] = 'I';
    m2["01001"] = 'J';
    m2["01010"] = 'K';
    m2["01011"] = 'L';
    m2["01100"] = 'M';
    m2["01101"] = 'N';
    m2["01110"] = 'O';
    m2["01111"] = 'P';
    m2["10000"] = 'Q';
    m2["10001"] = 'R';
    m2["10010"] = 'S';
    m2["10011"] = 'T';
    m2["10100"] = 'U';
    m2["10101"] = 'V';
    m2["10110"] = 'W';
    m2["10111"] = 'X';
    m2["11000"] = 'Y';
    m2["11001"] = 'Z';
    m2["11010"] = ' ';
    m2["11011"] = '.';
    m2["11100"] = ',';
    m2["11101"] = '-';
    m2["11110"] = '\'';
    m2["11111"] = '?';

    while( getline(cin,str) )
    {
        string conv = "";
        for( int i = 0; i < str.size(); i++ )
            conv += m1[str[i]];

        string res = "";
        for( int i = 0; i < conv.size(); i++ )
        {
            res += conv[i];
            if( i % 5 == 4 )
            {
                cout << m2[res];
                res = "";
            }
        }
        while( res.size() != 0 && res.size() < 5 )
            res += "0";
        if( res.size() == 5 )
            cout << m2[res];
        cout << endl;
    }
    return 0;
}


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

char map[30][30];

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

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

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

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256