akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

struct data_t {
    int w, v;
};

data_t I[101];

// 太郎君が持ち帰る品物の価値の総和の最大値
long V[101][100001];

int max(int X, int Y) {
    return X > Y ? X : Y;
}

int main() {
    int N, W; cin >> N >> W; // N <= 100, W <= 100000
    for (int i = 1; i <= N; ++i) {
        cin >> I[i].w;
        cin >> I[i].v;
    }

    for (int w = 0; w <= W; ++w) {
        V[0][w] = 0;
    }
    for (int i = 0; i <= N; ++i) {
        V[i][0] = 0;
    }
    for (int i = 1; i <= N; ++i) {
        for (int w = 0; w <= W; ++w) {
            if (w >= I[i].w) {
                V[i][w] = max(V[i - 1][w], V[i - 1][w - I[i].w] + I[i].v);
            } else {
                V[i][w] = V[i - 1][w];
            }
        }
    }

    // DEBUG
    // for (int i = 1; i <= N; ++i) {
    //     for (int w = 0; w <= W; ++w) {
    //         if (w == 0) {
    //             cout << V[i][w];
    //         } else {
    //             cout << " " << V[i][w];
    //         }
    //     }
    //     cout << endl;
    // }

    cout << V[N][W] << endl;

    return 0;
}


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

using ll = long long;
using P = pair<int, int>;

int main()
{
    int N;
    ll sum = 0, max = 0;
    ll A;
    cin >> N;
    rep(i, N)
    {
        cin >> A;
        if (i == 0)
        {
            max = A;
            continue;
        }
        if (max < A)
        {
            max = A;
        }
        else if (max > A)
        {
            sum += max - A;
        }
        // cout << "max: " << max << "\tsum: " << sum << endl;
    }
    cout << sum << endl;

    return 0;
}

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

int main(){
        int i,m,n,p,sum_gold,a_get;
        a_get=0;
        int a[100];
        for(i=0; i<100; i++) {
                a[i]=0;
        }

        while(1) {
                sum_gold=0;
                cin >> m >> n >> p;

                if((m==0)&&(n==0)&&(p==0)) {
                        break;
                }

                for(i=0; i<m; i++) {
                        cin >> a[i];
                        sum_gold+=a[i];
                }

                if(a[n-1]==0) {
                        cout << 0 << endl;
                }else{
                        sum_gold=sum_gold*100;

                        sum_gold=sum_gold*(100-p)/100;

                        a_get=sum_gold/a[n-1];

                        cout << a_get <<endl;
                }
        }
}



Measured memory_bytes: 3036
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{
    int x,y;
    long long z;
    bool operator<(const P &a)const{
        if(y!=a.y)
        return y>a.y;
        return z>a.z;
    }
};
vector<int> v[200056];
int a,b,c,n,m,i,k,o[310][3130],d,e,dy[5]={0,0,-1,1,0},dx[5]={-1,1,0,0,2};
int l[5100000];
long long x,y,z1[5000000],z2[5000000];
P u[100100];
int j[6000100];
queue<int> q;
stack<int> s;
priority_queue<P> q1,q2;
//long long x=0,y=0,z[99];

//deque<int> d;
//'1'==49;
map<int, P > p[2222];
//string r;
char r[1000];


void f(int t,int w)
{

    if(t*100+w>i) return;
    if(e*(t*100)<100*w) return;

    if(o[t][w]) return;
    //printf("@@%d %d\n",t,w);
    o[t][w]=1;
    if(w*(m*100+n)>(t*100+w)*n) n=w,m=t;
    f(t+a,w);
    f(t+b,w);
    f(t,w+c);
    f(t,w+d);
}

int main()
{
    scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&i);
    m=a;
    f(a,0);
    f(b,0);
    printf("%d %d",m*100+n,n);
}


Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)


typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;

#define ARRAY_MAX 100005

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


int main() {

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

	deque<int> que;

	if (n % 2)
	{
		for (int i = 0; i < n; i++)
		{
			if (i % 2)
			{
				que.push_back(a[i]);
			}
			else
			{
				que.push_front(a[i]);
			}
		}


	}
	else
	{

		for (int i = 0; i < n; i++)
		{
			if (i % 2)
			{
				que.push_front(a[i]);
			}
			else
			{
				que.push_back(a[i]);
			}
		}
		
	}
	int cnt = 0;
	for (auto itr : que)
	{
		if (cnt == 0)
		{
			cout << itr;
		}
		else 
		{
			cout << " " << itr;
		}
		cnt++;
	}
	cout << endl;
	
	return 0;
}

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

static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

int n,m[N][N];
int color[N],sta[N],fin[N],tt;
int nt[N];


int next(int u)
{
  for(int v=nt[u];v<n;v++)
  {
    nt[u]=v+1;
    if(m[u][v]) return v; //下に辺があれば返す
  }
  return -1;
}

void dfs_visit(int r)
{
  for(int i=0;i<n;i++) nt[i]=0;

  stack<int> s;
  s.push(r);
  color[r]=gray;
  sta[r]= ++tt;

  while(!s.empty()) //空じゃない間
  {
    int u=s.top();
    int v= next(u);
    if(v != -1)
    {
      if(color[v]==white)
      {
        color[v]=gray;
        sta[v]= ++tt;
        s.push(v);
      }
    }
    else //v=-1
    {
      s.pop();
      color[u]=black;
      fin[u]= ++tt;
    }
  }
}

void dfs()
{
  //初期化
  for(int i=0;i<n;i++)
  {
    color[i]=white;
    nt[i]=0;
  }
  tt=0;

  //未訪問のuを始点としてdfsする
  for(int u=0;u<n;u++)
  {
    if(color[u]==white) dfs_visit(u);
  }
  for(int i=0;i<n;i++)
  {
    cout<<i+1<<" "<<sta[i]<<" "<<fin[i]<<endl;
  }
}

int main()
{
  //入力
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++) m[i][j]=0;
  }
  for(int i=0;i<n;i++)
  {
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++)
    {
      cin>>v;
      v--;
      m[u][v]=1; //辺があれば1と定義される
    }
  }

  dfs();
}


Measured memory_bytes: 3184
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define UMLL unordered_map<ll,ll>
#define UMII unordered_map<int,int>
#define VI vector<int>
#define VL vector<ll>
#define S second
#define F first
#define PB push_back


int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

        
    int x;
    cin>>x;
    if(x<600)
        cout << "8";
    else if(x<800)
        cout << "7";
    else if(x<1000)
        cout << "6";
    else if(x<1200)
        cout << "5";
    else if(x<1400)
        cout << "4";
    else if(x<1600)
        cout << "3";
    else if(x<1800)
        cout << "2";
    else if(x<2000)
        cout << "1";

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  short int N,sum=1;
  cin >> N;
  vector<short int> d(N);
  short int i;
  for(i=0;i<N;++i)
    cin >> d.at(i);
  sort(d.begin(), d.end(), greater<int>());
  for(i=0;i<N;++i){
    if(i<(N-1))
      if(d.at(i)!=d.at(i+1))
        ++sum;
  }
  cout << sum << endl;
}


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

typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    if(n>1&&m>1){
        cout<<(n-2)*(m-2);
    }
    else{
        if(n==1&&m==1){
            cout<<"1";
            return 0;
        }
        if(n==1){
            cout<<m-2;
            return 0;
        }
        if(m==1){
            cout<<n-2;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double dis = sc.nextDouble();
    double min = sc.nextDouble();
    double speed = sc.nextDouble();
    if(dis / speed <= min){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

    

Measured memory_bytes: 37364
N = int(input())
mn=10**8
for A in range(1,N):
    B=N-A
    sm=0
    while A!=0:
        sm+=A%10
        A//=10
    while B!=0:
        sm+=B%10
        B//=10
    if mn>sm:
        mn=sm
print(mn)

Measured memory_bytes: 9040
def make_cyclic(w, v):
    flags = [True] * len(w)

    cyclics = []
    for i in range(len(w)):
        if flags[i]:
            flags[i] = False
            cycle = [w[i]]
            now = w[i]
            while True:
                j = v.index(now)
                if j == i:
                    break
                cycle.append(w[j])
                now = w[j]
                flags[j] = False
            cyclics.append(cycle)

    return cyclics


def min_cost_sort(w):
    v = w.copy()
    v.sort()

    cyclics = make_cyclic(w, v)

    ans = 0
    for cycle in cyclics:
        inner_cycle = min(cycle) * (len(cycle) - 2) + sum(cycle)
        if len(set(w) - set(cycle)) >= 1:
            outer_cycle = min(cycle) + min(set(w) - set(cycle)) * (len(cycle) + 1) + sum(cycle)
        else:
            outer_cycle = inner_cycle + 1
        ans += min(inner_cycle, outer_cycle)

    return ans


n = int(input())
w = [int(x) for x in input().split()]

print(min_cost_sort(w))


Measured memory_bytes: 5800
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e6;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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


map<int,int> cnt;


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;

    for(int cs=1; cs<=test; ++cs) {
        ll n,num,ans=0;
        cin>>n;
        int sqrtn=sqrt(n);
        num=n;
        for(ll i=2; i<=sqrtn; ++i) {
            if(num%i==0) {
                while(num%i==0) {
                    num/=i;
                    cnt[i]++;
                }
            }
        }
        for(auto x:cnt) {
            int ct=x.second,sb=1;
            while(ct>=sb) {
                ans++;
                ct-=sb;
                ++sb;
            }
        }
        if(num!=1ll) {
            cout<<ans+1<<endl;
        } else {
            cout<<ans<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
		a[i] *= -1;
	}
	V dp(n + 1, 1);
	rep(i, n) {
		*upper_bound(all(dp), a[i]) = a[i];
	}
	int len = lower_bound(all(dp), 1) - dp.begin();
	cout << len << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int k,n;
    cin>>k>>n;
    int sat=0;
    int mx=0;
    int sum=0;
    int b=0;
    int flag=1;
    while(n--)
    {
        int a;
        cin>>a;
        if(a!=0&&flag)
        b=a;
        mx=max(mx,a-sat);
        sat=a;
        flag=0;
    }
    if(b!=0)
    mx=max(mx,k-sat+b);
    mx=max(mx,k-sat);
    cout<<k-mx;
    return 0;
}

Measured memory_bytes: 256
number = int(input())
price = []
for i in range(number):
	price.append(input().split(" "))
jpy = 0
btc = 0
for i,j in price:
	if j == "JPY":
		jpy += float(i)
	else:
		btc += float(i)
print(jpy + btc*380000)

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i,n) cin >> a[i];
  int cnt = 1;
  rep(i,n){
    if(a[i] == cnt){
      cnt++;
    }
  }
  if(cnt == 1){
    cout << -1 << "\n";
  }else{
    cout << (n-cnt)+1 << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[30];
    for(int i=1;i<=n;i++) cin>>a[i];
    int t=a[1],m=1;
    for(int i=2;i<=n;i++){
        if(a[i]>=t){
            t=a[i];
            m++;
        }
    }
    cout<<m<<endl;
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  pair<int, int> red[n], blue[n];

  for (int i=0; i<n; i++) {
    cin>>red[i].first>>red[i].second;
  }
  for (int i=0; i<n; i++) {
    cin>>blue[i].first>>blue[i].second;
  }

  sort(red, red + n);
  sort(blue, blue + n);

  int cnt = 0;
  int used[n];
  for (int i=0; i<n; i++) used[i] = 0;
  for (int i=0; i<n; i++) {
    auto it = lower_bound(red, red + n, make_pair(blue[i].first, 0));
    if (it == red) {
      continue;
    }
    --it;
    int max_d = -1;
    int idx_max_d = -1;
    while (true) {
      int j = it - red;
      if ((*it).second < blue[i].second
          && used[j] == 0
          && (*it).second > max_d) {
        max_d = (*it).second;
        idx_max_d = it - red;
      }

      if (it == red) {
        break;
      } else {
        --it;
      }
    }
    if (idx_max_d != -1) {
      used[idx_max_d] = 1;
      ++cnt;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var ans = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] != t[i]) ans++;
        }

        // 出力
        Console.WriteLine(ans);
    }
}

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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long

#define MAX 10000

//-----????¨????-----

//?????????????????±
struct Node { 
	int key;
	Node *left, *right,*parent;
};


//-----?????°??£?¨?-----

Node *root, *NIL;

//-----??¢??°??£?¨?-----
void insert(int k) {

	//?????°??£?¨?
	Node *y=NIL;   //????????¨????????????????????????
	Node *x=root;  //??¢?´¢??????????????????
	Node *z;       //?????\????????????

	//z??????????¨????
	z=(Node*)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;

	//?????????????????????????????§???????????????????????¢????????¨???????????????
	while (x != NIL) {
		y=x;
		if (z->key < x->key) {
			x=x->left;
		}
		else {
			x=x->right;
		}
	}
	//???????¢????
	z->parent=y;

	//???????????????????¢?????????????
	if (y == NIL) {
		root=z;
	}
	else {
		if (z->key < y->key) y->left  = z;
		else                 y->right = z;
	}
}

//???????????????
void inorder(Node *u) {
	if(u==NIL) return;
	inorder(u->left);
	cout<<" "<<u->key;
	inorder(u->right);
}

//???????????????
void preorder(Node *u) {
	if(u==NIL)return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

//???????????¢??°
int main() {
	int n,x;
	string com;

	//??\???
	cin>>n;
	REP(i, n) {
		cin>>com;
		if (com == "insert") {
			cin>>x;
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 26620
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << fixed << setprecision(10);
    long double a, b, c;
    cin >> a >> b >> c;
    if(c < a + b)
    {
        cout << "No" << endl;
        return 0;
    }
    // LL left = 2 * sqrt(a * b);
    // LL right = c - a - b;
    if(a * b < (c-a-b) * (c-a-b) / 4)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
template<typename T>inline T read(){
    reg T x=0;reg short f=1;reg char c=getchar();
    for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());
    for(;isdigit(c);x=x*10+(c^48),c=getchar());
    return x*f;
}
const int maxn=1e5+5;
int n;
ll a[maxn],s[maxn],sum;
int main(){
	n=read<int>();for(reg int i=1;i<=n;i++)sum+=(a[i]=read<int>());a[0]=a[n];
	if(sum%(1ll*n*(n+1)/2))return 0*puts("NO");reg int cnt=sum/(1ll*n*(n+1)/2);
	for(reg int i=1;i<=n;i++)s[i]=a[i-1]-a[i]+cnt;
	for(reg int i=1;i<=n;i++)if(s[i]<0||s[i]%n)return 0*puts("NO");
	return 0*puts("YES");
}

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

using namespace std;

int K, S;

void solve() {
    int num = 0;
    for (int x = 0; x <= K; ++x) {
        for (int y = 0; y <= K; ++y) {
            if (S - x - y >= 0 && S - x - y <= K) {
                num++;
            }
        }
    }
    printf("%d\n", num);
}

int main() {
    cin >> K >> S;
    solve();
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		String[] ss = new String[3];
		int[] beg = new int[3];
		int[] sz = new int[3];

		Arrays.fill(beg, 0);
		for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		}

		int cur = 0;

		while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		}

		char ans = (char)(cur + 'A');
		
		out.println(ans);
	}

	private int getId(char ch) {
		return ch - 'a';
	}
}


class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

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

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

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

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


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

using namespace std;

int main(void) {
    long N;
    cin >> N;

    long long cnt = 0;
    for (long i = 1; i<=N; i++) {
        if ((i % 3)== 0) continue;
        if ((i % 5)== 0) continue;
        cnt+= i;
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n;
int l[MAXN], r[MAXN];
vector< pair<int, int> > v;
int ans = 0;
int mnEnd = 1e9;
set < pair<int, int> > r1, l2, r2;
int mxL, mnR;

int main() { 

  scanf("%d", &n);

  mxL = 0; mnR = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
    ans = max(ans, r[i] - l[i] + 1);
    mnEnd = min(mnEnd, r[i]);
    l2.insert({l[i], i});
    r2.insert({r[i], i});
    if (l[i] > l[mxL]) {
      mxL = i;
    }
    if (r[i] < r[mnR]) {
      mnR = i;
    }
  }

  int mxLen = 0;
  for (int i = 0; i < n; i++) {
    if (i != mxL && i != mnR) {
      mxLen = max(mxLen, r[i] - l[i] + 1);
    }
  }
  // cerr << mxLen << " " << mnR << " " << mxL << endl;
  ans = max(ans, mxLen + max(0, r[mnR] - l[mxL] + 1));

  for (int i = 0; i < n; i++) {
    v.push_back({l[i], i});
  }
  sort(all(v));

  for (int i = 0; i < n; i++) {
    int idx = v[i].second;
    int from = v[i].first, to = r[idx];
    if (from > mnEnd) {
      break;
    }

    r1.insert({to, idx});
    l2.erase({from, idx});
    r2.erase({to, idx});

    if (sz(l2) > 0) {
      int cur = r1.begin()->first - from + 1;
      int mxL = l2.rbegin()->first;
      int mnR = r2.begin()->first;  
      cur += max(0, mnR - mxL + 1);
      ans = max(ans, cur);
      //cerr << "upd " << idx << " " << cur << endl;
      //cerr << r1.begin()->first - from + 1 << " " << mnR - mxL + 1 << endl;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11516
using System;
using System.Linq;

namespace agc083_c
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long x = inputLongArray[0];
            long y = inputLongArray[1];
            long cnt = 0;
            while (x <= y)
            {
                x *= 2;
                cnt++;
            }

            Console.WriteLine(cnt);
        }
    }
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if(a+b-n>=0) {
    cout << min(a, b) << ' ' << (a+b)-n << endl;
  }
  else {
    cout << min(a, b) << ' ' << 0 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
int main(void)
{
	int n,m,w[50]={0},b[50]={0},r[50]={0},i,j,min=INT_MAX;
	char s[50];
	scanf("%d %d", &n, &m);
	for(i=0; i<n; i++)
	{
		scanf("%s", s);
		for(j=0; j<m; j++)
		{
			if(s[j]!='W')
			w[i]++;
			if(s[j]!='B')
			b[i]++;
			if(s[j]!='R')
			r[i]++;
		}
		if(i>0)
		{
			w[i]+=w[i-1];
			b[i]+=b[i-1];
			r[i]+=r[i-1];
		}
	}
	for(i=0; i<n-2; i++)
	{
		for(j=i+1; j<n-1; j++)
		{
			if(w[i]+b[j]-b[i]+r[n-1]-r[j]<min)
			min=w[i]+b[j]-b[i]+r[n-1]-r[j];
		}
	}
	printf("%d\n", min);
	
	return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int32_t main(){
    int x,h;
    cin>>x;
    h=h+(x/500)*1000;
    x=x-((x/500)*500);
    h=h+(x/5)*5;
    cout<<h;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn dfs(n: i64, v: i64, occ: i32) -> i64 {
    let mut ans = 0;
    if v > n {
        return ans;
    }
    if occ == 7 {
        ans += 1;
    }
    for (i, &u) in [3, 5, 7].iter().enumerate() {
        ans += dfs(n, 10 * v + u, occ | 1 << i);
    }
    ans
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(n: i64);
    puts!("{}\n", dfs(n, 0, 0));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
  ll n, h, max_a = 0;
  cin >> n >> h;
  vll a(n), b(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (max_a < a[i]) max_a = a[i];
  }
  
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  ll cnt = 0;
  for (ll i = 0; i <= n; i++) {
    if (b[i] > max_a) {
      h -= b[i];
      cnt++;
    }
    else {
      cnt += (h + max_a - 1) / max_a;
      break;
    }
    if (h <= 0) break;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 1792
/*
  AUTHOR:SOURABH
  CREATED:25:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,x,r,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>x;
        ans=(x/500)*1000;
        r=x%500;
        ans+=(r/5)*5;
        cout<<ans;
    }
    return 0;
}







Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions,time
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
if s[0] != s[1] or s[1] != s[2]:
    print('Yes')
else: print('No')

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

int main(){
    int N;
    int64_t K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i], A[i]--;

    vector<int> dist(N, 1e9);
    dist[0] = 0;
    int pos = 0, cnt = 0;
    while(K > 0){
        cnt++;
        K--;
        pos = A[pos];
        if(dist[pos] == 1e9){
            dist[pos] = cnt;
        }else{
            int period = cnt - dist[pos];
            K %= period;
        }
    }
    cout << pos+1 << endl;
    return 0;
}


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

int main() {
    int h, w;
    char a[110][110];
    int comp_h[110] = {};
    int comp_w[110] = {};

    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) cin >> a[i][j];
    }

    int ii = 0;
    for (int i = 0; i < h; i++) {
        bool comp_i = true;
        for (int j = 0; j < w; j++) {
            if (a[i][j] == '#') comp_i = false;
        }
        if (!comp_i) {
            comp_h[ii] = i;
            ii++;
        }
    }

    int jj = 0;
    for (int j = 0; j < w; j++) {
        bool comp_j = true;
        for (int i = 0; i < h; i++) {
            if (a[i][j] == '#') comp_j = false;
        }
        if (!comp_j) {
            comp_w[jj] = j;
            jj++;
        }
    }

    for(int i = 0; i < ii; i++) {
        for (int j = 0; j < jj; j++) {
            cout << a[comp_h[i]][comp_w[j]];
        }
        cout << endl;
    }

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,K;
  cin >> N >> K;
  vector<double> p(N),s(N+1);
  rep(i,N) {
    cin >> p[i];
    s[i+1]=s[i]+(p[i]+1)/2.0;
  }
  
  double ans=0;
  rep(i,N-K+1) ans=max(ans,s[i+K]-s[i]);
  
  cout << fixed << setprecision(10) << ans << endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

struct UnionFind {
    vi v;
    UnionFind(int n=0) : v(n, -1) {}
    int find(int x) {
        if (v[x] < 0) return x;
        return (v[x] = find(v[x]));
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (x > y) swap(x, y);
        v[x] += v[y];
        v[y] = x;
        return true;
    }
    int size(int x) {
        return abs(v[find(x)]);
    }
    bool same(int x, int y) {
        if (find(x) == find(y)) return true;
        else return false;
    }
};

int d[100001];
int blk[100001];

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        d[a]++; d[b]++;
        uf.unite(a, b);
    }
    rep(i, k) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (uf.same(a, b)) {
            blk[a]++; blk[b]++;
        }
    }
    rep(i, n) {
        int ans;
        ans = uf.size(i) - 1 - d[i] - blk[i];
        printf("%d%c", ans, i==n-1?'\n':' ');
    }
    return 0;
}



Measured memory_bytes: 2048
n,h=map(int,input().split())
x=[0]*n
y=0
for i in range(n):
    a,b=map(int,input().split())
    y=max(y,a)
    x[i]=b
cnt=0
x.sort(reverse=1)
for i in x:
    if i>y:
        cnt+=1
        h-=i
    if h<=0:
        print(cnt)
        exit()
print(cnt+(h+y-1)//y)

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


int main() {
    int n,a;
    cin >> n;
    int max_el=0,imax_el=0,ind=0;
    for (int i=0;i<n;i++) {
        cin >> a;
        if (a>max_el) {
            imax_el=max_el;
            max_el=a;
            ind=i;
        } else if (a>imax_el) imax_el=a;
    }
    for (int i=0;i<n;i++) {
        if (i!=ind) cout << max_el;
        else cout << imax_el;
        cout << endl;
    }
}

Measured memory_bytes: 1664
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    boolean han=true;
    int a=sc.nextInt();
    int b=sc.nextInt();
    char[] s=sc.next().toCharArray();
    for(int i=0;i<a;i++)
      if(s[i]=='-') {
        System.out.println("No");
        han=false;
        if(han==false)break;
      }
    if(han==true)
      if(s[a]!='-') {
        System.out.println("No");
        han=false;
      }
    if(han==true)
      for(int i=a+1;i<a+b+1;i++)
        if(s[i]=='-') {
          System.out.println("No");
          han=false;
          if(han==false)break;
        }
    if(han==true) System.out.println("Yes");
  }
}

Measured memory_bytes: 22100
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, M, H[(int)1e5], A[(int)1e5], B[(int)1e5];
    intmax_t good[(int)1e5], ans = 0;

    scanf("%jd%jd", &N, &M);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &H[i]);
        good[i] = true;
    }
    for (size_t i = 0; i < M; i++) {
        scanf("%jd%jd", &A[i], &B[i]);
    }

    for (size_t i = 0; i < M; i++) {
        if (H[A[i] - 1] < H[B[i] - 1])
            good[A[i] - 1] = false;
        else if (H[A[i] - 1] == H[B[i] - 1])
            good[A[i] - 1] = good[B[i] - 1] = false;
        else
            good[B[i] - 1] = false;
    }

    for (size_t i = 0; i < N; i++) {
        if (good[i])
            ans++;
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 5264
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, a, b;
	cin >> n >> a;
	for (int i = 0; i < 4; i++) { cin >> b; a = min(a, b); }
	cout << (n + a - 1) / a + 4 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MaxN = 100005;

int v[MaxN];

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

  int currSgn = 0;
  int ans = 0;
  for (int i = 2; i <= n; ++i) {
    if (currSgn == 0 and v[i] < v[i - 1]) {
      currSgn = -1;
    }
    else if (currSgn == 0 and v[i] > v[i - 1]) {
      currSgn = 1;
    }
    else if (currSgn == 1 and v[i] < v[i - 1]) {
      ++ans;
      currSgn = 0;
    }
    else if (currSgn == -1 and v[i] > v[i - 1]) {
      ++ans;
      currSgn = 0;
    }
  }

  cout << ans + 1 << '\n';
  return 0;
}

Measured memory_bytes: 640
//Digit Number
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		while (true) {

			String tmp = in.readLine();
			if (tmp == null) {
				break;
			}
			String[] ab = tmp.split(" ");

			int a = Integer.parseInt(ab[0]);
			int b = Integer.parseInt(ab[1]);

			// String out =Integer.toString(a+b);
			// System.out.println(out.length());
			//

			int i = 0;
			while (true) {
				i++;
				if (Math.pow(10, i) > a + b) {
					break;
				}
			}
			System.out.println(i);

		}

		// Scanner scan = new Scanner(System.in);
		//
		// while(scan.hasNext()){
		//
		// String[] ab = scan.next().split(" ");
		//
		// int a = Integer.parseInt(ab[0]);
		// int b = Integer.parseInt(ab[1]);
		//
		//// String out =Integer.toString(a+b);
		//// System.out.println(out.length());
		////
		//
		// int i=0;
		// while(true){
		// i++;
		// if(Math.pow(10, i)>a+b){
		// break;
		// }
		// }
		// System.out.println(i);
		//
		// }
		// scan.close();
	}
}

Measured memory_bytes: 16992
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    if n == 0:
        return 1
    r = 0
    while n > 0:
        r += 1
        n //= k

    return r


print(main())





Measured memory_bytes: 5444
#include <iostream>
//#define int long long
//#define _DEBUG
using namespace std;
int T[107][107];
signed main(){
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            T[i][j] = 0;
        }
    }
    for(int i=0; i<N; i++){
        int i_, k;
        cin >> i_ >> k;
        for(int l=0; l<k; l++){
            int v;
            cin >> v;
            T[i][v-1] = 1;
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(j<N-1) cout << T[i][j] << " ";
            else cout << T[i][j] << endl;
        }
    }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=200100;

const ll mod=998244353;
struct node
{
    ll sum=0;
    ll now;
    bool zr,one;
};

node Tree[10][sz*4];
ll n;
ll pr[sz];

void push(ll id,ll pos,ll nex,ll val)
{
     Tree[id][nex].now=(Tree[id][nex].sum * val)%mod;
     Tree[id][nex].one=Tree[id][nex].zr=false;
     
     if(val==0) Tree[id][nex].zr=true;
     else Tree[id][nex].one=true;
     return ;
}

void init()
{
    pr[n]=1;
    for(ll i=n-1;i>=1;i--){
        pr[i]=(pr[i+1] * 10)%mod;
    }
}

void fun(ll id, ll l,ll r,ll pos)
{
    if(l==r){
        Tree[id][pos].sum=(id * pr[l])%mod;
        Tree[id][pos].zr=Tree[id][pos].one=false;
        Tree[id][pos].now=0;
        return ;
    }

    ll mid=(l+r)/2ll;
    ll lc=pos*2+1;
    ll rc=lc+1;
    fun(id,l,mid,lc),  fun(id,mid+1,r,rc);
    Tree[id][pos].sum=(Tree[id][lc].sum + Tree[id][rc].sum)%mod;
}

void update(ll id,ll l,ll r,ll p,ll q,ll val,ll pos)
{
    if(r<p || q<l) return ;
    else if(p<=l && r<=q)
    {
        Tree[id][pos].one=Tree[id][pos].zr=false;
        Tree[id][pos].now=(val * Tree[id][pos].sum)%mod;
        if(val==0) Tree[id][pos].zr=true;
        else Tree[id][pos].one=true;
        return ;
    }

    ll mid=(l+r)/2ll;
    ll lc=pos*2+1;
    ll rc=lc+1;
    
    if(Tree[id][pos].one==true){
        push(id,pos,lc,1), push(id,pos,rc,1);
    }
    else if(Tree[id][pos].zr==true){
        push(id,pos,lc,0), push(id,pos,rc,0);
    }

    Tree[id][pos].one=Tree[id][pos].zr=false;
    
    update(id,l,mid,p,q,val,lc);
    update(id,mid+1,r,p,q,val,rc);

    Tree[id][pos].now=(Tree[id][lc].now+Tree[id][rc].now)%mod;

}



int main()
{
    Go_
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    

    cin>>n>>m;
    init();

    for(int i=1;i<=9;i++) fun(i,1,n,0);

    update(1,1,n,1,n,1,0);

    while(m--)
    {
        cin>>p>>q>>x;
        for(int i=1;i<=9;i++) update(i,1,n,p,q,0,0);
        update(x,1,n,p,q,1,0);
        
        ll sum=0;
        for(int i=1;i<=9;i++){
            sum=(sum + Tree[i][0].now)%mod;
        }

        cout<<sum<<'\n';
    }
    
}

Measured memory_bytes: 192804
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<map>
using namespace std;
#define f(n) for(int i=0;i<n;++i)
#define ll long long

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int mod_pow(int x, int pow) {
    if(pow == 0) return 1;
    int a = mod_pow(x, pow / 2);
    a = a * a % MOD;
    if(pow % 2 == 1) a *= x;
    return a % MOD;
}

int mod_div(int a, int b) {
    return a * mod_pow(b, MOD - 2) % MOD;
}

vector<int> fact;

void init_fact(int n) {
    fact = vector<int>(n);
    fact[0] = 1;
    for(int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
}

int calc_comb(int n, int r) {
    if(n < r) return 0;
    return mod_div(fact[n], fact[r] * fact[n - r] % MOD);
}

signed main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int s;
    cin >> s;
    if(s < 3) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    init_fact(s+10);

    for(int i = 2; i * 3 <= s; i++) {
        int now = s - i*3;
        ans += calc_comb(now+i-1, i-1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n';

const int N=1e5+7;

void solve(){
	int n; cin>>n;
	vector<int> a(n),b(n);
	for(int i=0 ; i<n ; i++){
		cin>>a[i]>>b[i];
	}
	sort(all(a)); sort(all(b));
	int ans=0;
	if(n&1){
		ans=abs(b[sz(b)/2]-a[sz(a)/2])+1;
	}
	else{
		int just=0;
		ld x=(b[sz(b)/2-1]+b[sz(b)/2])/2.0;
		if(x==(int)x){
		}
		else{
			just++;
		}
		ans=x;
		x=(a[sz(a)/2-1]+a[sz(a)/2])/2.0;
		if(x==(int)x){
			just++;
		}
		ans=abs(ans-(int)x)*2;
		ans+=just;
	}
	cout<<ans;LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cout<<setprecision(2);
  int _=1; //cin>>_;
  for(int i=1 ; i<=_ ; i++) solve();
  return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> table(H,(vector<char>(W)));
  vector<vector<int>> ans(H,(vector<int>(W)));
  
  for(int i = 0; i < H; i++){
    string str;
    cin >> str;  
    for(int j = 0; j < W; j++){
      table.at(i).at(j) = str.at(j);
    }
  }
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(table.at(i).at(j) == '#'){
        ans.at(i).at(j) = -1;
      }
      else{
        int c = 0;
        for(int k = 0; k <= 8; k++){
          if(k == 4){
            continue;
          }
          else{
            if(i-1+k/3 < 0 || H <= i-1+k/3 || j-1+k%3 < 0 || W <= j-1+k%3){
              continue;
            }
            else if(table.at(i-1+k/3).at(j-1+k%3) == '#'){
              c++;
            }
          }
        }
        ans.at(i).at(j) = c;
      }
    }
  }
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(ans.at(i).at(j) == -1){
        cout << '#';
      }
      else{
        cout << ans.at(i).at(j);
      }
      if(j == W-1){
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 256