akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define FOR2(i,a,b) for (int i=(a);i<(b);i++)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define ROF2(i,x,y) for(int i = (y) ; i >= (x) ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define FAST ios_base::sync_with_stdio(false); cin.tie(0)

template<class T,class U>
ostream &operator<<(ostream &os,const pair<T,U> &x) {
    return os<<"("<<x.first<<","<<x.second<<")";
}

template<class T>
ostream &operator<<(ostream &os,const vector<T> &x) {
    os << '[';
    if ( !x.empty() ) {
        std::copy (x.begin(), x.end(), std::ostream_iterator<T>(os, ","));
        os << "\b";
    }
    os << "]";
    return os;
}
template<class T>
ostream &operator<<(ostream &os,const vector<vector<T> > &x) {
    os << '[';
    if ( !x.empty() ) {
        os << x[0];
        for (int i=1;i<x.size();i++) os << endl << " " << x[i];
    } else os << "[]";
    os << "]";
    return os;
}

int main() {
    FAST;
    //freopen ("in.txt", "r", stdin);
    int n,m;cin>>n>>m;

    vii p(m);
    FOR(i,m){
        cin>>p[i].first>>p[i].second;
        if (p[i].first>p[i].second) swap(p[i].first,p[i].second);
    }
    sort(p.begin(),p.end());
    int fin=p[0].second;
    int cnt=1;
    FOR2(i,1,m){
        if (fin<=p[i].first){
            cnt++;
            fin=p[i].second;
        }else {
            fin = min(fin, p[i].second);
        }
    }
    cout << cnt;
    return 0;
}



Measured memory_bytes: 1024
import itertools
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    S = [list(input()[:-1]) for _ in range(H)]

    C = [['0']*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j]=='#':
                C[i][j] = '#'
                for op in itertools.product([-1, 0, +1], repeat=2):
                    ni = i + op[0]
                    nj = j + op[1]
                    if ni>=0 and ni<H and nj>=0 and nj<W and S[ni][nj]!='#':
                        C[ni][nj] = str(int(C[ni][nj]) + 1)
    
    for i in range(H):
        print(''.join(C[i]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 #define MAX 1000000000005
 #define ll long long int
 int main()
 {    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        long long int m,sum=0,k=0,i,d=0,j,sum1=0,sum2=0,sum3=0,l,kk,sum4=0,sum5=0,sum6=0,c=0,x,y,q;
         ll n;
           cin>>n;
          ll a[n],b[1000000]={0};
           for(i=0;i<n;i++)
             {cin>>a[i];
              b[a[i]]++;
              sum+=a[i];
             }
          cin>>q;
           while(q--){
            cin>>x>>y;
             c=b[x];
             d=b[y];
             sum-=x*b[x];
             sum+=y*b[x];
              cout<<sum<<endl;
              b[y]+=b[x];
              b[x]=0;


           }
    }




Measured memory_bytes: 12204
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    }
}


Measured memory_bytes: 21588
#include <stdio.h>

int main(void) {
	// your code goes here
	int a,b,c,d,i,j,x,y,z;
	scanf("%d %d",&a,&b);
	if (a>b) c=a-1;
	if (a<=b) c=a;
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret),greater<int>());
  return (ret);
}

signed main(){
  int n;cin>>n;n--;
  cout << n * (n+1) / 2 << endl;
}


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

int main(){
int K,S;cin>>K>>S;
int cnt=0;
for(int i=0;i<=K;++i){
  for(int j=0;j<=K;++j){
    if(S-i-j<=K&&S-i-j>=0){
      cnt++;
    }
  }
  }
cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  long long a;
  double b;
  cin >> a >> b;
  if(a==0 || b==0){
    cout << 0 << endl;
    return 0;
  }
  long long num=b*100+0.99;
  long long ans=num*a;
  ans/=100;
  cout << ans << endl;
}


Measured memory_bytes: 3728
#include <iostream>

using namespace std;

int main ()
{
	int n,m,a[21][21];
	cin >> n >> m;

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

	int co[21],gg = 0;

	for (int i = 0; i < n; i++)
	{
		co[i] = 0;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][j] == 1)
			{
				co[i] += 1;
			}
		}
		if (co[i] > gg)
		{
			gg = 0;
			gg = co[i];
		}
	}

	cout << gg << endl;
}


Measured memory_bytes: 3116
//#pragma GCC diagnostic error "-std=c++11"
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

int a[maxn], b[maxn];

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		if(i & 1) a[x]++;
		else b[x]++;
	}
	int Max1 = -1, Max2 = -1;
	int val1, val2;
	for(int i = 1; i <= maxn; i++){
		if(a[i] > Max1) val1 = i;
		if(b[i] > Max2) val2 = i;
		Max1 = max(Max1, a[i]);
		Max2 = max(Max2, b[i]);
	}
	int ans;
	if(val1 != val2){
		ans = n - Max1 - Max2;
		return 0 * printf("%d\n", ans);
	}
	int cnt1 = 0, cnt2 = 0;
	for(int i = 1; i <= maxn; i++){
		if(a[i] == Max1) cnt1++;
		if(b[i] == Max2) cnt2++;
	}
	if(cnt1 > 1 || cnt2 > 1){
		ans = n - Max1 - Max2;
		return 0 * printf("%d\n", ans);
	}
	cnt1 = cnt2 = 0;
	for(int i = 1; i <= maxn; i++){
		if(i != val1)
			cnt1 = max(cnt1, a[i]);
		if(i != val2)
			cnt2 = max(cnt2, b[i]);
	}
	ans = n - max(cnt1 + Max2, cnt2 + Max1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

//Reverse a Road
public class Main{

	class E{
		int id, t;
		public E(int id, int t) {
			this.id = id;
			this.t = t;
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		int INF = 1<<29;
		int[] o = new int[1001], d = new int[1001];
		int[][] e = new int[10001][2];
		List<E>[] adj = new List[1001];
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			for(int i=1;i<=n;i++)adj[i]=new ArrayList<E>();
			int S = sc.nextInt(), T = sc.nextInt(), m = sc.nextInt();
			for(int i=1;i<=m;i++){
				int s = sc.nextInt(), t = sc.nextInt();
				adj[s].add(new E(i, t));
				e[i][0] = s; e[i][1] = t;
			}
			Arrays.fill(o, INF);
			o[S] = 0;
			Queue<Integer> q = new LinkedList<Integer>();
			q.add(S);
			while(!q.isEmpty()){
				int v = q.poll();
				for(E r:adj[v])if(o[r.t]==INF){
					o[r.t] = o[v]+1; q.add(r.t);
				}
			}
			int res = o[T], ID = 0;
			for(int i=1;i<=m;i++){
				Arrays.fill(d, INF);
				d[S] = 0;
				q = new LinkedList<Integer>();
				q.add(S);
				int rs = e[i][1], rt = e[i][0];
				while(!q.isEmpty()){
					int v = q.poll();
					if(res<=d[v])break;
					for(E r:adj[v])if(r.id!=i&&d[r.t]==INF){
						d[r.t] = d[v]+1; q.add(r.t);
					}
					if(v==rs&&d[rt]==INF){
						d[rt] = d[v]+1; q.add(rt);
					}
				}
				if(d[T]<res){
					res = d[T]; ID = i;
				}
			}
			System.out.println(res+" "+ID);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  char b;
  cin>>b;
  if(b=='A')
    cout<<"T";
  else if(b=='T')
    cout<<'A';
  else if(b=='C')
    cout<<'G';
  else
    cout<<'C';


  return 0;
}
  


Measured memory_bytes: 256
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[];
        A=new int[N];
        for(int i=0;i<N;i++) A[i]=sc.nextInt();
        boolean swp=true;
        int cnt=0;
        while(swp){
            swp=false;
            for(int i=N-1;i>=1;i--) if(A[i]<A[i-1]){
                swp=true;
                cnt++;
                int tmp=A[i];
                A[i]=A[i-1];
                A[i-1]=tmp;
            } 
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            System.out.print(i==N-1?"\n":" ");
        }
        System.out.println(cnt);
        sc.close();
    }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, K;
    cin >> N >> K;
    int c[SIZE] = {};
    for(int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        for(int j = 0; j < d; ++j) {
            int a;
            cin >> a;
            c[a]++;

        }
    }

    int res = 0;
    for(int i = 1; i <= N; ++i) {
        if(c[i] == 0) ++res;

    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 4400
#include <iostream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 22;
const int MOD = 1e9 + 7;

int dp[1 << N], graph[N][N];

void add(int& a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

void solve() {
    int n;
    cin >> n;
    
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j)
            cin >> graph[i][j];
    }
    
    dp[0] = 1;
    for (int msk = 1; msk < (1 << n); ++msk) {
        int bits = 0, temp = msk;
        while (temp) {
            bits += temp % 2;
            temp /= 2;
        }
        
        for (int i = 0; i < n; ++i) {
            if (graph[bits - 1][i] && (msk & (1 << i)))
                add(dp[msk], dp[msk ^ (1 << i)]);
        }
    }
    
    cout << dp[(1 << n) - 1] << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 10496
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = (int) 2e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int a[N];
int dp[N];

class AFrog1 {
public:
    void init() {
        clr(dp, 0);
    }

    void solve(istream &cin, ostream &cout) {
        init();
        int n;
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        dp[0] = 0;
        dp[1] = abs(a[0] - a[1]);
        for (int i = 2; i < n; i++) {
            dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
        }
        cout << dp[n - 1] << el;
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	AFrog1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
int a[110];
int n;
int check(int p) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += (a[i] - p) * (a[i] - p);
    }
    return sum;
}
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int lb = 0, ub = 100;
    int ans = 0, lmid, rmid;
    while (lb <= ub) {
        lmid = lb + (ub - lb) / 3;
        rmid = ub - (ub - lb) / 3;
        if (check(lmid) >= check(rmid)) {
            ans = rmid;
            lb = lmid + 1;
        }
        else {
            ans = rmid;
            ub = rmid - 1;
        }
    }
    cout << check(ans) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll n,m;cin>>n>>m;
    vll s;
    for(ll i=1; i*i<=m; i++){
        if (m % i==0) {
            s.push_back(i); 
            s.push_back(m/i);
        }

    }
    VSORT(s);
    REP(i, s.size()){
        if (s[i]>=n){
            cout<<m/s[i]<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


int main(){
    int N, M;   cin >> N >> M;
    int s[5], c[5];

    if(N == 1 && M == 0){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < M; i++){
        cin >> s[i] >> c[i];
        s[i]--;
    }

    int x[5];
    fill(x, x+5, -1);
    for(int i = 0; i < M; i++){
        if(x[s[i]] == -1 || x[s[i]] == c[i]){
            x[s[i]] = c[i];
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }

    if(N > 1 && x[0] == 0){
        cout << -1 << endl;
        return 0;
    }
    else{
        for(int i = 0; i < N; i++){
            if(i == 0 && x[i] == -1){
                cout << 1;
            }
            else if(x[i] == -1){
                cout << 0;
            }
            else {
                cout << x[i];
            }
        }
        cout << endl;
    }







    return 0;
}


Measured memory_bytes: 256
NN = 19
X = [0] * ((1<<NN+1)-1)
 
def popcount(x):
    x -= (x >> 1) & 0x55555555
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x3f

def update(a, x):
    i = (1<<NN) - 1 + a
    X[i] = x
    while True:
        i = (i-1) // 2
        X[i] = X[2*i+1] | X[2*i+2]
        if i == 0:
            break

def rangeor(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    x = 0
    while l < r:
        if l%2:
            x |= X[l-1]
            l += 1
        if r%2:
            r -= 1
            x |= X[r-1]
        l >>= 1
        r >>= 1
    return x

N = int(input())
A = [ord(a) - 97 for a in input()]
for i, a in enumerate(A):
    update(i+1, 1<<a)

Q = int(input())
for _ in range(Q):
    a, b, c = input().rstrip().split()
    if a == "1":
        b = int(b)
        c = ord(c) - 97
        update(b, 1<<c)
    else:
        b, c = int(b), int(c)
        print(popcount(rangeor(b, c+1)))

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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

int gcd(int a, int b);
int lcm(int a, int b);

void solve_A(){
    string s, t;
    cin >> s >> t;

    int a, b;
    cin >> a >> b;

    string u;
    cin >> u;

    if(s == u) cout << a-1 << " " << b;
    else cout << a << " " << b-1;
}

void solve_B(){
    int n;
    string s;
    cin >> s;

    n = s.length();
    REP(i,n) cout << "x";
}

void solve_C(){
    int n;
    cin >> n;

    /*
    int a[n];
    int* num;
    num = (int*)calloc(1000000010, sizeof(int));
    if(num == NULL) exit(1);

    int flag = 0;
    REP(i,n){
        cin >> a[i];
        num[a[i]] ++;
        if(num[a[i]] == 2){
            flag ++;
            break;
        }
    }

    if(flag == 0) cout << "YES";
    else cout << "NO";
    */

    int a[n];
    REP(i,n) cin >> a[i];

    bool flag = false;
    sort(a, a+n);
    REP(i,n-1){
        if(a[i] == a[i+1]) flag = true;
    }

    if(flag) cout << "NO";
    else cout << "YES";

    // free(num);
}

double Expect(int n){
    return (double) (n + 1) / 2;
}

void solve_D(){
    int n, k;
    cin >> n >> k;

    int p[n];
    double e[n];
    double sum = 0.0;
    REP(i,n){
        cin >> p[i];
        sum += Expect(p[i]);
        e[i] = sum;
    }

    double ans = 0;

    if(k != n){
        REP(i, n-k){
            if(ans <= e[i+k] - e[i]) ans = e[i+k] - e[i];
        }
    } else{
        ans = e[n-1];
    }
    
    printf("%.10f", ans);
}

int main(void){
    solve_A();
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
long long n, k, m, s, p, q; vector<long long>x[300000]; vector<pair<long long, long long>>y[300000];
long long dist1[300000], dist[300000];
queue<long long>Q1; priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>Q;
int main() {
	cin >> n >> m >> k >> s >> p >> q;
	for (int i = 1; i <= n; i++) { dist[i] = 1LL << 50; dist1[i] = 1LL << 50; }
	for (int i = 0; i < k; i++) { long long a; cin >> a; Q1.push(a); dist1[a] = 0; }
	for (int i = 0; i < m; i++) { long long a, b; cin >> a >> b; x[a].push_back(b); x[b].push_back(a); }
	while (!Q1.empty()) {
		long long a1 = Q1.front(); Q1.pop();
		for (int i = 0; i < x[a1].size(); i++) {
			if (dist1[x[a1][i]] > dist1[a1] + 1) {
				dist1[x[a1][i]] = dist1[a1] + 1; Q1.push(x[a1][i]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < x[i].size(); j++) {
			if (dist1[x[i][j]] == 0)continue;
			if (x[i][j] == 1 || x[i][j] == n) { y[i].push_back(make_pair(x[i][j], 0)); }
			else if (dist1[x[i][j]] <= s) { y[i].push_back(make_pair(x[i][j], q)); }
			else { y[i].push_back(make_pair(x[i][j], p)); }
		}
	}
	Q.push(make_pair(0, 1)); dist[1] = 0;
	while (!Q.empty()) {
		long long a1 = Q.top().first, a2 = Q.top().second; Q.pop();
		for (int i = 0; i < y[a2].size(); i++) {
			if (dist[y[a2][i].first] > a1 + y[a2][i].second) {
				dist[y[a2][i].first] = a1 + y[a2][i].second;
				Q.push(make_pair(dist[y[a2][i].first], y[a2][i].first));
			}
		}
	}
	cout << dist[n] << endl;
	return 0;
}

Measured memory_bytes: 34432
#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define NMAX 200005
using namespace std;
typedef long long ll;
ll k, x;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
}
int main()
{
    fast();
    cin>>k>>x;
    ll l=max(x-k+1,-1000000LL);
    ll r=min(x+k-1,1000000LL);
    for(int i=l;i<=r;++i)
        cout<<i<<' ';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44


const int MOD = (int) 1e9 + 7;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}


inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}


using namespace std;

const int MAXK = 100;
const int MAXVAL = 50000;

int dp1[MAXK + 1][MAXVAL];
int dp2[MAXK + 1][MAXVAL];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n, k;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> k;

    int val = sqrt(n);
    for(i = 1; i <= val; i++) {
        dp1[1][i] = i;
    }
    for(i = val; i >= 1; i--) {
        dp2[1][i] = max(0, n / i - max(n / (i + 1), val));
        add(dp2[1][i], dp2[1][i + 1]);
    }

    for(i = 2; i <= k; i++) {
        for(j = 1; j <= val; j++) {
            add(dp1[i][j], dp1[i - 1][val]);
            add(dp1[i][j], dp2[i - 1][j]);

            add(dp2[i][j], (1LL * dp1[i - 1][j] * max(0, n / j - max(val, n / (j + 1)))) % MOD);
        }

        for(j = 1; j <= val; j++) {
            add(dp1[i][j], dp1[i][j - 1]);
        }
        for(j = val; j >= 1; j--) {
            add(dp2[i][j], dp2[i][j + 1]);
        }
    }

    int ans = dp1[k][val] + dp2[k][1];
    mod(ans);

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}


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

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

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) os << "[" << el.first << " " << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }

ll M,K;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> M >> K;
}

int solve(){
  if(M==0){
    if(K==0) {cout << 0 << " " << 0 << endl; return 0;}
    else {cout << -1 << endl; return 0;}
  }
  if(M==1){
    if(K==0) {cout << 0 << " " << 0 << " " <<  1 << " " << 1 << endl; return 0;}
    else {cout << -1 << endl; return 0;}
  }
  if(K>=(1<<M)) {cout << -1 << endl; return 0;}
  vector<ll> ans;
  for (int i = 0; i < (1<<M); i++)
  {
    if(i!=K) ans.push_back(i);
  }
  ans.push_back(K);
  for (int i = (1<<M)-1; i >= 0; i--)
  {
    if(i!=K) ans.push_back(i);
  }
  ans.push_back(K);
  cout << ans << endl;

  return 0;
}


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


Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<ull> vul;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pl;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define Sort(a) sort(a.begin(), a.end())
ll dp[110][100010];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, W;
	cin >> n >> W;
	vl w(n);
	vl u(n);
	ll s = 0;
	For(i, n) {
		cin >> w[i] >> u[i];
		s += u[i];
	}
	For(i, s + 1) {
		dp[0][i] = 2 * W;
		dp[1][i] = 2 * W;
	}
	dp[1][0] = 0;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		For(j, s + 1) {
			if (j == u[i - 1]) {
				dp[i][j] = min(dp[i - 1][j], w[i - 1]);
			} 
			else if (j > u[i - 1]) {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - u[i - 1]] + w[i - 1]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
			//cout << dp[i][j] << ' ' << i << ' ' << j << endl;
			if (dp[i][j] <= W) {
				ans = max(ans, j);
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 82392
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, d = map(int, input().strip().split())
    ll = [[] for i in range(n)]
    for i in range(n):
        ll[i] = list(map(int, input().strip().split()))
    cnt = 0
    for i in range(n):
        for j in range(i+1, n):
            dist = 0
            for k in range(0, d):
                dist += (ll[i][k] - ll[j][k])**2
            # eprint(dist**(1/2))
            dist_sqr = dist**(1/2)
            if dist_sqr.is_integer() is True:
                # eprint("dist**0.5 ", end=": ")
                # eprint(dist**0.5)
                cnt += 1
    print(cnt)
    return


if __name__ == '__main__':
    main()


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

string s;

int main(){
  cin >> s;
  int sn  = 0;
  int n = 0;
  for(int i=0;i<s.size();i++){
    sn += s[i]-'0';
    n = 10*n+(s[i]-'0');
  }
  if(n%sn!=0)cout<<"No"<<endl;
  else cout <<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    N = N % K
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)


Measured memory_bytes: 38256
import java.util.Scanner;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
      int N = in.nextInt();
      int ones = N % 10;
       if ((ones == 2)||(ones == 4)||(ones == 5)||(ones == 7)||(ones == 9)){
            System.out.println("hon");
       }else if ((ones == 0)||(ones == 1)||(ones == 6)||(ones == 8)){
            System.out.println("pon");
       }else if (ones == 3) {
            System.out.println("bon");
       }
    }
}
        

Measured memory_bytes: 35824
#include <stdio.h>


int bom(int i, int j, int h, int w, char s[][51]){
  int a = 0;
  for(int dx = -1; dx <= 1; dx++){
    for(int dy = -1; dy <= 1; dy++){
      if(i + dx >= 0 && i + dx <= h - 1 && j + dy >= 0 && j + dy <= w - 1){
	if(s[i + dx][j + dy] == '#') a++;
      }
    }
  }
  return a;
}

int
main(int argc, char *argv[])
{
  char s[50][51];
  int h, w;
  scanf("%d %d", &h, &w);
  for(int i = 0; i < h; i++) scanf("%s", s[i]);

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '.'){
	printf("%d", bom(i, j, h, w, s));
      }else{
	printf("#");
      }
    }
    printf("\n");
  }

  return 0;
}


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

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

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

    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1] << endl;
    // for (int i = 0; i < n; i++)
    //     cout << dp[i] << " ";
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl "\n"
const int MAXN=3e5+5;
const int M= 1e9+7;

int col[MAXN];

ll res[MAXN],sub[MAXN],val[MAXN];

vector<int> v[MAXN];

void dfs(int node,int par){
	sub[node]=1;

	for(int x:v[node]){
		if(x==par) continue;

		dfs(x,node);
		sub[node]+=sub[x];
	}
}

void solve(int node,int par){
	ll N=val[col[node]];

	ll fin=(N-sub[node]+1)*(sub[node]);

	ll sum=0;

	for(int x:v[node]){
		if(x==par) continue;
		fin+=(sum*sub[x]);
		sum+=sub[x];
	}

	res[col[node]]+=fin;

	for(int x:v[node]){
		if(x==par) continue;
		val[col[node]]=sub[x];
		solve(x,node);
	}

	val[col[node]]=N-sub[node];

}

int main(){	
	
	int n;
	sfi(n)

	f(i,1,n+1){
		sfi(col[i])
		val[i]=n;
	}

	f(i,0,n-1){
		int x,y;
		sfi(x) sfi(y)

		v[x].push_back(y);
		v[y].push_back(x);
	}

	dfs(1,1);

	solve(1,1);

	for(int i=1;i<=n;i++){
		cout<<res[i]<<"\n";
	}


	return 0;	
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
vector<vector<int>> G;
int S, T;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  G.assign(N, vector<int>());
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    G[--u].emplace_back(--v);
  }
  cin >> S >> T;
  S--, T--;

  vector<vector<ll>> res(N, vector<ll>(3, -1));
  res[S][0] = 0;
  queue<pii> que;
  que.push(make_pair(S, 0));
  while (!que.empty()) {
    pii cur = que.front();
    que.pop();

    int v = cur.first;
    int p = cur.second;
    for (auto nv : G[v]) {
      int np = (p + 1) % 3;
      if (res[nv][np] == -1) {
        res[nv][np] = res[v][p] + 1;
        que.push(make_pair(nv, np));
      }
    }
  }

  cout << (res[T][0] == -1 ? -1 : res[T][0] / 3) << '\n';
  return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(){
  double l; cin>> l;
  double x = l/3.0;
  double z = l - x*2;
  printf("%.10f\n", x*x*z);
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int c1, c5, c10, c50, c100, c500;
    cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
    cout << (c1 + 5 * c5 + 10 * c10 + 50 * c50 + 100 * c100 + 500 * c500 >= 1000) << '\n';
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int d, n;

    cin >> d >> n;
    if(n==100){
        n++;
    }

    cout << (int)pow(100, d) * n << endl;

    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;


// a x + b y = gcd(a, b)
LL extgcd(LL a, LL b, LL &x, LL &y) {
    LL g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

// mod m での a の 逆元
LL mod_inverse(LL a, LL m){
    LL x, y;
    extgcd(a, m, x, y);
    return (m + x%m)%m;
}

const LL MOD = 1000000007;
LL combi(LL N_, LL C_) {
	const int NUM_ = 1010101;
	static LL fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%MOD, factr[i] = factr[i - 1] * inv[i] % MOD;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % MOD*factr[N_ - C_] % MOD;
}

int n, a, b, c;

//n^k%MOD
long long power(long long n, long long k, long long m) {
	if (k == 0) {
		return 1;
	}
	else if (k % 2 == 1) {
		return power(n, k - 1, m)*n%m;
	}
	else {
		long long t = power(n, k / 2, m);
		return t*t%m;
	}
}

int main(){
    cin >> n >> a >> b >> c;
    LL ans = 0;
    for(LL i = n;i <= 2 * n - 1;++i){
        LL bunsi = (power(a, n, MOD) * power(b, i - n, MOD) % MOD + power(a, i - n, MOD) * power(b, n, MOD) % MOD) * i * 100 % MOD;
        LL bunbo = (power(a + b, i, MOD) * (100LL - c)) % MOD;
        (ans += combi(i - 1, n - 1) * bunsi % MOD * mod_inverse(bunbo, MOD) % MOD) %= MOD;
    }
    cout << ans << endl;
}

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

#define MAX 40000

main(){
  int n, P1[MAX+1], P2[MAX+1], T[MAX+1];
  while(1){
    scanf("%d", &n);
    if ( n == 0 ) break;

    for ( int i = 1; i <= n; i++ ) {
      scanf("%d", &P1[i]);
    }
    for ( int i = 1; i <= n; i++ ) {
      scanf("%d", &P2[i]);
    }
    sort(P1+1, P1+n+1, greater<int>());
    sort(P2+1, P2+n+1, greater<int>());
    
    for ( int i = 0; i <= n; i++ ) T[i] = 0;

    int s = 1, t = 1;
    while( s <= n && t <= n ){
      while( P1[t] > P2[s] && t <= n ) t++;
      
      if ( t <= n && P2[s] >= P1[t] ){
	T[t]++;
	t++; s++;
      }
    }

    for ( int i = 1; i <= n; i++ ) T[i] += T[i-1];

    int k = -1;
    for ( int i = 1; i <= n; i++ ){
      if ( (i-T[i]) >= (i+2)/2 ) {
	k = i;
	break;
      }
    }

    if ( k == -1 || k == n ) cout << "NA" << endl;
    else cout << k << endl;

  }
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int dp_mn_x[2001][2001][2];
int dp_mx_x[2001][2001][2];
int dp_mn_y[2001][2001][2];
int dp_mx_y[2001][2001][2];

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

  string S; cin >> S;
  int K; cin >> K;
  int N = SZ(S);

  fill((int*)dp_mn_x, (int*)dp_mn_x+2001*2001*2, 1e9);
  fill((int*)dp_mx_x, (int*)dp_mx_x+2001*2001*2, -1e9);
  fill((int*)dp_mn_y, (int*)dp_mn_y+2001*2001*2, 1e9);
  fill((int*)dp_mx_y, (int*)dp_mx_y+2001*2001*2, -1e9);
  dp_mn_x[0][0][0] = dp_mx_x[0][0][0] = dp_mn_y[0][0][0] = dp_mx_y[0][0][0] = 0;

  REP(i,N){
	REP(k,K+1){
	  REP(f,2){
		if(S[i] == 'L' || S[i] == 'R'){
		  mini(dp_mn_y[i+1][k][f], dp_mn_y[i][k][f]);
		  maxi(dp_mx_y[i+1][k][f], dp_mx_y[i][k][f]);

		  int dx = (S[i]=='L'?-1:1) * (f==0?1:-1);
		  mini(dp_mn_x[i+1][k][f], dp_mn_x[i][k][f] + dx);
		  mini(dp_mn_x[i+1][k+1][f^1], dp_mn_x[i][k][f] + dx * -1);
		  maxi(dp_mx_x[i+1][k][f], dp_mx_x[i][k][f] + dx);
		  maxi(dp_mx_x[i+1][k+1][f^1], dp_mx_x[i][k][f] + dx * -1);
		}
		else{
		  mini(dp_mn_x[i+1][k][f], dp_mn_x[i][k][f]);
		  maxi(dp_mx_x[i+1][k][f], dp_mx_x[i][k][f]);

		  int dx = (S[i]=='D'?-1:1) * (f==0?1:-1);
		  mini(dp_mn_y[i+1][k][f], dp_mn_y[i][k][f] + dx);
		  mini(dp_mn_y[i+1][k+1][f^1], dp_mn_y[i][k][f] + dx * -1);
		  maxi(dp_mx_y[i+1][k][f], dp_mx_y[i][k][f] + dx);
		  maxi(dp_mx_y[i+1][k+1][f^1], dp_mx_y[i][k][f] + dx * -1);
		}
	  }
	}
  }

  int ans = -1e9;
  REP(k1,K+1) REP(k2,K+1){
	if(k1+k2 > K) continue;
	REP(f1,2) REP(f2,2)
	  maxi(ans, max(-dp_mn_x[N][k1][f1], dp_mx_x[N][k1][f1])
		   + max(-dp_mn_y[N][k2][f2], dp_mx_y[N][k2][f2]));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 128364
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>

using namespace std;

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

int main()
{
  string S;
  cin >> S;
  if (S == "ABC")
  {
    cout << "ARC" << endl;
  }
  else
  {
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
    int h,w;
    cin>>h>>w;
    vector<string> c(h);
    rep(i,0,h) cin>>c[i];
    rep(i,0,h){
        cout<<c[i]<<"\n"<<c[i]<<"\n";
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

n = int(input())
P = []
for i in range(n):
    x, y = map(int, input().split())
    P.append((x, y, i))

import heapq
def prim_heap():
    used = [True]*n
    edgelist = []
    for e in edge[0]:
        heapq.heappush(edgelist, e)
        used[0] = False
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)
        if not  used[minedge[1]]:
            continue
        v = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, e)
        res += minedge[0]
    return res

P.sort()
edge = [[] for _ in range(n)]
for i in range(n-1):
    d = min(abs(P[i+1][0]-P[i][0]), abs(P[i+1][1]-P[i][1]))
    edge[P[i][2]].append((d, P[i+1][2]))
    edge[P[i+1][2]].append((d, P[i][2]))

P.sort(key = lambda x: x[1])
for i in range(n-1):
    d = min(abs(P[i+1][0]-P[i][0]), abs(P[i+1][1]-P[i][1]))
    edge[P[i][2]].append((d, P[i+1][2]))
    edge[P[i+1][2]].append((d, P[i][2]))

print(prim_heap())

Measured memory_bytes: 112860
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

    int A, B;
    cin >> A >> B;

    if(A > B){
        cout << A + ( A-1) << endl;
    }

    if(B > A){
        cout << B + (B-1) << endl; 
    }

    if(A == B){
        cout << A + B << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pli = std::pair<long long, int> ;

using namespace std;

const long long MOD = 1000000007;

int solve(int n, int a, int b) {
	int retv = 0;
	if (a == b && n >= a) ++retv;

	int t = a * 10 + b;
	int q = 1;
	rep(i, 5) {
		if (n < t) break;
		if (t == a * 10 + b) {
			++retv;
		}
		else {
			if (n >= t + (q - 1) * 10) retv += q;
			else {
				retv += (n - t) / 10 + 1;
			}
		}

		q *= 10;
		t = (t - b) * 10 + b;
	}

	return retv;
}

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

	int n;
	cin >> n;

	int ans = 0;
	REP(i, 1, 10) {
		REP(j, 1, 10) {
			ans += solve(n, i, j)*solve(n, j, i);
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

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;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int k,s;
	cin>>k>>s;
	int ans=0;
	rep(x,k+1)rep(y,k+1){
		int z=s-x-y;
		if(0<=z && z<=k) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256