akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

char T[9][5] = 
  { {'.', ',', '!', '?', ' '}, 
    {'a', 'b', 'c'},
    {'d', 'e', 'f'},
    {'g', 'h', 'i'},
    {'j', 'k', 'l'},
    {'m', 'n', 'o'},
    {'p', 'q', 'r', 's'},
    {'t', 'u', 'v'},
    {'w', 'x', 'y', 'z'} };

int C[9] = {5, 3, 3, 3, 3, 3, 4, 3, 4};

int main() {
  int N;
  cin >> N;
  for (int k=0; k<N; k++) {
    string S;
    cin >> S;
    string A = "";
    int now;
    int count = 0;
    for (unsigned int i=0; i<S.size(); i++) {
      int x = (int)S[i] - '0';
      if (x != 0) {
	now = x;
	count++;
      } else if (count > 0){
	A += T[now-1][(count-1)%C[now-1]];
	count = 0;
      }
    }
    cout << A << endl;
  }
}

Measured memory_bytes: 1216
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
    ll N;
    string s;
    cin>>N>>s;
    for(ll i=0;i<s.size();i++)
    {
        cout<<(char)('A'+(s[i]-'A'+N)%26);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int a[100001];
signed main(){
	int n, ans = 0, d = inf;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld", &a[i]);
	sort(a, a+n);
	int mn = a[n-1]/2, mx = (a[n-1]+1)/2;
	rep(i,n){
		if(d > llabs(a[i]-mn)){
			ans = a[i];
			d = llabs(a[i]-mn);
		}
		if(d > llabs(a[i]-mx)){
			ans = a[i];
			d = llabs(a[i]-mx);
		}
	}
	printf("%lld %lld\n", a[n-1], ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const ll MOD = (ll)1e9 + 7LL;
ll dp[(int)1e5 + 5][4];

int main()
{
	memset(dp, 0LL, sizeof(dp));
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string S; cin >> S;
	int N = (int)S.length();
	
	dp[0][0] = 1LL;
	rep (i, N){
		if (S[i] == 'A' || S[i] == '?'){
			rep (j, 4){
				dp[i+1][j] += dp[i][j];
			} // end rep
			dp[i+1][1] += dp[i][0];
		} // end if

		if (S[i] == 'B' || S[i] == '?'){
			rep (j, 4){
				dp[i+1][j] += dp[i][j];
			} // end rep
			dp[i+1][2] += dp[i][1];
		} // end if

		if (S[i] == 'C' || S[i] == '?'){
			rep (j, 4){
				dp[i+1][j] += dp[i][j];
			} // end rep
			dp[i+1][3] += dp[i][2];
		} // end if

		rep (j, 4){
			dp[i+1][j] %= MOD;
		} // end rep
	} // end rep

	cout << dp[N][3] << endl;

	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,j,k,ans=0;cin>>N;ll L[N];
  REP(i,N)cin>>L[i];
  REP(k,N)REP(j,k)REP(i,j)if(L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]&&abs(L[j]-L[k])<L[i]&&L[i]<L[j]+L[k])ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <math.h>



int main (void) {
int n;
scanf("%d",&n);
int array[n];
int j=1;
int count=0;
for (int i=1;i<=n;i++){
    scanf("%d",&array[i]);
         while (j<=i){
           if (j==i && array[i]<=array[j]){
            count++;
            break;}
            else if (array[i]<=array[j] && j<i)j++;
            else if (array[i]>=array[j])break;
            }
}
printf("%d",count);
return EXIT_SUCCESS;
}



Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_K = (int)1e5 + 777;

int dist[MAX_K], k;

void solve() {
	cin >> k;

	for(int i = 0; i < k; ++i) {
		dist[i] = INF;
	}

	for(int digit = 1; digit < 10; ++digit) {
		dist[digit % k] = std::min(dist[digit % k], digit);
	}

	std::set<pii> setik;

	for(int i = 0; i < k; ++i) {
		setik.emplace(dist[i], i);
	}

	while(!setik.empty()) {
		auto iter = setik.begin();
		int v = iter->second;
		setik.erase(iter);

		for(int digit = 0; digit < 10; ++digit) {
			int u = (10 * v + digit) % k;

			if(dist[u] > dist[v] + digit) {
				setik.erase({dist[u], u});
				dist[u] = dist[v] + digit;
				setik.emplace(dist[u], u);
			}
		}
	}

	cout << dist[0] << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int n;
	cin>>n;
	if(n%1000!=0)
	cout<<1000-(n%1000)<<endl;
	else
	cout<<0<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define endl '\n'
using namespace std;
const int N=1e5+1;


int32_t main()
 {
 ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
 int x,k,d,ans; cin>>x>>k>>d;
 int a=abs(x)/d;
 if(a>=k){ans=abs(x)-k*d;}
 else
    {ans=abs(x)-a*d; k-=(a);
       if(ans>abs(ans-d)){k--;}
        ans=min(ans,abs(ans-d));
       if(k%2!=0){ans=(min(abs(ans-d),ans+d));}
    }


 cout<<ans;
 }

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
vector<int>adj[N+2];
vector<pair<int,int> >bk;
int vis[1000+2],lev[N+2],prnt[1000+2];
void dfs(int node,int par,int lv)
{
  lev[node]=lv;prnt[node]=par;
  vis[node]=1;
  for(auto x:adj[node])
  {
    if(vis[x])bk.push_back({node,x});
    else dfs(x,node,lv+1);
  }
}
int main()
{
  //freopen("inp.txt","r",stdin);
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n,m;cin>>n>>m;
  for(int i=1;i<=n;i++)adj[i].clear();
  for(int i=1;i<=m;i++)
  {
    int u,v;cin>>u>>v;
    adj[u].push_back(v);
  }
  int mn=n+1,u,v;vector<int>pr;
  for(int i=1;i<=n;i++)
  {
    memset(vis,0,sizeof(vis));
    bk.clear();dfs(i,-1,1);
    for(auto x:bk)
    {
      int df=lev[x.first]-lev[x.second];
      if(df>0&&df<mn)
      {
        int f=0;u=x.first,v=x.second;vector<int>tmp;
        while(true)
        {
          if(u==-1){f=1;break;}
          tmp.push_back(u);if(u==v)break;
          u=prnt[u];
        }
        if(!f)mn=df,pr=tmp;
      }
    }
  }
  if(mn>n)cout<<-1<<endl,exit(0);
  cout<<mn+1<<"\n";
  for(auto x:pr)
    cout<<x<<"\n";
  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}

struct Node {
  Node *par;
  Node *ch[26];
  int val = -1;
  int cnt[26];

  Node() {
    REP(i, 26) {
      par = nullptr;
      ch[i] = nullptr;
      cnt[i] = 0;
    }
  }
};

void dfs(Node *now, vi &nowcnt) {
  REP(i, 26) {
    now->cnt[i] += nowcnt[i];
  }
  if(now->par == nullptr) return;
  nowcnt[now->val] = 1;
  dfs(now->par, nowcnt);
}

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

  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, n) {
    cin >> s[i];
    reverse(ALL(s[i]));
  }

  Node *head = new Node();
  REP(i, n) {
    Node *now = head;
    REP(j, SZ(s[i])) {
      int to = s[i][j] - 'a';
      if (now->ch[to] == nullptr) {
        now->ch[to] = new Node();
      }
      now->ch[to]->par = now;
      now = now->ch[to];
      now->val = to;
    }
    vi nowcnt(26);
    dfs(now, nowcnt);
  }

  ll ans = 0;
  REP(i, n) {
    Node *now = head;
    REP(j, SZ(s[i])-1) {
      now = now->ch[s[i][j]-'a'];
    }
    int idx = s[i][SZ(s[i])-1] - 'a';
    ans += now->cnt[idx] - 1;
  }
  cout << ans << endl;


}








Measured memory_bytes: 332300
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    string s; cin >> s;
    cin >> s;
    char c = s[0];

    cout << 'A' << c << 'C' << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, m;
vector<long long> a;
vector<pair<long long, long long>> v;

long long solve();

int main() {
  cin >> n >> m;
  a.resize(n);
  v.resize(m);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < m; ++i) cin >> v[i].se >> v[i].fi;
  sort(a.begin(), a.end(), greater<long long>());
  sort(v.begin(), v.end(),
       greater<pair<long long, long long>>());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, cnt = 0, nowa = 0, nowv = 0;
  while(cnt < n) {
    if(nowv < m && v[nowv].fi >= a[nowa]) {
      ans += min(n - cnt, v[nowv].se) * v[nowv].fi;
      cnt += min(n - cnt, v[nowv].se);
      ++nowv;
    }
    else {
      ans += a[nowa++];
      ++cnt;
    }
  }
  return ans;
}

Measured memory_bytes: 2560
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits



def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))



sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = list(input())

s_mae = ''.join([s[0], s[1]])
s_usiro = ''.join([s[2], s[3]])

s_mae = int(s_mae)
s_usiro = int(s_usiro)


flag = [0, 0]

if (0 <= s_mae and s_mae < 100 and 0 < s_usiro and s_usiro < 13):
    flag[0] = 1
    
if (0 < s_mae and s_mae < 13 and 0 <= s_usiro and s_usiro < 100):
    flag[1] = 1

if flag == [0, 0]:
    print('NA')
elif flag == [1, 0]:
    print('YYMM')
elif flag == [0, 1]:
    print('MMYY')
else:
    print('AMBIGUOUS')    




Measured memory_bytes: 3948
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int X = scan.nextInt();
		int []A = new int[M];
		for(int i = 0; i< M; i++) {
			A[i] = scan.nextInt();
		}
		scan.close();
		int index1 = X;
		int cost1 = 0;
		int cost2 = 0;
		for(int i = 0; i < X - 1; i++) {
			index1 --;
			for(int j = 0; j < M; j++) {
				if(index1 == A[j]) {
					cost1 ++;
				}
			}
		}
		cost2 = A.length - cost1;
		if(cost2 > cost1) {
			System.out.println(cost1);
		}else {
			System.out.println(cost2);
		}

	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N,a,b,c;
string S;
ll solve(int P) {
    vector<ll> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main() {
    cin >> S;
    N = (ll)S.size();
    // a = solve(3);
    // b = solve(673);
    c = solve(2019);
    cout << c << endl;
}

Measured memory_bytes: 3752
n = int(input())

a = []
x = [[] for _ in range(n)]

for i in range(n):
    
    k = int(input())
    a.append(k)
    
    for j in range(k):
        x[i].append(list(map(int,input().split())))

# print(x)
ans = 0
for i in range(1<<n):
    
    cnt = bin(i).count("1")
    if ans > cnt:
        continue
    flag = True
    for j in range(n):
        # if i==3:
        #     print(i,j,i>>j&1,cnt)
        if i>>j & 1:
            # True if 1
            # if i==3:
                # print(i,j)
            for t in x[j]:
                # 証言:testimony
                # if i == 3:
                    # print(i,t[0]-1, i>>t[0]-1, t[1])
                if (i>>(t[0]-1) &1 ) != t[1]:
                    flag = False
                        # break
            # if flag == False:
            #     break
    # if flag == False:
    #     break
    if flag == True:
        # print(i) # 0 000
        ans = cnt

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
    int i,a,b,s,result;
    result = 0;

    while( scanf( "%d %d" , &a , &b ) != EOF ){
        s = a + b;    
        if( s >= 1000000 ){ result = 7;
        }else if( s >= 100000 ){ result = 6;
        }else if( s >= 10000 ){ result = 5;
        }else if( s >= 1000 ){ result = 4;
        }else if( s >= 100 ){ result = 3;
        }else if( s >= 10 ){ result = 2;
        }else{ result = 1; }
        printf( "%d\n", result );
    }
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  int n,k;
  cin>>n>>k;

  vector<bool> ans(n,true);
  rep(i,k){
    int d;
    cin>>d;
    rep(j,d){
      int a;
      cin>>a;
      --a;
      ans[a]=false;
    }
  }

  int count=0;
  rep(i,n) if(ans[i]) count++;

  return count;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3632
/* A Rooted Trees */

#include<stdio.h>
#define NIL -1

int main(){
  int i, j;
  int n, id, k;
  int temp2;
  int d=0;

  scanf("%d",&n);

  int C[n][3];  /*C[n][0]=P, C[n][1]=L(left child), C[n][2]=R(right sibling)*/

  /* initialize C[n][3]*/
  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      C[i][j]=NIL;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    if(k>0){
      int temp[k];
      for(j=0;j<k;j++){
	if(j==0){
	  scanf("%d",&temp[0]);
	  C[id][1]=temp[0];
	  C[temp[0]][0]=id;
	}else{
	  scanf("%d",&temp[j]);
	  C[temp[j-1]][2]=temp[j];
	  C[temp[j]][0]=id;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",C[i][0]);

    /*search parent*/
    temp2=C[i][0];
    if(temp2!=NIL){
      while(1){
	if(C[temp2][0]==NIL){
	  d++;
	  break;
	}
	else{ 
	  temp2=C[temp2][0];
	  d++;
	}
      }
    }
    printf("depth = %d, ",d);
    d=0;
    
    if(C[i][0]==NIL){
      printf("root, [");
    }else if(C[i][1]==NIL){
      printf("leaf, []\n");
      continue;
    }else{
      printf("internal node, [");
    }

    /*search child*/
    if(C[i][1]!=NIL){
      temp2=C[i][1];
      if(C[temp2][2]!=NIL){
	printf("%d, ",C[i][1]);
      }else{
	printf("%d",C[i][1]);
      }
      while(1){
	if(C[temp2][2]!=NIL){
	  printf("%d",C[temp2][2]);
	  temp2=C[temp2][2];
	  if(C[temp2][2]!=NIL)printf(", ");
	}else break;
      }
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 1976
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;

    int main(){
      int n;
      cin>>n;
      auto c = vec(int,n-1);
      auto s = vec(int,n-1);
      auto f = vec(int,n-1);
      rep(i,n-1)cin>>c[i]>>s[i]>>f[i];
      rep(h,n-1){
          int ans = 0;
      rep(i,n-1){
          if(h>i)continue;
          int j = 0;
          while(1){
              if(ans <= s[i]+f[i]*j){
                  ans = s[i]+f[i]*j+c[i];
                  break;
              }
              j++;
          }
      }
      cout<<ans<<endl;
      }
      cout<<0<<endl;
    }


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if (x==0)return y;
      if(y==0)return x;
      if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

   
int main(){
int N;
cin >> N;
vector<int> C(N,0),S(N,0),F(N,0);
for(int i = 0; i < N-1;i++){
	cin >> C[i] >> S[i] >> F[i];
}
for(int i = 0; i < N; i++){
	long long t = S[i]+C[i];
	for(int j = i+1; j < N-1;j++){
		if(t<=S[j])t=S[j];
		else if((t-S[j])%F[j]==0);
		else{
			t += F[j]-((t-S[j])%F[j]);
			
		}
		t += C[j];
		}
		cout << t << endl;
	}

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;

        for (int i = 1; i <= 5; i++) {
            int k = sc.nextInt();

            if (k == 0) {
                ans = i;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 26924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll dpa[100007];
ll dpb[100007];
ll dpc[100007];

int main(){
  ll n;
  cin >> n;
  vi a(n+1);
  vi b(n+1);
  vi c(n+1);
  rep(i, n){
    cin >> a[i + 1] >> b[i + 1] >> c[i + 1];
  }
  dpa[1] = a[1];
  dpb[1] = b[1];
  dpc[1] = c[1];
  for (ll i = 2; i <= n;i++){
    dpa[i] = max(a[i] + dpb[i - 1], a[i] + dpc[i - 1]);
    dpb[i] = max(b[i] + dpa[i - 1], b[i] + dpc[i - 1]);
    dpc[i] = max(c[i] + dpa[i - 1], c[i] + dpb[i - 1]);
  }
  ll ans = max(dpa[n], max(dpb[n], dpc[n]));
  print(ans);
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;

int main()
{
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;

    ll ans = INF;

    ll sim = a*x + b*y;
    for(int i=1; i<=max(x, y); i++){
        ll sum = sim;
        if(i>x) sum -= x*a;
        else sum -= a*i;
        if(i>y) sum -= b*y;
        else sum -= b*i;
        sum += 2*c*i;
        
        ans = min(ans, sum);
    }
    ans = min(ans, sim);
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#define e 0.000000001
using namespace std;
int func(int,int,double,int);
int p,q,a,n;
double k;
 
int main(){
  while(1){
    cin>>p>>q>>a>>n;
    if(!p&&!q&&!a&&!n) break;
    k=1.0*p/q;
    cout<<func(0,1,0,1)<<endl;
  }
  return 0;
}
 
int func(int x,int w,double y,int I){
  int r=0;
  if(-e<=k-y&&k-y<=e) r++;
  if(x==n||y>k+e) return r;
  for(int i=I;w*i<=a;i++) r+=func(x+1,w*i,1.0/i+y,i);
  return r;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

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

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		for (Int j = i+1; j < N; j++) {
			ans += d[i] * d[j];
		}
	}

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


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

tmp = []
for i, a in enumerate(A, start=1):
    tmp.extend([i] * a)

ans = []
rev = 0

add = []
for i in range(1, H * W + 1):
    add.append(tmp[i-1])
    if i % W == 0:
        if rev:
            add = add[::-1]
        ans.append(add)
        rev = 1 - rev
        add = []

for a in ans:
    print(*a)


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

int main()
{
    string s;
    cin>>s;
    while(s.size()>0)
    {
        int n=s.size();
        if(n>=5&&(s.substr(n-5,5)=="dream"||s.substr(n-5,5)=="erase"))s.erase(n-5,5);
        else if(n>=7&&s.substr(n-7,7)=="dreamer")s.erase(n-7,7);
        else if(n>=6&&s.substr(n-6,6)=="eraser")s.erase(n-6,6);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n;
int main(){
	while(cin>>n){
		if(n==0)break;
		int s[110]={},ma=0,mi=1001,cn=0;
		for(int i=0;i<n;i++){
			cin>>s[i];
			if(s[i]>ma){
				ma=s[i];
			}
			if(s[i]<mi){
				mi=s[i];
			}
			cn+=s[i];
		}
		cout<<((cn-mi)-ma)/(n-2)<<endl;
	}
	return 0;
}

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

ll solve() {
    ll N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int>> p(26);
    for ( int i = 0; i < N; i++ ) {
        p[S[i]-'a'].insert(i);
    }
    ll T, I, L, R;
    char C;
    vector<ll> ans;
    for ( int q = 0; q < Q; q++ ) {
        cin >> T;
        if ( T == 1 ) {
            cin >> I >> C;
            I--;
            p[S[I]-'a'].erase(I);
            p[C-'a'].insert(I);
            S[I] = C;
        } else {
            cin >> L >> R;
            L--, R--;
            ll cnt = 0;
            for ( int i = 0; i < 26; i++ ) {
                if (p[i].lower_bound(L) != p[i].upper_bound(R) ) cnt++;
            }
            ans.push_back(cnt);
        }
    }
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 24708
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int h, w, k; cin >> h >> w >> k;
	char s[h][w]; rep(i,h)rep(j,w) cin >> s[i][j];
	int ans[h][w] = {};
	int cnt = 1;
	for(int y = 0; y < h; ++y) {
		bool flg = false;
		for(int x = 0; x < w; ++x) {
			if(s[y][x] == '#') flg = true;
		}
		if(flg) {
			for(int x = 0; x < w; ++x) {
				if(ans[y][x] > 0) continue;
				int tmp = 0;
				int sx = w;
				for(int dx = x; dx < w; ++dx) {
					if(s[y][dx] == '#') {
						++tmp;
					}
					if(tmp > 1) {
						sx = dx;
						break;
					}
				}
				for(int dx = x; dx < sx; ++dx) {
					ans[y][dx] = cnt;
				}
				++cnt;
			}
		} else {
			for(int x = 0; x < w; ++x) {
				if(y - 1 >= 0) ans[y][x] = ans[y - 1][x];
			}
		}
	}
	for(int y = h - 1; y >= 0; --y) {
		bool flg = false;
		for(int x = 0; x < w; ++x) {
			if(s[y][x] == '#') flg = true;
		}
		if(flg) {
			for(int x = 0; x < w; ++x) {
				if(ans[y][x] > 0) continue;
				int tmp = 0;
				int sx = w;
				for(int dx = x; dx < w; ++dx) {
					if(s[y][dx] == '#') {
						++tmp;
					}
					if(tmp > 1) {
						sx = dx;
						break;
					}
				}
				for(int dx = x; dx < sx; ++dx) {
					ans[y][dx] = cnt;
				}
				++cnt;
			}
		} else {
			for(int x = 0; x < w; ++x) {
				if(y + 1 < h) ans[y][x] = ans[y + 1][x];
			}
		}
	}
	rep(y,h){
		rep(x,w){
			cout << ans[y][x] << (x == w - 1 ? "\n" : " ");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
import sys
 
N, K, Q = [int(n) for n in sys.stdin.readline().strip().split()]
ans_idx = [int(sys.stdin.readline().strip()) for _ in range(Q)]
scores = [0]*N
 
for ai in ans_idx:
  scores[ai-1] += 1
scores = [K-(Q-s) for s in scores]
  
for s in scores:
  print('No' if s<=0 else 'Yes')

Measured memory_bytes: 11804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
   	
int main() {
	long double w, h, x, y;

	cin >> w >> h >> x >> y;

	if (x == (w/2) && y == (h/2))
	{
		cout << fixed << setprecision(9) << w*h/2 << " " << 1;
	}
	else
	{
		cout << fixed << setprecision(9) << w*h/2 << " " << 0;
	}

	return 0;
}



Measured memory_bytes: 256
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b = list(map(int, sys.stdin.readline().split()))
    if a < 10 and b < 10:
        print(a*b)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int n,x;
  cin>>n>>x;
  vector<int>m(n);
  rep(i,n)cin>>m[i];
  int sum=0;
  rep(i,n)sum+=m[i];
  int w=0;
  sort(m.begin(),m.end());
  int l=m[0];
  if(x-sum>0)
  cout <<n+(x-sum)/l<<endl;
  else cout<<n<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    int las = n %10;
    if(las == 2 || las == 4 ||las == 5 ||las == 7 ||las == 9)
        cout << "hon\n";
    else if (las == 0 || las == 1 ||las == 6 ||las == 8)
        cout << "pon\n";
    else if (las == 3)
        cout << "bon\n";
    return 0;
}


Measured memory_bytes: 3580
int main(){
int a;
int s,t;
 
scanf("%d%d%d",&a,&s,&t);
 
  for(int i = s; i<=t; i++){
    if(i%a == 0){
      printf("OK");
      return 0;
    }else if(i==t){
    	printf("NG");
      return 0;
    }
  } 
}

Measured memory_bytes: 1708
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, K;
    cin >> N >> K;

    VL A(N);
    REP(i, N) {
        cin >> A[i];
    }

    FOR(i, K, N) {
        if (A[i - K] < A[i]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

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

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<ll, ll>
#define nyan "(=^･ω･^=)"
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+10;
vector<int> adj[maxn];
int distA[maxn], distB[maxn], color[maxn];
int visited[maxn];
int a, b;

void dfs1(int u, int par) {
    distA[u] = distA[par] + 1;
    for(auto v : adj[u]) {
        if(v != par) dfs1(v, u);
    }
}

void dfs2(int u, int par) {
    distB[u] = distB[par] + 1;
    for(auto v : adj[u]) {
        if(v != par) dfs2(v, u);
    }
}

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

    for(int i = 1, x, y; i < n; i++) {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    dfs1(a, 0);
    
    queue<int> q;
    q.push(b); q.push(a);

    memset(color, -1, sizeof color);
    color[b] = 1; color[a] = 0;

    while(!q.empty()) {
        int u = q.front();
        q.pop();

        if(visited[u]) continue;
        visited[u] = 1;

        for(auto v : adj[u]) {
            if(color[v] == -1) color[v] = color[u];
            q.push(v);
        }
    }

    dfs2(b, 0); int mx = 0;
    for(int i = 1; i <= n; i++) {
        if(color[i]) mx = max(mx, distB[i]);
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(color[i])
            ans = max(ans, distA[i] - 2);
    }

    cout << ans << endl;

    return 0;   
}

Measured memory_bytes: 11136
'''
import sys
input=sys.stdin.readline
n,m,c = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
from math import ceil
from collections import defaultdict ,Counter
'''
n = int(input())
s = input()
res = 1
t = s[0]
for i in range(1,n):
    if s[i] != s[i-1]:
        res+=1
        t = s[i]
print(res)



Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define ll long long
#define PI acos(-1)
using namespace std;
const ll N = 1e5+100;
const ll MOD = 1e9+7;

ll n,m,T;
ll l[110];
int main()
{
	/*scanf("%d",&T);
	while(T--)
	{
	
	 } 
	 */
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&l[i]);
	}
	ll ans = 0;
	for(ll i=1;i<=n;i++)
	for(ll j=i+1;j<=n;j++)
	for(ll k=j+1;k<=n;k++)
	{
		ll a = l[i], b = l[j], c = l[k];
		if(a==b||b==c||a==c)	continue;
		if(a+b>c&&a+c>b&&b+c>a)	ans++;
		
	}	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3816
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int ans = max(0, c - (a - b));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long


signed main(void) {
  string S;
  cin >> S;
  int year = stoi(S.substr(0, 4));
  int month = stoi(S.substr(5, 2));
  string ans;
  if (year > 2019) {
    ans = "TBD";
  } else {
    if (year == 2019 && month > 4) {
      ans = "TBD";
    } else {
      ans = "Heisei";
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int n, m, a[100010];

int main() {
	scanf("%d", &n);
	for(int i = 0;i < n;i ++) 
		scanf("%d", &a[i]);
	sort(a, a + n);
	m = unique(a, a + n) - a;
	m -= !(m & 1);
	printf("%d", m);
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

struct node{int x,d;}p[maxn];
struct n2{int l,r,w;}t[maxn<<2];
int n,b[maxn],cnt,R[maxn],tot;
const int mod=998244353;
ll dp[maxn];

inline bool cmp(node a,node b){return a.x<b.x;}

inline void upd(int now){t[now].w=max(t[now<<1].w,t[now<<1|1].w);}

inline void build(int now,int l,int r)
{
	t[now].l=l; t[now].r=r;
	if(l==r) {t[now].w=l; return;}
	int mid=(l+r)>>1;
	build(now<<1,l,mid); build(now<<1|1,mid+1,r); upd(now);
}

inline void add(int now,int x,int w)
{
	t[now].w=max(t[now].w,w);
	if(t[now].l==x&&t[now].r==x) {t[now].w=w; return;}
	int mid=(t[now].l+t[now].r)>>1;
	if(x<=mid) add(now<<1,x,w); else add(now<<1|1,x,w);
}

inline int q(int now,int l,int r)
{
	if(t[now].l==l&&t[now].r==r) return t[now].w;
	int mid=(t[now].l+t[now].r)>>1;
	if(l>=mid+1) return q(now<<1|1,l,r);
	else if(r<=mid) return q(now<<1,l,r);
	return max(q(now<<1,l,mid),q(now<<1|1,mid+1,r));
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++) p[i].x=read(),p[i].d=read(),b[++cnt]=p[i].x;
	sort(p+1,p+n+1,cmp); build(1,1,n);
	sort(b+1,b+cnt+1); tot=unique(b+1,b+cnt+1)-b-1;
	for(int i=n;i>=1;i--)
	{
		int x=upper_bound(b+1,b+tot+1,p[i].x+p[i].d-1)-b-1;
		R[i]=q(1,i,x); add(1,i,R[i]); //cout<<R[i]<<endl;
	}
	dp[n+1]=1;
	for(int i=n;i>=1;i--) dp[i]=(dp[i+1]+dp[R[i]+1])%mod; cout<<dp[1]<<endl;
	return 0;
}

Measured memory_bytes: 12032
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
signed main() {
	ll n, a, b, c, cnt = 0, ans = 0;
	cin >> a >> b >> c;
	cnt = min(a, min(b, c)); ans = max(a, max(b, c));
	if (a % 2 != 0 && b % 2 != 0 && c % 2 != 0) {
		cout << cnt * (a + b + c - ans - cnt) << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	if (n == m)cout << "Yes" << endl;
	else {
		cout << "No" << endl;
	}
		return 0;
	
}

Measured memory_bytes: 3624
N = input()
a = raw_input().split()

even = []
odd = []

for i in range(N):
    if (i + 1) % 2 != 0:
        odd.append(a[i])
    else:
        even.append(a[i])

if N % 2 != 0:
    even.reverse()
else:
    odd.reverse()

ans = []
if N % 2 != 0:
    ans = even + odd
else:
    ans = odd + even

for i in range(N - 1):
    print ans.pop(),

print ans.pop()


Measured memory_bytes: 25076
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ n ] = readMany(1).map(it => parseInt(it))
    const a = readMany(n).map(it => parseInt(it)).sort((a, b) => a- b)

    const dp = []
    for (let i = 1; i <= a[n - 1]; i += 1) {
        dp[i] = false
    }

    for (const num of a) {
        for (let i = 2; num * i <= a[a.length - 1]; i += 1) {
            dp[i * num] = true
        }
    }

    let count = 0
    let duplicated = false
    for (let i = 0; i < n; i += 1) {
        const num = a[i]

        if (num == a[i + 1]) {
            duplicated = true
            continue
        }
        if (duplicated) {
            duplicated = false
            continue
        }

        if (!dp[num]) {
            count += 1
        }
    }

    console.log(count)
})()


Measured memory_bytes: 83312
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  while (true) {
    int joi = 0;
    int ioi = 0;
    cin >> s;
    if (cin.eof()) {
      return 0;
    }
    for (size_t i = 0; i < s.length(); ++i) {
      if (s.substr(i, 3) == "JOI") {
        ++joi;
      } else if (s.substr(i, 3) == "IOI") {
        ++ioi;
      }
    }
    cout << joi << endl << ioi << endl;
  }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	bool flg = true;
	if(s[2] != s[3]) flg = false;
	if(s[4] != s[5]) flg = false;
	if(flg){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b)
{ return (a<b ? (a=b)||1 : 0); }
int main(){
	string s,t; cin>>s>>t;
	int n=s.size(), m = t.size();
	vector<vector<pair<int,int>>> prev (n+1,vector<pair<int,int>>(m+1,{-1,-1}));
	vector<vector<int>> dp(n+1,vector<int>(m+1));
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(s.at(i-1)==t.at(j-1)) {
				dp.at(i).at(j) = dp.at(i-1).at(j-1)+1;
				prev.at(i).at(j) = {i-1,j-1};
			}
			else{
				if(chmax(dp.at(i).at(j), dp.at(i-1).at(j))) prev.at(i).at(j) = {i-1,j};
				if(chmax(dp.at(i).at(j), dp.at(i).at(j-1))) prev.at(i).at(j) = {i,j-1};

			} 
		}
	}
	int a = n,b = m;
	string ans;
	while(1){
		auto p = prev.at(a).at(b);
		if(p == make_pair(-1,-1)) break;
		if(p.first!=a&&p.second!=b) {
			ans += s.at(p.first);
		}
		a = p.first;
		b = p.second;
		
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}


Measured memory_bytes: 105984