akhauriyash/Code-Regression huggingface dataset:
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
cnt = 0
r = []
l = []
for i in range(q-1,-1,-1):
    if tbl[i][0] == '1':
        cnt += 1
    else:
        if (cnt + int(tbl[i][1]))%2 == 1:
            l.append(tbl[i][2])
        else:
            r.append(tbl[i][2])
l = ''.join(l)
if cnt%2 == 1:
    s = s[::-1]
r = ''.join(r[::-1])
print(l+s+r)


Measured memory_bytes: 107424
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int sho = s.size();
  int dai = 0;
  for (int i=0;i<s.size();i++){
    if(s.at(i) == 'A' && sho > i){
      sho = i;
    }
    if(s.at(i) == 'Z' && dai < i){
      dai = i;
    }
  }
  
  cout << dai - sho + 1<< endl;
  return 0;
}


Measured memory_bytes: 640
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        AB = [tuple(map(int, input().split())) for _ in range(N)]

        AB.sort(key=lambda x: x[1])
        total_time = 0
        for a, b in AB:
            total_time += a
            if total_time > b:
                print("No")
                exit()
        print("Yes")


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 76440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
double a[105];
double ans;
int main(void){
	double n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans+=1/a[i];
	}
	cout<<std::setprecision(8)<<1/ans<<endl;
	
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    multiset <int> s;
    multiset <int> t;
    int x,y;
    for (int i=0;i<n;i++){
        cin>>x>>y;
        s.insert(x+y);
        t.insert(x-y);
    }
    cout<<max(*s.rbegin()-*s.begin(),*t.rbegin()-*t.begin())<<"\n";
	return 0;
}

Measured memory_bytes: 22356
N, Q = map(int, input().split())

tree = [[] for _ in range(N)]
result = [0]*N

for _ in range(N - 1):
    a, b = map(int, input().split())
    tree[a-1].append(b)

for _ in range(Q):
    p, x = map(int, input().split())
    result[p-1] += x

for i in range(N - 1):
    for j in tree[i]:
        result[j-1] += result[i]

print(' '.join(map(str, result)))

Measured memory_bytes: 58976
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll h,a;cin>>h>>a;

    cout<<(h+a-1)/a<<endl;
    return 0;
}

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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int count = 0;
    for(auto c: s){
        if(c == 'I'){
            count++;
            ans = max(ans, count);
        }else{
            count--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=105;
int n,m;
int a[N][N],b[N];
int g[N][N];
int vis[N],Match[N];
int dfs(int x){
	For(y,1,n)
		if (g[x][y]&&!vis[y]){
			vis[y]=1;
			if (!Match[y]||dfs(Match[y])){
				Match[y]=x;
				return 1;
			}
		}
	return 0;
}
int main(){
	n=read(),m=read();
	For(i,1,n)
		For(j,1,m)
			a[i][j]=read();
	For(c,1,m){
		clr(g);
		For(i,1,n)
			For(j,c,m){
				int r=(a[i][j]+m-1)/m;
				if (!g[i][r])
					g[i][r]=j;
			}
		clr(Match);
		For(i,1,n){
			clr(vis);
			assert(dfs(i));
		}
		For(i,1,n){
			int r=Match[i];
			swap(a[r][c],a[r][g[r][i]]);
		}
	}
	For(i,1,n){
		For(j,1,m)
			printf("%d ",a[i][j]);
		puts("");
	}
	For(i,1,m){
		For(j,1,n)
			b[j]=a[j][i];
		sort(b+1,b+n+1);
		For(j,1,n)
			a[j][i]=b[j];
	}
	For(i,1,n){
		For(j,1,m)
			printf("%d ",a[i][j]);
		puts("");
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    pair<pair<string,int>,int> res[n];
    for(int i=0;i<n;i++){
        string s;
        int a;
        cin >> s >> a;
        a = a*-1;
        res[i]=make_pair(make_pair(s,a),i);
    }
    sort(res,res+n);
    for(int i=0;i<n;i++){
        cout << res[i].second+1 << endl;
    }
}

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

int main()
{
 int a[4];

 while(cin >> a[0] >> a[1] >> a[2] >> a[3]){
  int hit = 0, blow = 0;
  for(int i=0; i<4; i++){
   int n;
   cin >> n;
   if(n == a[i]){
    hit++;
    continue;
   }
   for(int j=0; j<4; j++){
    if(n == a[j]){
     blow++;
     break;
    }
   }
  }
  cout << hit << ' ' << blow << '\n';
 }
 
 return 0;
}

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

int main() {
  long long int A=0;
  int N;
  long int S;
  cin >> N;
  vector<long int> vec(3*N);
  
  for (int i =0; i<3*N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for (int i=0; i<N; i++) {
    A += vec.at(2*i+1);
  }
  cout << A << endl;
  return 0;
}

Measured memory_bytes: 2560
n = gets.chomp.split("")
op = ['+', '-']
for i in 0..1
	for j in 0..1
		for k in 0..1
			s = n[0] + op[i] + n[1] + op[j] + n[2] + op[k] + n[3]
			if eval(s) == 7
				puts s + '=7'
				exit
			end
		end
	end
end



Measured memory_bytes: 1788
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()

signed main() {
	int a;
	std::cin >> a;
	std::string s;
	std::cin >> s;
	if(a>=3200) print(s);
	else print("red");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  int s; cin>>s;
  set<int> se;
  se.insert(s);
  int i=2;
  while(1){
    if(s%2==0){
      s/=2;
    }else{
      s=s*3+1;
    }
    if(se.count(s)){
      break;
    }
    i++;
    se.insert(s);
  }
  cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll ans=max(a*c,max(a*d,max(b*c,b*d)));
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
long long m,n;
int main() {
    int ans=0,a,b;
    cin>>m>>n;
    if(m>n) swap(m,n);
    if(m==1)
        if(n==1) ans=1;
        else if(n==2) ans=0;
        else if(n>=3) ans=n-2;
    if(m==1){cout<<ans<<endl;exit(0);}
    cout<<(m-2)*(n-2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
#define MAX_N 100000

int n;
ll a[MAX_N];

void solve()
{
    ll ans = 1;

    for (int i = 0; i < n; i++)
    {
        if (a[i] == 0)
            ans = 0;
    }
    if (ans != 0)
    {
        for (int i = 0; i < n; i++)
        {
            if (ans > 1000000000000000000 / a[i])
            {
                ans = -1;
                break;
            }
            ans *= a[i];
        }
    }
    cout << ans;
}

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

    solve();
}


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

using namespace std;
map<int,int> cnt;
int a[100010];
int n;
bool check(){
    for (std::map<int,int>::iterator i=cnt.begin(); i!=cnt.end(); ++i)
    {
        if(i->second>1)return false;
    }
    return true;
}
int main()
{
    scanf("%d",&n);
    int i , j , s=0,x;
    for(i=0;i<n;i++){scanf(" %d",&a[i]); cnt[a[i]]++; if(cnt[a[i]]>2)cnt[a[i]]-=2;}


    for(map<int,int>::iterator it=cnt.begin(); it!=cnt.end(); ++it)
    {
        if(it->second>1){
            for(map<int,int>::reverse_iterator itt=cnt.rbegin(); itt!=cnt.rend(); ++itt)
            {
               if(itt->second>=2&&it->first!=itt->first){it->second--; itt->second--; break;}
               else if(it->first==itt->first){
                it->second--;
                it->second--;
               break; }
            }
        }
    //for(map<int,int>::iterator it=cnt.begin(); it!=cnt.end(); ++it)cout<<it->first<<" : "<<it->second<<endl;

    }


    for(map<int,int>::iterator it=cnt.begin(); it!=cnt.end(); ++it)if(it->second==1)s++;

    cout<<s<<endl;

    return 0;
}


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

#define int long long

const int maxn = 200004;

int N, M, K;
int a[maxn], b[maxn];

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

	cin >> N >> M >> K;
	for (int i=1; i<=N; i++) cin >> a[i];
	for (int i=1; i<=M; i++) cin >> b[i];

	for (int i=1; i<=N; i++) a[i] += a[i-1];
	for (int i=1; i<=M; i++) b[i] += b[i-1];

	int ans = 0;

	for (int i=0; i<=M; i++) if (b[i] <= K) {
		ans = max<int>(ans, i + (upper_bound(a+1, a+N+1, K - b[i]) - a - 1));
	}

	cout << ans << '\n';
}

Measured memory_bytes: 6792
//Bismillahir Rahmanir Rahim
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;

    for(int i=1; i<10; i++)
    {
        for(int j=1; j<10; j++)
        {
            if(i*j==n)
            {
                cout<<"Yes"<<endl;
                return 0;
            }

        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3128
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef pair<double,double> P;
double cross(P p1,P p2){
  return p1.first*p2.second-p1.second*p2.first;
}
double getArea(vector<P> p){
  double sum=0;
  for(int i=0;i<p.size();i++)sum+=cross(p[i],p[(i+1)%p.size()]);
  return abs(sum/2.0);
}

int main(){
  vector<P> poly;
  P p;
  while(scanf("%lf,%lf",&p.first,&p.second) != EOF){
    poly.push_back(p);
  }
  printf("%.6f\n",getArea(poly));
}

Measured memory_bytes: 1240
#include<iostream>
#include<algorithm>
#include<vector>
#include <string>
#include<math.h>
typedef long long int ll;
using namespace std;

int main(){
	string s; cin >>s;
	int n=s.size();
	ll ans=0;
	for(int i=0;i< 1<<(n-1);i++){
		ll m=s[0]-'0';
		for(int j=0;j<n-1;j++){
			if((i>>j)&1){
				ans+=m;
				m=s[j+1]-'0';
			}
			else{
				m=m*10+(s[1+j]-'0');
			}
		}
		ans+=m;
	}
	cout << ans << endl;
}

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

int main() {
  string w;
  cin >> w;
  transform(w.begin(), w.end(), w.begin(), ::tolower);

  int c = 0;
  for(;;){
    string t;
    cin >> t;
    if(t == "END_OF_TEXT"){
      cout << c << endl;
      return 0;
    }
    transform(t.begin(), t.end(), t.begin(), ::tolower);
    if(t == w){
      c++;
    }
  }
}


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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int n;
vector<int> a;

int main() {
    init();
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    int cnt = 0;

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

    cout << cnt << endl;

    return 0;
}

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

int main(void) {

  char inp[100];

  scanf("%s",inp);

  int year, month, day;
  sscanf(inp, "%d/%d/%d", &year, &month, &day);

  if(year<=2019 && month<=4 && day<=30)
	printf("Heisei\n");
  else
	printf("TBD\n");
  

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

    long long a,b,k;
    cin>>a>>b>>k;

    if(a-k>=0){
        cout<<a-k<<" "<<b<<endl;
    }else if(a+b>=k){
        cout<<0<<" "<<a+b-k<<endl;
    }else{
        cout<<0<<" "<<0<<endl;
    }
    

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, ex, area, r;
    scanf("%d %d", &a, &b);
    area = a*b;
    ex = a+b-1;
    r = area-ex;
    printf("%d\n", r);
  //  printf("In this case,the area is %d square yards.", r);
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
X, Y= map(int, input().split())
if (Y % 2) != 0:
  print('No')
elif (2 * X) > Y :
  print('No')
else:
  if (2 * X - Y /2 ) >= 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 9112
import sys
def input():
    return sys.stdin.readline()[:-1]
S = list(input())
u = 10**9+7
d = len(S)
dp = [0]*13
dp[0] = 1
m = 1

for i in range(d-1,-1,-1):
    tmp = [0]*13
    a = S[i]
    if a=='?':
        for j in range(10):
            c = j*m
            for k in range(13):
                n = (c+k)%13
                tmp[n] += dp[k]
                tmp[n] %= u
    else:
        c = int(a)*m
        for k in range(13):
            n = (c+k)%13
            tmp[n] += dp[k]
            tmp[n] %= u
    m *= 10
    m %= 13
    dp = tmp
print(dp[5])

Measured memory_bytes: 49904
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    string s1,s2;
    cin >> s1;
    cin >> s2;

    bool ans = true;

    rep(i,3){
        if(s1[i] != s2[2 - i]){
            ans = false;
            break;
        }
    }

    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void solveforthiscase(const int & test)
{//deb(test);
cin>>a>>b>>c;
ll temp=(ll)(c-a-b)*(ll)(c-a-b);
ll temp1=a*b*4;
if(temp1<temp && (c-a-b)>0)
{
    cout<<"Yes";
}
else
cout<<"No";





return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

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

using namespace std;

const int maxn = 100010;
int n, x, y, ans = 0;

int read(){
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*w;
}

signed main()
{
    #ifndef ONLINE_JUDGE
  	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
    #endif  

    n = read();
	for(int i = 1; i <= n; i ++) {
		ans += n / i;
		if(n % i == 0) ans --;
	}
	printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;

string ans = "xxoxxxabcxdefghxijkxxxoxx";

class board{
public:
  int h,c;
  string s;
  board(int x,int y,string z){ h=x; c=y; s=z;}
  const bool operator<(const board x)const{return h+c>x.h+x.c; }
};

int score(string s){
  int res=0,m;
  for(int i=0;i<25;i++){
    if(s[i]!='x' && s[i]!='o'){
      for(int j=0;j<25;j++){
	if(s[i]==ans[j]){
	  m = abs(i/5-j/5) + abs(i%5-j%5);
	  break;
	}
      }
      res += m;
    }
  }
  return res;
}

char trans(int x){
  if(!x)return 'o';
  else return 'a'+x-1;
}

int main(){
  string s = "xxxxxxxxxxxxxxxxxxxxxxxxx";
  int tmp,cost;

  for(;;){
    cin >> tmp;
    if(tmp<0)break;

    s[2] = trans(tmp);
    for(int i=0;i<3;i++){
      cin >> tmp;
      s[6+i] = trans(tmp);
    }
    for(int i=0;i<5;i++){
      cin >> tmp;
      s[10+i] = trans(tmp);
    }
    for(int i=0;i<3;i++){
      cin >> tmp;
      s[16+i] = trans(tmp);
    }
    cin >> tmp;
    s[22] = trans(tmp);

    priority_queue<board> q;
    q.push(board(score(s),0,s));

    map<string,bool> m;
    while(q.size()){
      board p = q.top();q.pop();
      int dx[] = {-5,1,5,-1};

      cost = p.c;
      if(p.s == ans)break;
      if(p.h+cost>20){
	cost = 21;
	break;
      }

      m[p.s] = true;
      for(int i=0;i<25;i++){
	if(p.s[i]=='o'){
	  for(int j=0;j<4;j++){
	    int sx = i + dx[j];
	    if(sx<0 || 25<=sx)continue;
	    if(p.s[sx] == 'x' || p.s[sx] == 'o')continue;
	    string str = p.s;
	    swap(str[i],str[sx]);
	    if(!m[str])q.push(board(score(str),cost+1,str));
	  }
	}
      }
    }

    if(cost>20)cout << "NA\n";
    else cout << cost << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
string n;
cin>>n;
for(int i=0;i<3;i++){
    if(n.at(i)=='1'){
        cout<<"9";
    }else{
        cout<<"1";
    }
}
}









Measured memory_bytes: 256
#include <string.h>
i,t;
main(){
    char W[11],T[1001];
    for(i=0,scanf("%s",W);W[i];W[i]=tolower(W[i]),i++);
    for(;scanf("%s",T),strcmp(T,"END_OF_TEXT");){
        for(i=0;T[i];T[i]=tolower(T[i]),i++);
        if(strcmp(W,T)==0)t++;
    }
    printf("%d\n",t);
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  long double a, b, c;
  cin >> a >> b >> c;
  if (c - a - b - 2 * sqrt(a * b) > 0) {
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    ld arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    ld ans=0;
    sort(arr,arr+n);
    ans=arr[0];
    for(i=1;i<n;i++)
    {
        ans+=arr[i];
        ans/=2.0;
    }
    cout<<setprecision(8)<<fixed<<ans;
}

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

int num[10];
int left_num[10], right_num[10];
int l, r;

bool dfs(int i) {
	if (i == 10) {
		return true;
	}
	if (i == 0) {
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (left_num[l] < num[i]) {
		l++;
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (right_num[r] < num[i]) {
		if (r == 0) {
			right_num[r] = num[i];
			return dfs(i + 1);
		} else {
			r++;
			right_num[r] = num[i];
			return dfs(i + 1);
		}
	}
	return false;
}

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

	while (N--) {
		l = 0, r = 0;
		for (i = 0; i < 10; i++) {
			cin >> num[i];
			left_num[i] = 0;
			right_num[i] = 0;
		}
		if (dfs(0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

void chmin(int&a, int b) {
  if (a > b) a = b;
}

int main() {
  int N;
  cin >> N;
  
  int dp[100001];
  for (int i = 0; i <= 100001; i++) {
    dp[i] = 100000;
  }
  dp[0] = 0;
  
  
  for (int i = 0; i < N; i++) {
    int x = 6;
    int y = 9;
    
    chmin(dp[i+1], dp[i] + 1);

    while (i + x <= 100000) {
      chmin(dp[i + x], dp[i] + 1);
      x *= 6;
    }
    
    while (i + y <= 100000) {
      chmin(dp[i + y], dp[i] + 1);
      y *= 9;
    }
    
  }
       
  cout << dp[N] << endl;
  
}

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	x,y=MI()
	a=abs(x-y)
	print("Brown" if a<=1 else "Alice")


if __name__ == "__main__":
	main()


Measured memory_bytes: 62048
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll a[MAX],b[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>b[i];
    ll ans=0;
    for(int bit=0; bit<30; bit++)
    {
        vector<ll>tempA(n),tempB(n);
        ll T=1ll<<bit;
        for(int i=0; i<n; i++)
        {
            tempA[i]=a[i]%(2ll*T);
            tempB[i]=b[i]%(2ll*T);
        }
        sort(tempB.begin(),tempB.end());
        ll sum=0;
        for(int i=0;i<n;i++){
          auto l=lower_bound(tempB.begin(),tempB.end(),T-tempA[i]);
          auto r=lower_bound(tempB.begin(),tempB.end(),2*T-tempA[i]);
          sum+=r-l;
          l=lower_bound(tempB.begin(),tempB.end(),3*T-tempA[i]);
           r=lower_bound(tempB.begin(),tempB.end(),4*T-tempA[i]);
          sum+=r-l;
        }
        if(sum%2)
            ans+=T;
    }
    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 9404
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


int main(){
  vector<int> a(3);
  rep(i,3) cin>>a[i];
  sort(a.begin(),a.end());
  int sum=0;
  sum+=a[1]-a[0];
  sum+=a[2]-a[1];
  cout<<sum<<endl;

  return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

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

	int num = 1;
	for(int i = 0; i < n; i++){
		if(num < k)
			num *= 2;
		else
			num += k;
	}

	cout << num << endl;

	return 0;
}

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

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              123456789

using namespace std;

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fx[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

ll digit(ll x)
{
    ll sum = 0;
    while(x>0)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

int main()
{
    ll n,a,b,sum=0,tmp;
    scln(n);
    scln(a);
    scln(b);
    for(ll i=1;i<=n;i++)
    {
        tmp = digit(i);
        if(tmp>=a&&tmp<=b)
            sum+=i;
    }
    pf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int         // 10^18
#define INF 1000000001           // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    string s;cin>>s;
    bool flag1=false;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='C'){
            flag1=true;
        }
        if(flag1 && s[i]=='F'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
using namespace std;
#define ll long long
const int maxx = 100005;
int ans[maxx];
int solve(int x)
{
    int k = 10000,cnt = 0,y = x;
    while(y){
        int now = y%10;
        y /= 10;
        cnt += now*k;
        k /= 10;
    }
    //cout<<cnt<<endl;
    if(cnt == x){
        return 1;
    }
    return 0;
}
int main()
{
    int x,y,cnt = 0;
    cin>>x>>y;
    for(int i=x;i<=y;i++){
        if(solve(i)){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    //cout<<ans[y] - ans[x]<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(map(int, list(input())))
now = 1
cnt = 0
Nums = []
for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    Nums.append(cnt)

if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left, right = 0, 0
tmp = 0  # sum of [left, right)
for i in range(len(Nums))[::2]:
    next_left = i
    next_right = min(i + add, len(Nums))
    while next_left > left:
        tmp -= Nums[left]
        left += 1
    while next_right > right:
        tmp += Nums[right]
        right += 1

    ans = max(tmp, ans)

print(ans)


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


string S;
int Q;
deque<char> dq;
int b = 2;


void input() {
    cin >> S >> Q;
}


void query1() {
    if (b == 1) {
        b = 2;
    } else {
        b = 1;
    }
}


void query2() {
    int f;
    char c;
    cin >> f >> c;
    if (f * b == 2) {
        dq.push_front(c);
    } else {
        dq.push_back(c);
    }
}


int main() {
    input();
    for (char c : S) dq.push_back(c);
    rep(_, Q) {
        int t;
        cin >> t;
        if (t == 1) {
            query1();
        } else {
            query2();
        }
    }
    int n = dq.size();
    if (b == 1) {
        for (int i = n - 1; i >= 0; i--) cout << dq[i];
    } else {
        for (char c : dq) cout << c;
    }
    cout << endl;
}


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

int main(){
  int n, k, v = 1;
  cin >> n >> k;

  for(int i=0; i<n; i++){
    if(v < k)
      v*=2;
    else
      v+=k;
  }
  cout << v << endl;
  
  return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))

def water(a):
    if min(a)==max(a):
        return min(a)
    elif min(a)>0:
        m=min(a)
        for i in range(len(a)):
            a[i]-=m
        return water(a)+m
    else:
        s=[]
        l=-1
        for i in range(len(a)):
            if a[i]!=0:
                if l==-1:
                    l=i
                if i==len(a)-1:
                    r=i+1
                    s.append((l,r))
    
            else:
                if l>-1:
                    r=i
                    s.append((l,r))
                    l=-1
    
        res=0
        for k in s:
            res+=water(a[k[0]:k[1]])
        return res

print(water(h))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int, int>
#define vp vector<pii>
#define vs vector<string>
#define mii map<int, int>

void show(auto a){
  int i = 0;
  while(i < a.size()){
    cout<<a[i]<<" ";
    i++;
  }
  cout<<endl;
}

long long dp[410][410];

int main(){
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  vi a(n); for(int i =0; i < n; i++) cin>>a[i];

  for(int l = n; l >= 0; l--){
  	for(int r = 0; r <= n; r++){
  		if(l == r) dp[l][r] = 0;
  		else{
  			dp[l][r] = 1e18;
  			long long int s = 0;
  			for(int i = l; i <= r; i++){
  				s += a[i];
  			}
  			for(int i = l; i <= r; i++){
  				dp[l][r] = min(dp[l][r], dp[l][i] + dp[i+1][r] + s);
  			}
  		}
  	}
  }

  cout<<dp[0][n-1]<<endl;


  

}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

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

	ll t = 1;
	// cin>>t;

	while(t--){
		
		string s,r;
		cin>>s>>r;

		ll ans = 0;
		for(ll i=0;i<s.length();++i) if(s[i] != r[i]) ++ans;

		cout<<ans<<"\n";

	}

	return 0;

}

Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <cmath>
#include <limits>

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> th(h);
    rep(i, h) cin >> th[i];
    rep(i, h) rep(j,2) cout << th[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;

    int N=0, W=0, S=0, E=0;
    bool flg;

    for(int i=0; i<s.size(); i++){
        if(s[i] == 'N') N++;
        if(s[i] == 'W') W++;
        if(s[i] == 'S') S++;
        if(s[i] == 'E') E++;
    }

    if(N == 0 && S == 0){
        if(E>0 && W>0) flg = true;
        else flg = false;
    }
    else if(E == 0 && W == 0){
        if(N>0 && S>0) flg = true;
        else flg = false;
    }
    else{
        if(E>0 && W>0 && S>0 && N>0) flg = true;
        else flg = false;
    }


    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

//flagを用いたバブルソート
int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for (int i=0; flag; i++) {
        flag = 0;
        for (int j = N-1; j >= i+1; j--) {
            if (A[j] < A[j-1]) {
                // 隣接要素が交換する
                swap(A[j], A[j-1]);
                flag = 1;//隣接要素を交換すると、交換した次の隣接要素を調べるためにフラグが立つ
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int A[100], N, sw;
    cin >> N;
    for (int i=0; i<N; i++) cin >> A[i];

    sw = bubbleSort(A, N);

    for (int i=0; i<N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }    
    cout << endl;
    cout << sw << endl;

    return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll gcd(ll a,ll b){
  if(!b) return a;
  return gcd(b,a%b);
}
int main(){
    ll n,A[200001],B[200001];
    cin>>n;
    rep(i,n) cin>>A[i]>>B[i];
    vector<P> C,D;
    rep(i,n) if(A[i]&&B[i]){
        C.push_back(P(A[i]/gcd(A[i],B[i]),B[i]/gcd(A[i],B[i])));
        D.push_back(P(-B[i]/gcd(A[i],B[i]),A[i]/gcd(A[i],B[i])));
    }
    rep(i,C.size()) if(C[i].second<0) C[i].first*=(-1),C[i].second*=(-1);
    rep(i,D.size()) if(D[i].second<0) D[i].first*=(-1),D[i].second*=(-1);
    sort(all(C));
    sort(all(D));
    ll mod=1e9+7,a=0,z=0;
    vector<P> E;
    P c;
    rep(i,C.size()){
        if((C[i].first>0)^(C[i].second>0)) continue;
        z++;
        if(z==1) c=C[i];
        if(c==C[i]) a++;
        if(c!=C[i]){
            ll b=upper_bound(all(D),c)-lower_bound(all(D),c);
            if(b) E.push_back(P(a,b));
            a=1;
            c=C[i];
        }
    }
    ll b=upper_bound(all(D),c)-lower_bound(all(D),c);
    if(b) E.push_back(P(a,b));
    ll X=0,Y=0,Z=0;
    rep(i,n){
        if(!A[i]&&B[i]) X++;
        if(A[i]&&!B[i]) Y++;
        if(!A[i]&&!B[i]) Z++;
    }
    if(X&&Y) E.push_back(P(X,Y));
    ll sum=0;
    for(auto i:E){
        sum+=i.first+i.second;
    }
    vec F(n+1,1);
    rep(i,n) F[i+1]=F[i]*2%mod;
    ll ans=F[n-Z-sum];
    for(auto i:E){
        ans=ans*((F[i.first]+F[i.second]-1+mod)%mod)%mod;
    }
    cout<<(ans+Z-1+mod)%mod<<"\n";
}

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

bool is_prime(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      return false;
    }
  }
  return true;
}

int min_prime(int n){
  while(true){
    if(is_prime(n)){
      return n;
    }
    n++;
  }
}

int main() {
  int a;
  cin>>a;
  cout<<min_prime(a)<<endl;
}

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

using namespace std;

typedef long long ll;

const int MAXN=2e5+1;

int n,num[MAXN],tot[MAXN]={0};
ll ans=0;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1; i<=n; ++i) {
		cin>>num[i];
		++tot[num[i]];
	}
	for(int i=1; i<=n; ++i) ans+=1LL*tot[i]*(tot[i]-1)>>1;
	for(int i=1; i<=n; ++i)
		cout<<ans-tot[num[i]]+1<<'\n';
	cout.flush();
	return 0;
}

Measured memory_bytes: 3712
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
l = list(map(int,input().split()))
cou = 0
co = 0
num = 0
nu = 0
ans = []
an = []
lis.sort(reverse = True)
li.sort(reverse = True)
for i in range(n):
  while True:
    if num == n:
      ans.append(0)
      break
    if lis[num] >= li[i]:
      num += 1
    else:
      ans.append(n-num)
      break
l.sort()
for i in range(n):
  while True:
    if nu == n:
      an.append(0)
      break
    if li[-1-i] >= l[nu]:
      nu += 1
    else:
      an.append(n-nu)
      break
for i in range(n):
  cou += ans[i]*an[-1-i]
print(cou)

Measured memory_bytes: 23488
#include <stdio.h>
#include <stdlib.h>

#define N 100000

typedef struct{
  int id,p,d,leaf,k,pk;
  int *type;
}Node;

Node node[N]={0};

void check_d(int,int);

int main(){
  int n,i,j,in_id,k,in,now,root;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    node[i].p=-1;
  }
  for(i=0; i<n; i++){
    scanf("%d",&in_id);
    node[in_id].id=in_id;
    scanf("%d",&k);
node[in_id].type=malloc(sizeof(int)*k);

    if(k==0) node[in_id].leaf=1;
    node[in_id].k=k;
    for(j=0; j<k; j++){
      scanf("%d",&in);
      node[in_id].type[j]=in;
      node[in].p=in_id;
    }
  }

  for(i=0; i<n; i++){
    //printf("%d %d\n",node[i].pk,node[i].k);
    if(node[i].p==-1){
      root=i;
      break;
    }
  }
  
  check_d(root,0);

  for(i=0; i<n; i++){
    printf("node %d: ",node[i].id);
    printf("parent = %d, ",node[i].p);
    printf("depth = %d, ",node[i].d);
    if(node[i].p==-1){
      printf("root, ");
      if(node[i].k!=0){
      printf("[");
	for(j=0; j<node[i].k-1; j++){
	  printf("%d, ",node[i].type[j]);
	}
	printf("%d]",node[i].type[j]);
      }else{
	printf("[]");
      }
    }else{
      if(node[i].leaf==1) printf("leaf, []");
      else{
	printf("internal node, ");
	printf("[");
	for(j=0; j<node[i].k-1; j++){
	  printf("%d, ",node[i].type[j]);
	}
	printf("%d]",node[i].type[j]);
      }
    }
    printf("\n");
  }
  
  return 0;
}

void check_d(int now_id,int now_d){
  //printf("DEBUG %d %d\n",now_id,node[now_id].k);
  if(node[now_id].leaf==1){
    node[now_id].d=now_d;
    return;
  }else{
    while(node[now_id].pk<node[now_id].k){
      check_d(node[now_id].type[node[now_id].pk],now_d+1);
      node[now_id].pk++;
    }
    node[now_id].d=now_d;
  }
}



Measured memory_bytes: 8444
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
int coun[100];
char s[200005];
int main()
{
    scanf("%s",s);
        memset(coun,0,sizeof(coun));
        int len=strlen(s);
        long long ans=(long long)(len)*(long long)(len-1)/(long long)2;
        for(int i=0;i<len;i++)
        {
            coun[s[i]-'a']++;
        }
        for(int i=0;i<26;i++)
        {
            ans=ans-(long long)(coun[i])*(long long)(coun[i]-1)/(long long)2;
        }
        printf("%lld\n",ans+1);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
      int n;
      cin >> n;
      
      vector<int> a(n);
      for(int i = 0; i < n; i++)
      {
        cin >> a[i];
      }
      
      int ans1 = *max_element(a.begin(), a.end());
      int ans2 = 0;
      for(int i = 0; i < n; i++)
      {
        if(abs(ans2 - (ans1 / 2)) > abs(a[i] - (ans1 / 2)))
        {
          ans2 = a[i];
        }
      }
      
      cout << ans1 << " " << ans2 << endl;
      return 0;
    }

        // #include <bits/stdc++.h>
    // using namespace std;
     
    // int main(){
    //   long long  n;
    //   cin >> n;
    //   long long a[n];
    //   for (int i =0; i<n; i++) 
    //   cin >> a[i];
      
    //   sort(a,a+n);
      
    //   long  max = a[n-1];
    //   long double  dif = 1000000000;
    //   long double  target  = max/2.0;
    //   long  ans = a[0];
      
    //   for (int i =0; i<n; i++){
    //     long double c = abs(a[i]-target);
    //     if(dif> c)  ans = a[i];
    //     dif = min(dif,c);
    //   }
        
      
    //   cout << max <<" "<< ans  << endl;
    // }

Measured memory_bytes: 640
from collections import Counter
import itertools
N=input()
L=len(N)
M=int(N)
S=["3","5","7"]
ans=0
for i in range(3,L):
  for item in itertools.product(S,repeat=i):
    c=Counter(item)
    if c["3"]>0 and c["5"]>0 and c["7"]>0:
      ans+=1
t=0
for item in itertools.product(S,repeat=L):
  c=Counter(item)
  if c["3"]>0 and c["5"]>0 and c["7"]>0:
    t=0
    for j in range(L):
      t+=int(item[-j-1])*(10**j)
    if t<=M:
      ans+=1
  if t>M:
    break
print(ans)

Measured memory_bytes: 3444