akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    int n;
    cin>>n;
    map<string,int> m;
    forn(i,n){
        string s; cin>>s;
        m[s]++;
    }
    for(auto s: {"AC","WA", "TLE", "RE"}){
        cout<<s<<" x "<<m[s]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[200001], ans = 0;
map<ll, ll> mp;

int main()
{
    fast_io;
    ll n, i;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= n; i++)
    {
        ans += mp[a[i] - i];
        mp[-(i + a[i])]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 27896
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
void solve() {
    int n;
    string s;
    cin >> n >> s;
    int a, r;
    a = r = 0;
    for (int i = 0; i < n; i++) {
        if(s[i] == 'I') a++;
        else a--;
        r = max(a, r);
    }
    cout << r << endl;
}
int main() {
   // freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

std::vector<std::pair<int64_t, int64_t>> FactorizeIntoPrimeFactors(const int64_t N) {
  std::vector<std::pair<int64_t, int64_t>> result;
  if (N <= 0LL || N == 1LL) {
    return result;
  }
  int64_t remaining = N;
  for (int64_t i = 2LL; i * i <= remaining; ++i) {
    int64_t count = 0LL;
    while (remaining % i == 0LL) {
      ++count;
      remaining /= i;
    }
    if (count > 0LL) {
      result.push_back(std::pair<int64_t, int64_t>(i, count));
    }
  }
  if (remaining > 1) {
    result.push_back(std::pair<int64_t, int64_t>(remaining, 1));
  }
  return result;
}

int64_t GetNumberOfDigits(const int64_t N) {
  constexpr int64_t kBase = 10;
  int64_t result;
  if (N == 0) {
    result = 1;
  } else if (N < 0) {
    result = GetNumberOfDigits(-N);
  } else {
    result = 0;
    int64_t temp = N;
    while (temp > 0) {
      ++result;
      temp /= kBase;
    }
  }
  return result;
}

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

  int64_t N;
  cin >> N;
  const int64_t initial = static_cast<int64_t>(sqrt(static_cast<double>(N)));
  // vector<pair<int64_t, int64_t>> factors = FactorizeIntoPrimeFactors(N);
  int64_t result = INT64_MIN;
  for (int64_t A = initial; A >= 1; --A) {
    if (N % A == 0) {
      const int64_t B = N / A;
      result = GetNumberOfDigits(B);
      break;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main () {
  string x,y;
  cin >> x >> y;
  int n = x.length();
  int cnt = 0;
  for(int i = 0 ; i < n ; i++){
    if (x[i]!=y[i]){
      cnt++;
    }
  }
  cout << cnt;
}


Measured memory_bytes: 3928
#include <algorithm>
#include <cstdio>

using namespace std;

const int MAXN = 2e3 + 10;

int n, x, y;
int sol[MAXN];

int main(void) {
  scanf("%d%d%d", &n, &x, &y); --x; --y;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = min(abs(i - j),
                  min(1 + abs(i - x) + abs(j - y), 1 + abs(i - y) + abs(j - x)));
      sol[d]++;
    }
  }
  for (int i = 1; i < n; ++i)
    printf("%d\n", sol[i]);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int num;
  int yesno[1000];
  int i, flag;
  int a, b, c;

  scanf("%d", &num);

  for(i = 0; i < num; i++){
    scanf("%d %d %d", &a, &b, &c);
    if(a > b && a > c) flag = 0;
    if(b > a && b > c) flag = 1;
    if(c > a && c > b) flag = 2;

    // YES→1 NO→0
    switch(flag){
    case 0: 
      if(a*a == b*b + c*c){
	yesno[i] = 1;
      } else {
	yesno[i] = 0;
      }
      break;
    case 1: 
      if(b*b == a*a + c*c){
	yesno[i] = 1;
      } else {
	yesno[i] = 0;
      }
      break;
    case 2:
       if(c*c == b*b + a*a){
	yesno[i] = 1;
      } else {
	yesno[i] = 0;
      }
       break;
    }
  }

  for(i = 0; i < num; i++){
    if(yesno[i] == 1){
      printf("YES\n");
    } else if(yesno[i] == 0){
      printf("NO\n");
    }
  }

  return 0;
}

Measured memory_bytes: 584
n = int(input())
a = input().split()
b = input().split()
c = input().split()

result = 0
j = 0
isFirst = True
for i in a:
  m = int(i) - 1
  result += int(b[m])
  if (not (isFirst)) and (j + 1 == m):
      result += int(c[j])
  j = m
  isFirst = False
print(result)

Measured memory_bytes: 3064
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);

  int[] s;
  foreach (d; 3..10) s ~= find753(d);

  writeln(s.assumeSorted.lowerBound(n+1).length);
}

auto find753(int d)
{
  int[] s;
  foreach (i; 0..3^^d) {
    auto r = conv3(i, d);
    if (!r.canFind(0) || !r.canFind(1) || !r.canFind(2))
      continue;
    auto j = 0;
    foreach (k, ri; r)
      j += ri.predSwitch(0, 3, 1, 5, 2, 7) * 10^^k;
    s ~= j;
  }
  return s;
}

auto conv3(int i, int d)
{
  auto r = new int[](d);
  foreach (j; 0..d) {
    r[j] = i%3;
    i /= 3;
  }
  return r;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;



int main(){
    string s,t;cin>>s>>t;
    map<char,vector<ll> > m;
    rep(i,0,s.size())m[s[i]].push_back(i);
    rep(i,0,t.size()){
        if(m[t[i]].size()==0){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll an=0,now=-1;
    rep(i,0,t.size()){
        if(upper_bound(m[t[i]].begin(),m[t[i]].end(),now)==m[t[i]].end()){
            an+=s.size();
            now=m[t[i]][0];
        }
        else now=m[t[i]][upper_bound(m[t[i]].begin(),m[t[i]].end(),now)-m[t[i]].begin()];
    }
    an+=now+1;
    cout<<an<<endl;
}







Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define len(x) (int) (x.size())

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> myvs(26);
    for(int i = 0; i < len(s); i++)
        myvs[s[i]-'a'].push_back(i);
    for(int i = 0; i < len(s); i++)
        myvs[s[i]-'a'].push_back(i+len(s));

    ll ans = 0, p = 0;        
    for(int i = 0; i < len(t); i++) {
        int c = t[i]-'a';
        if (len(myvs[c]) == 0) {
            cout << -1 << '\n';
            return 0;
        }
        p = *lower_bound(myvs[c].begin(), myvs[c].end(), p)+1;
        if (p >= len(s)) {
            p -= len(s);
            ans += len(s);
        }
    }
    ans += p;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b==c+d)
	cout<<"Balanced"<<endl;
	if(a+b>c+d)
	cout<<"Left"<<endl;
	if(a+b<c+d)
	cout<<"Right"<<endl;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, a, b, sum;
    cin >> n >> a >> b;
    sum = a + b;
    long long val = a * (n / sum);
    cout << val + min(a, (n % sum)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  bitset<100'001> dp;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i < a[j]) break;
      if (!dp[i - a[j]]) {
        dp[i] = true;
        break;
      }
    }
  }
  cout << (dp[k] ? "First" : "Second") << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 2*1e5;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    //i-1文字目まで見た時, 最後に何文字使ったか
    auto dp = make_vec(n+1, 5, 0);
    rep(i,n) rep2(j,1,5)
    {
        rep2(k,1,5)
        {
            int ni = i+k;
            int nj = k;
            if(ni > n) continue;
            if(i >= j)
            {
                string u = s.substr(i-j,j);
                string v = s.substr(i,k);
                if(u == v) continue;
            }
            chmax(dp[ni][nj], dp[i][j] + 1);
        }
    }
    int ans = 0;
    rep(i,4) chmax(ans, dp[n][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14448
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		string[] b=new string[s[0]];
		int[][] a=new int[s[0]][];
		for(int i = 0;i<s[0];i++) {
			b[i]=sc.S;
			int[] h=new int[s[1]];
			int[] g=new int[s[1]];
			a[i]=new int[s[1]];
			for(int j = 0;j<s[1];j++) {
				if(b[i][j]=='.'){h[j]=(j!=0?h[j-1]:0)+1;}
			}
			for(int j = s[1]-1;j>=0;j--) {
				if(b[i][j]=='.'){g[j]=(j!=s[1]-1?g[j+1]:0)+1;}
				a[i][j]=h[j]+g[j]-1;
			}
		}
		int ans=0;
		for(int j = 0;j<s[1];j++) {
			int[] h=new int[s[0]];
			int[] g=new int[s[0]];
			for(int i = 0;i<s[0];i++) {
				if(b[i][j]=='.'){h[i]=(i!=0?h[i-1]:0)+1;}
			}
			for(int i = s[0]-1;i>=0;i--) {
				if(b[i][j]=='.'){g[i]=(i!=s[0]-1?g[i+1]:0)+1;}
				a[i][j]+=h[i]+g[i]-2;
				ans=Max(ans,a[i][j]);
			}
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}
	public int[] Ia3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}
	public long[] La3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 62772
function Main(s) {
	s = s.split("\n");
	var n = s[0];
	var a = s[1].split(" ").map(a => parseInt(a));
	var b = s[2].split(" ").map(a => parseInt(a));
	
	var sa = a.reduce((a,b) => a+b);
	var sb = b.reduce((a,b) => a+b);
	var ab = 0;
	for(var i = 0; i < n; i++){
		ab += Math.ceil(Math.max(b[i] - a[i], 0) / 2);
	}
	console.log(ab <= sb - sa ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
//using Graph = vector<vector<int>>;


const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  int n;
  cin >> n;
  ll d[n+1][2];

  ll cnt = 0;

  bool ok = false,flag = false;;
  rep (i,n){
    cin >> d[i][0] >> d[i][1];
  }
  rep (i,n){
    if (d[i][0] == d[i][1]) {
      ok = true;
      cnt++;
    }
    else {
      ok = false;
      cnt = 0;
    }
    if (cnt == 3) {
      flag = true;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

int main(){
	string s;
	cin >> s;
	bool flag = false;
	
	for (int i=0; i<3; ++i){
		if (s[i]==s[i+1]){
			flag = true;
		}
	}
	
	if (flag == true){
		cout << "Bad" << endl;
	} else {
		cout << "Good" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for per in ab:
    diff = []
    for check in cd:
        diff.append(abs(per[0]-check[0]) + abs(per[1]-check[1]))
    print(diff.index(min(diff))+1)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<numeric>
#include<string>
#include<cstdio>
using namespace std;

int main(){
	int n, m;
	bool door = false;
	string id[256];
	string id2;

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> id[i];
	}

	cin >> m;

	for (int i = 0; i < m; i++){
		cin >> id2;
		for (int j = 0; j < n; j++){
			if (id2 == id[j]){
				door = !door;
				if (door){
					cout << "Opened by " << id2 << endl;
				}
				else cout << "Closed by " << id2 << endl;
				break;
			}
			else {
				if (j == n - 1)
					cout << "Unknown " << id2 << endl;
			}
		}
	}
	return 0;
}

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

bool number753_checker(string num_str) {
    if (num_str.find("3") == string::npos) {
        return false;
    }
    if (num_str.find("5") == string::npos) {
        return false;
    }
    return num_str.find("7") != string::npos;
}

int solve(int n) {
    stack<string> targets;
    targets.push("3");
    targets.push("5");
    targets.push("7");
    int ans = 0;
    while (!targets.empty()) {
        string target_num = targets.top();
        targets.pop();

        if (stoll(target_num) > n) {
            continue;
        }

        if (number753_checker(target_num)) {
            ++ans;
        }
        targets.push(target_num + "3");
        targets.push(target_num + "5");
        targets.push(target_num + "7");
    }
    return ans;
}

int main() {
    int n;
    cin >> n;

    cout << solve(n) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
#define mod 1000000007

long long  calc(long long  p,int q){
	long long ans =1;
	for(int i=0;i<q;i++){
		ans = (ans*p)%mod;
	}
	return ans;
}

int main(){
	long long  ruijo[401][401]={};
	for(int t=0;t<401;t++){
		ruijo[0][t]=t;
	}
	for(int k=1;k<401;k++){
		for(int l=1;l<401;l++){
			ruijo[k][l] = (ruijo[k][l-1] + calc(l,k))%mod;
		}
	}
	long long  n,c,tmp,g;
	long long dp[401][401]={};
	dp[0][0]=1;
	vector <long long> a,b;
	cin >> n >>c;
	for(int i=0;i<n;i++){
		cin >> tmp;
		a.push_back(tmp);
	}
	for(int j=0;j<n;j++){
		cin >> tmp;
		b.push_back(tmp);
	}
	for(int x=1;x<=n;x++){
		for(int y=0;y<=c;y++){
			for(int z=0;z<=y;z++){
				g = (dp[x-1][y-z]*(ruijo[z][b[x-1]]-ruijo[z][a[x-1]-1]+2*mod))%mod;
				dp[x][y]=(dp[x][y]+g)%mod;
			}
		}
	}
	cout << dp[n][c] <<endl;
	return 0;
}

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int x,a;
    cin>>x>>a;
    cout<<(x<a ? 0 : 10)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define fi first
#define se second
const int inf = 1e9;

int a[100][2], b[100][2];
int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 0;i < n;i++)scanf("%d%d", &a[i][0], &a[i][1]);
	for(int i = 0;i < m;i++)scanf("%d%d", &b[i][0], &b[i][1]);
	for(int i = 0;i < n;i++){
		P p = P(inf,-1);
		for(int j = 0;j < m;j++){
			int d = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
			if(p.fi > d){
				p = P(d, j+1);
			}
			//printf("d=%d %d: \n", a[i][0], b[j][0]);
		}
		printf("%d\n", p.se);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        while(n>0){
            if(n&1) a*=*this;
            *this*=*this;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

struct combination{
    int N;
    vector<mint> fac,finv,inverse;
    combination(int N=0):N(N){
        fac.resize(N+1);finv.resize(N+1);
        fac[0]=1;
        for(int i=1;i<=N;++i){fac[i]=fac[i-1]*i;}
        finv[N]=fac[N].inv();
        for(int i=N-1;i>=0;--i){finv[i]=finv[i+1]*(i+1);}
    }
    void inverse_build(){
        inverse.resize(N+1);
        inverse[1]=1;
        for(int i=2;i<=N;++i){inverse[i]=finv[i]*fac[i-1];}
    }
    constexpr mint c(const int& n,const int& k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k]*finv[k];
    }
    constexpr mint p(const int& n,const int& k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k];
    }
};

int main(){
    combination com(1000000);
    int x,y;
    cin >> x >> y;
    mint ans = 0;
    if(2*y-x<0||2*x-y<0);
    else if((2*y-x)%3 != 0 || (2*x-y)%3 != 0);
    else{
        int s = (2*x-y)/3;
        int t = (2*y-x)/3;
        ans = com.c(s+t,s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18640
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////

ll dp[3010][3010];

void solve(){
  inl(N); out(N * N);
  

}

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

const int base = 111;

void solve(long long N){
    for(int i = 0; i <= 9; ++i){
        if(base*i >= (int)N){
            cout << base*i << endl;
            break;
        }
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

int main()
{
  int N;
  cin>>N;
  string S;
  cin>>S;
  int len=0,len1=0;
  len=S.size();
  int i=0,j=0;
  while(i<len)
  {
  	if(S[i] == S[i+1])
    {
      int k;
      k=i;
      while(S[k]==S[k+1])
      {
      k++;
      }
      i=k+1;
      j++;
    }
    else
    {
      i++;
      j++;
    }
  }
  cout<<j;
}


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

typedef long long int ll;

int main() {
	ll a = 0;
	cin >> a;
	int key = 0;
	ll keta = 0;
	ll b = a;

	while (b >= 10) {
		keta += 1;
		b = b / 10;

	}
	ll m = a;
	keta += 1;
	//桁数
	for (int i = 1; i <= keta-1; i++) {
		m = m / 10;
	}

	//mは最高桁の数字
	ll c = a;
	for (int i = 1; i <= keta; i++) {
		int  k = c % 10;
		if (k == 9) {
			key += 1;
		}
		c = c / 10;
	}

	if (keta - 1 == key && m != 9) {
		cout << 9 * (keta - 1) + m << endl;
	}
	else if (keta == key) {
		cout << 9 * keta << endl;
	}
	else {
		cout << 9 * (keta - 1) + m - 1 << endl;
	}

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int answer=0;
  vector<int> L(N);
 for (int i=0; i<N; i++){
   
   cin >> L.at(i);
 }
   sort(L.begin(), L.end());
 
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1;k<N; k++){
        
        if (L.at(i)!=L.at(j) && L.at(i)!=L.at(k) && L.at(j)!=L.at(k)){
         
          if (L.at(k)-L.at(i) < L.at(j) && L.at(j) < L.at(i)+L.at(k)){
            answer++;
          }
        }
      }
    }
  }
  if (N<3){
    answer=0;
  }
  cout << answer << endl;
            
}
  


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = (int) 2e18;

int32_t main(){
	int n, m, x;
	cin >> n >> m >> x;
	vector<vector<int>> v(n, vector<int>(m));
	vector<int> cost(n);
	for(int i=0; i<n; i++){
	    cin >> cost[i];
	    for(int j=0; j<m; j++){
	        cin >> v[i][j];
	    }
	}
	int tot = 1ll << n;
	int res = inf;
	for(int mask=0; mask<tot; mask++){
	    int mCost = 0;
	    vector<int> mAlgo(m);
	    for(int i=0; i<n; i++){
	        int f = 1ll << i;
	        if(mask & f){
	            mCost += cost[i];
	            for(int j=0; j<m; j++){
	                mAlgo[j] += v[i][j];
	            }
	        }
	    }
	    bool valid = true;
	    for(int i=0; i<m; i++){
	        valid &= (mAlgo[i] >= x);
	    }
	    if(valid)
	        res = min(res, mCost);
	}
	if(res == inf)
	    cout << -1 << "\n";
	else
	    cout << res << "\n";
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(){
	int number[100];
	int N;
	int i,j,k,tmp,count;

	scanf("%d",&N);

	for(count = 0;count < N; count++){
		scanf("%d",&number[count]);
	}
	//sort ??¨???
	for(j=0;j<N;j++){
		
		for(i=0;i<N;i++){
			printf("%d",number[i]);
			if(i == N-1){
				printf("\n");
			}
			else{
				printf(" ");
			}
		}
		
		for(k=j+1;k>0;k--){
			if(number[k] - number[k-1]<0){
				tmp = number[k];
				number[k] = number[k-1];
				number[k-1] = tmp;
			}
		}
	}
}

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

const int maxi = 111111;
ll a[maxi];
map<ll, ll> mp;
ll cnt = 0;

int main() {
    int n;

    cin>>n;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
        mp[a[i]]++;
    }

    for(int i=1; i<=n; i++) {
        if(mp[a[i]] != a[i]) {
            if(mp[a[i]] < a[i]) cnt += mp[a[i]];
            else cnt += mp[a[i]]- a[i];
            mp[a[i]] = a[i];
        }
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    string a , b , c ;
    cin>>a>>b>>c ;
    if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
    {
        cout<<"YES"<<endl ;
    }
    else
    {
        cout<<"NO"<<endl ;
    }

    return 0 ;
}


Measured memory_bytes: 3596
n=int(input())
cc = 0
for i in range(1, n+1, 2):
    c = 0
    for j in range(1, i+1, 2):
        if i % j == 0:
            c += 1
        if c > 8:
            break
    if c == 8:
        cc += 1
print(cc)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n, k;
   cin>>n>>k;
   vector<int> h(n);
   rep(i, n) cin>>h[i];

   sort(h.rbegin(), h.rend());
   ll cnt=0;
   for(int i=k; i<n; i++) cnt+=h[i];

   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 4032
#D 
inp = input().split(' ')
N = int(inp[0])
K = int(inp[1])

print((int((N+1)*((N+1)*(N+2) - K*(K-1))/2.0 - ((N+1)*(N+2)*(2*N+3) - (K-1)*K*(2*K-1))/6.0) + (N+1+1-K)) % (int(10**9) + 7))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define ll long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
vector <ll> g[100005];
ll dp[100005];
ll dfs(ll u){
	if(dp[u] != -1) return dp[u];
	dp[u] = 0;
	fop(i,0,g[u].size()){
		dp[u] = max(dfs(g[u][i]) + 1, dp[u]);
	}
	return dp[u];
}
int main(){
	ll n, m;
	cin >> n >> m;
	fop(i,0,m){
		ll x, y;
		cin >> x >> y;
		g[x].push_back(y);
	}
	memset(dp,-1,sizeof(dp));
	ll ans = 0;
	fop(i,1,n+1){
		ans = max(ans,dfs(i));
	}
	cout << ans;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  cout << (x-a)%b << endl;
}

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

int main() {
  int n; cin>>n;
  string S; cin>>S;

  int cnt=0;
  rep(i, n-2) {
    if (S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C') {
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 100000

int main()
{
    int N; 
    int sum = 0;
    int num[26] = {0};
    int flg = 0;
    string str;
    string alp = "abcdefghijklmnopqrstuvwxyz";

    cin >> str;

    //sort(str.begin(), str.end());
    //str.erase(unique(str.begin(), str.end()), str.end());

    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < str.size(); j++){
            if(alp[i] == str[j]) {
                num[i]++;
            }
        }
    }

    for(int i = 0; i < 26; i++) {
        if(!num[i]) {
            cout << alp[i] << endl;
            flg = 1;
            break;
        }
    }

    if(!flg) {
        cout << "None" << endl;
    } 

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
signed main() 
{ 
    fast;
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int i = 0;
    int j = 0;
    int ch = 0;
    while(i<n || j<n)
    {
        if(ch%2==0)
        {
            cout<<s[i];
            i++;
        }
        else
        {
            cout<<t[j];
            j++;
        }
        ch = ch^1;
    }

} 

Measured memory_bytes: 256
from collections import Counter
import heapq

n,m = map(int,input().split())
l = list(map(int,input().split()))

hq  = sorted(tuple(Counter(l).items()), key=lambda x:x[0])

heapq.heapify(hq)
# print(hq)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])

for b,c in BC:
    while b > 0:
        x,y = heapq.heappop(hq)
        if x < c:
            if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
        else:
            heapq.heappush(hq,(x,y))
            break
    # print(hq)

ans = 0
for i in range(len(hq)):
    ans += hq[i][0]*hq[i][1]
print(ans)

Measured memory_bytes: 115432
#include <iostream>

using namespace std;

int main(){
  
    int H,W,N,r,c;
    int L,R,U,D;
    int i;
    string First,Second;

    cin>>H>>W>>N;
    cin>>r>>c;
    cin>>First>>Second;
    L=R=U=D=0;
    for (i=N-1;i>=0;i--){
        if(Second[i]=='U') D=(D-1>0)?D-1:0;
        if(Second[i]=='D') U=(U-1>0)?U-1:0;
        if(Second[i]=='L') R=(R-1>0)?R-1:0;
        if(Second[i]=='R') L=(L-1>0)?L-1:0;

        if(First[i]=='U') U++;
        if(First[i]=='D') D++;
        if(First[i]=='R') R++;
        if(First[i]=='L') L++;

        if (L+R>=W || U+D>=H){
            cout<<"NO\n";
            return 0;
        }
    }

    if(L>=c || c+R>W || U>=r || r+D>H)
        cout<<"NO\n";
    else
        cout<<"YES\n";

    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    string ans = "";

    rep(i, s.size()){
        if(s[i] == '0') ans += "0";
        else if(s[i] == '1') ans += "1";
        else{
            if(ans.empty()) continue;
            else ans.erase(ans.size()-1);
        }
    }
    cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[15],ans=0;
	for (int i = 0; i < 15; ++i)
	{
		a[i]=-1;
	}
	while (a[11]==-1)
	{
		++a[0];
		long long now=0;
		while (a[now]==3)
		{
			a[now]=0;
			++now;
			++a[now];
		}
		long long tmp=0,d=1,f1=0,f2=0,f3=0;
		for (int i = 0; i < 15; ++i)
		{
			if (a[i]==0)
			{
				f1=1;
				tmp+=3*d;
			}
			else if (a[i]==1)
			{
				f2=1;
				tmp+=5*d;
			}
			else if (a[i]==2)
			{
				f3=1;
				tmp+=7*d;
			}
			d*=10;
		}
		if (tmp>n)
		{
			break;
		}
		if (f1==1&&f2==1&&f3==1)
		{
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 10002;
// const int mo = 1e9 + 7;

int n, ans = 0;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;

	int a = 0, b = 0, c = 0;
	string s;
	for (int i = 0; i < n; ++i) {
		cin >> s;

		int m = s.length();
		for (int j = 0; j < m - 1; ++j)
			if (s[j] == 'A' && s[j+1] == 'B')
				++ans;

		if (s[0] == 'B' && s[m-1] == 'A')
			++c;
		else if (s[0] == 'B')
			++b;
		else if (s[m-1] == 'A')
			++a;
	}

	ans += min(a, b);

	if (c > 0) {
		ans += c - 1;
		if (max(a,b) > 0)
			++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), m = fs.nextInt();
		UnionFind uf = new UnionFind(n);
		for(int i=0;i<m;i++) {
			int x = fs.nextInt()-1, y = fs.nextInt()-1, z = fs.nextInt();
			uf.unite(x, y);
		}
		System.out.println(uf.getGroupNum());
	}
}

class UnionFind{
	int parent[];
	UnionFind(int n){
		parent = new int[n];
		Arrays.fill(parent,  -1);
	}
	
	int getGroupNum(){
		int cnt = 0;
		for(int i=0;i<parent.length;i++) {
			if(parent[i]<0)cnt++;
		}
		return cnt;
	}
	
	
	int root(int x) {
		if(parent[x]<0)return x;
		return parent[x] = root(parent[x]);
	}
	
	boolean same(int x, int y) {
		return root(x) == root(y);
	}
	
	int size(int x) {
		return -parent[root(x)];
	}
	
	void unite(int x, int y) {
		if(same(x,y)) return;
		if(size(x)>size(y)) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		parent[root(y)] += parent[root(x)];
		parent[root(x)] = y;
	}
	
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 40996
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j, N, tmp, cnt=0;
	int p[100001] = { 0 };
	int pp[100001] = { 0 };

	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> p[i];
	}

	int flag;
	for (; ; ) {
		flag = 0;
		for (i = 1; i <= N; i++) {
			if (i == p[i-1]) {
				tmp = p[i-1];
				p[i-1] = p[i ];
				p[i ] = tmp;
				cnt++;
				flag = 1;
				break;
			}

		}
		if (flag == 0) {
			break;
		}


	}


	//cout << "cnt->" << cnt << endl;
	cout  << cnt << endl;




	return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int main(void){
    int n,m,t[100],p,x,ans[100];
    int sum=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",t+i);
        sum+=t[i];
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&p,&x);
        ans[i] = sum - t[p-1] + x;
    }

    for(int i=0;i<m;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int M = 120000;
const int N = 50010;

int n, m, tt;
int x[M];
int y[M];

bitset<N> bb[N];

int en[N];
char ans[M];

void solve1() {
	for (int i = 0; i < n; ++i) {
		bb[i][i] = 1;
	}
	for (int i = 0; i < m; ++i) {
		bb[x[i]] |= bb[y[i]];
		bb[y[i]] |= bb[x[i]];
	}

	for (int i = 0; i < n; ++i) {
		if (bb[i].count() == n) {
			en[i] = 1;
			for (int i = m - 1; i >= 0; --i) {
				if (en[x[i]]) {
					ans[i] = '^';
					en[y[i]] = 1;
				} else {
					en[x[i]] = en[y[i]];
					ans[i] = 'v';
				}
			}
			cout << ans << "\n";
			exit(0);
		}
	}

	cout << -1 << "\n";
}

int dp[500][500];
int go[M];

void solve2() {
	set<pair<int, int>> ss;
	for (int i = 0; i < m; ++i) {
		ss.insert({x[i], y[i]});
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (ss.count({i, j}) == 0) {
				for (int k = 0; k < m; ++k) {
					if (x[k] == i || x[k] == j) {
						ans[k] = '^';
					} else {
						ans[k] = 'v';
					}
				}
				cout << ans << "\n";
				exit(0);
			}
		}
	}


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

	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) {
			if (dp[y[i]][j] < M && dp[x[i]][j] == M) {
				dp[x[i]][j] = i;
				dp[j][x[i]] = i;
			}
			if (dp[x[i]][j] < M && dp[y[i]][j] == M) {
				dp[y[i]][j] = i;
				dp[j][y[i]] = i;
			}
		}
		go[i] = dp[x[i]][y[i]];
		dp[x[i]][y[i]] = dp[y[i]][x[i]] = M;
	}

	for (int a = 0; a < n; ++a) {
		for (int b = a + 1; b < n; ++b) {
			if (dp[a][b] < M) {
				for (int i = m - 1; i >= 0; --i) {
					dp[x[i]][y[i]] = dp[y[i]][x[i]] = go[i];
					for (int j = 0; j < n; ++j) {
						if (dp[y[i]][j] == i) {
							dp[y[i]][j] = M;
							dp[j][y[i]] = M;
						}
						if (dp[x[i]][j] == i) {
							dp[x[i]][j] = M;
							dp[j][x[i]] = M;
						}
					}
					if (x[i] == a && y[i] == b) {
						assert(false);
					}
					if (x[i] == b && y[i] == a) {
						assert(false);
					}
					if (x[i] == a) {
						ans[i] = '^';
						if (dp[a][b] == M) {
							a = y[i];
						}
					} else if (y[i] == a) {
						ans[i] = 'v';
						if (dp[a][b] == M) {
							a = x[i];
						}
					} else if (x[i] == b) {
						ans[i] = '^';
						if (dp[a][b] == M) {
							b = y[i];
						}
					} else if (y[i] == b) {
						ans[i] = 'v';
						if (dp[a][b] == M) {
							b = x[i];
						}
					} else {
						ans[i] = 'v';
					}
					assert(dp[a][b] < M);
				}
				cout << ans << "\n";
				exit(0);
			}
		}
	}

	cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> m >> tt;
	for (int i = 0; i < m; ++i) {
		cin >> x[i] >> y[i];
		--x[i], --y[i];
	}

	if (tt == 1) {
		solve1();
	} else {
		solve2();
	}

	return 0;
}




Measured memory_bytes: 306944
n,k,q=map(int,input().split())

dic={}

for i in range(q):
    a=int(input())
    dic[a]=dic.get(a,0)+1

for i in range(1,n+1):
    win=dic.get(i,0)
    if k-(q-win)<=0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 9064